Skip to content

Commit

Permalink
feat(settings): add clickable notice that jump to setting tab when fo…
Browse files Browse the repository at this point in the history
…lder-note-core not enabled
  • Loading branch information
aidenlx committed Feb 18, 2022
1 parent 8ea9769 commit 156d1b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/fn-main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import "./styles/main.css";

import {
FolderNoteAPI,
getApi,
isPluginEnabled,
} from "@aidenlx/folder-note-core";
import { FolderNoteAPI, getApi } from "@aidenlx/folder-note-core";
import { debounce, Debouncer, Notice, Plugin } from "obsidian";

import initialize from "./initialize";
import { ClickNotice } from "./misc";
import FEHandler from "./modules/fe-handler";
import {
ALxFolderNoteSettings,
Expand Down Expand Up @@ -56,8 +53,10 @@ export default class ALxFolderNote extends Plugin {
return api;
} else {
message =
"Failed to initialize alx-folder-note: Check out the Setting Tab for more details";
new Notice(message);
"Failed to initialize alx-folder-note: Click here for more details";
new ClickNotice(message, () =>
this.app.setting.openTabById(this.manifest.id),
);
throw new Error(message);
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AFItem,
FolderItem,
Modifier,
Notice,
Platform,
TAbstractFile,
TFile,
Expand Down Expand Up @@ -57,3 +58,14 @@ export const getParentPath = (src: string) => {
if (path === ".") return "/";
else return path;
};

export class ClickNotice extends Notice {
constructor(
message: string,
action: (evt: MouseEvent) => any,
timeout?: number,
) {
super(message, timeout);
this.noticeEl.addEventListener("click", action);
}
}
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class ALxFolderNoteSettingTab extends PluginSettingTab {
.onClick(async () => {
await this.app.plugins.disablePlugin(this.plugin.manifest.id);
await this.app.plugins.enablePlugin(this.plugin.manifest.id);
this.app.setting.openTabById(this.plugin.manifest.id);
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,11 @@ declare module "obsidian" {
};
};
};
setting: {
openTabById(id: string): any;
};
}
interface Notice {
noticeEl: HTMLElement;
}
}

0 comments on commit 156d1b3

Please sign in to comment.