Skip to content

Commit d8fdf50

Browse files
committed
Add boot background option
1 parent 6e55e74 commit d8fdf50

File tree

9 files changed

+34
-12
lines changed

9 files changed

+34
-12
lines changed

main.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ export default class MetaTitlePlugin extends Plugin implements PluginInterface {
5151
this.container.getAllNamed<ListenerInterface>(SI.listener, "unnamed").map(e => e.bind());
5252
await this.loadSettings();
5353
this.app.workspace.onLayoutReady(() => this.getDefer().setFlag(DeferPluginReady));
54-
await this.delay();
5554

56-
this.fc = Container.get(SI["feature:composer"]);
57-
this.mc = Container.get(SI["manager:composer"]);
58-
this.bind();
59-
this.registerCommands();
55+
await this.delay();
6056
}
6157

6258
public onunload() {
@@ -84,8 +80,18 @@ export default class MetaTitlePlugin extends Plugin implements PluginInterface {
8480

8581
private async delay(): Promise<void> {
8682
const delay = this.storage.get("boot").get("delay").value();
83+
const background = this.storage.get("boot").get("background").value();
8784
this.logger.log(`Plugin manual delay ${delay}`);
88-
await new Promise(r => setTimeout(r, delay));
85+
const promise = new Promise(r =>
86+
setTimeout(() => {
87+
this.fc = Container.get(SI["feature:composer"]);
88+
this.mc = Container.get(SI["manager:composer"]);
89+
this.bind();
90+
this.registerCommands();
91+
r();
92+
}, delay)
93+
);
94+
return background ? null : promise;
8995
}
9096

9197
private bindServices(): void {
@@ -130,6 +136,7 @@ export default class MetaTitlePlugin extends Plugin implements PluginInterface {
130136
this.dispatcher.dispatch("file:rename", new Event({ old, actual }))
131137
)
132138
);
139+
await new Promise(r => setTimeout(r, 3000));
133140
this.reloadFeatures();
134141
await this.mc.refresh();
135142
this.getDefer().setFlag(DeferFeaturesReady);

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-front-matter-title-plugin",
33
"name": "Front Matter Title",
4-
"version": "3.12.0",
4+
"version": "3.13.0",
55
"minAppVersion": "1.7.4",
66
"description": "Lets you define a title in frontmatter to be displayed as the filename for explorer, graph, search and etc.",
77
"author": "Snezhig",

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-front-matter-title",
3-
"version": "3.12.0",
3+
"version": "3.13.0",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {

src/Settings/SettingBuilders/Util/UtilBuilder.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SettingsType } from "@src/Settings/SettingsType";
33
import { ObjectItemInterface, PrimitiveItemInterface } from "@src/Storage/Interfaces";
44
import { injectable } from "inversify";
55
import { Setting } from "obsidian";
6-
import { t } from "../../../i18n/Locale";
6+
import { t } from "@src/i18n/Locale";
77

88
type BootItem = ObjectItemInterface<SettingsType["boot"]>;
99
type DebugItem = PrimitiveItemInterface<SettingsType["debug"]>;
@@ -55,5 +55,13 @@ export default class UtilBuilder implements SettingBuilderInterface<SettingsType
5555
item.get("delay").set(v);
5656
})
5757
);
58+
new Setting(container)
59+
.setName(t("boot_background.title"))
60+
.setDesc(t("boot_background.desc"))
61+
.addToggle(e =>
62+
e.setValue(item.get("background").value()).onChange(e => {
63+
item.get("background").set(e);
64+
})
65+
);
5866
}
5967
}

src/Settings/SettingsType.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type SettingsType = {
3333
debug: boolean;
3434
boot: {
3535
delay: number;
36+
background: boolean;
3637
};
3738
features: SettingsFeature;
3839
};

src/Utils/PluginHelper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default class PluginHelper {
4040
debug: false,
4141
boot: {
4242
delay: 1000,
43+
background: true,
4344
},
4445
features: {
4546
[Feature.Alias]: {

src/i18n/en/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ const en = {
164164
title: "Boot delay",
165165
desc: "Plugin will be loaded with specified delay in ms",
166166
},
167+
boot_background: {
168+
title: "Boot in background",
169+
desc: "Plugin will be loaded in background to not blocking application",
170+
},
167171
disabled: "Disabled",
168172
processor: {
169173
name: "Processor",

versions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
"3.9.0": "1.5.3",
5757
"3.10.0": "1.5.3",
5858
"3.11.0": "1.7.4",
59-
"3.12.0": "1.7.4"
59+
"3.12.0": "1.7.4",
60+
"3.13.0": "1.7.4"
6061
}

0 commit comments

Comments
 (0)