Skip to content

Commit

Permalink
Add boot background option
Browse files Browse the repository at this point in the history
  • Loading branch information
snezhig committed Dec 7, 2024
1 parent 6e55e74 commit d8fdf50
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 12 deletions.
19 changes: 13 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ export default class MetaTitlePlugin extends Plugin implements PluginInterface {
this.container.getAllNamed<ListenerInterface>(SI.listener, "unnamed").map(e => e.bind());
await this.loadSettings();
this.app.workspace.onLayoutReady(() => this.getDefer().setFlag(DeferPluginReady));
await this.delay();

this.fc = Container.get(SI["feature:composer"]);
this.mc = Container.get(SI["manager:composer"]);
this.bind();
this.registerCommands();
await this.delay();
}

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

private async delay(): Promise<void> {
const delay = this.storage.get("boot").get("delay").value();
const background = this.storage.get("boot").get("background").value();
this.logger.log(`Plugin manual delay ${delay}`);
await new Promise(r => setTimeout(r, delay));
const promise = new Promise(r =>
setTimeout(() => {
this.fc = Container.get(SI["feature:composer"]);
this.mc = Container.get(SI["manager:composer"]);
this.bind();
this.registerCommands();
r();
}, delay)
);
return background ? null : promise;
}

private bindServices(): void {
Expand Down Expand Up @@ -130,6 +136,7 @@ export default class MetaTitlePlugin extends Plugin implements PluginInterface {
this.dispatcher.dispatch("file:rename", new Event({ old, actual }))
)
);
await new Promise(r => setTimeout(r, 3000));
this.reloadFeatures();
await this.mc.refresh();
this.getDefer().setFlag(DeferFeaturesReady);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-front-matter-title-plugin",
"name": "Front Matter Title",
"version": "3.12.0",
"version": "3.13.0",
"minAppVersion": "1.7.4",
"description": "Lets you define a title in frontmatter to be displayed as the filename for explorer, graph, search and etc.",
"author": "Snezhig",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-front-matter-title",
"version": "3.12.0",
"version": "3.13.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion src/Settings/SettingBuilders/Util/UtilBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SettingsType } from "@src/Settings/SettingsType";
import { ObjectItemInterface, PrimitiveItemInterface } from "@src/Storage/Interfaces";
import { injectable } from "inversify";
import { Setting } from "obsidian";
import { t } from "../../../i18n/Locale";
import { t } from "@src/i18n/Locale";

type BootItem = ObjectItemInterface<SettingsType["boot"]>;
type DebugItem = PrimitiveItemInterface<SettingsType["debug"]>;
Expand Down Expand Up @@ -55,5 +55,13 @@ export default class UtilBuilder implements SettingBuilderInterface<SettingsType
item.get("delay").set(v);
})
);
new Setting(container)
.setName(t("boot_background.title"))
.setDesc(t("boot_background.desc"))
.addToggle(e =>
e.setValue(item.get("background").value()).onChange(e => {
item.get("background").set(e);
})
);
}
}
1 change: 1 addition & 0 deletions src/Settings/SettingsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type SettingsType = {
debug: boolean;
boot: {
delay: number;
background: boolean;
};
features: SettingsFeature;
};
Expand Down
1 change: 1 addition & 0 deletions src/Utils/PluginHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class PluginHelper {
debug: false,
boot: {
delay: 1000,
background: true,
},
features: {
[Feature.Alias]: {
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ const en = {
title: "Boot delay",
desc: "Plugin will be loaded with specified delay in ms",
},
boot_background: {
title: "Boot in background",
desc: "Plugin will be loaded in background to not blocking application",
},
disabled: "Disabled",
processor: {
name: "Processor",
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"3.9.0": "1.5.3",
"3.10.0": "1.5.3",
"3.11.0": "1.7.4",
"3.12.0": "1.7.4"
"3.12.0": "1.7.4",
"3.13.0": "1.7.4"
}

0 comments on commit d8fdf50

Please sign in to comment.