generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
50 lines (42 loc) · 1.02 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, ButtonComponent, Setting, debounce } from 'obsidian';
export default class Reloader extends Plugin {
async onload() {
this.addCommand({
id: `refresh`,
name: `Refresh plugin list`,
callback: async () => {
await this.reloadPlugin(`plugin-reloader`);
}
})
window.setTimeout(() => {
// @ts-ignore
const plugins = this.app.plugins.plugins;
for (let name in plugins) {
try {
const m = plugins[name].manifest;
this.addCommand({
id: m.id,
name: `Reload ${m.name}`,
callback: async () => {
new Notice(`Reload ${m.name}`);
await this.reloadPlugin(m.id);
}
})
} catch (e) {
console.error(e)
}
}
}, 1000)
}
onunload() { }
async reloadPlugin(pluginName: string): Promise<void> {
// @ts-ignore
const { plugins } = this.app;
try {
await plugins.disablePlugin(pluginName);
await plugins.enablePlugin(pluginName);
} catch (e) {
console.error(e)
}
}
}