generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
43 lines (35 loc) · 972 Bytes
/
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
import {Plugin} from 'obsidian';
import {MainView, VIEW_TYPE_MAIN} from 'src/views/MainView';
export default class PendingNotesPlugin extends Plugin {
async onload() {
this.registerView(
VIEW_TYPE_MAIN,
(leaf) => new MainView(leaf)
);
// This creates an icon in the left ribbon.
this.addRibbonIcon('file-clock', 'Pending Notes', () => {
this.activateView()
});
// This adds a simple command that can be triggered anywhere
this.addCommand({
id: 'pending-notes-show-view',
name: 'Open pending notes list',
callback: () => {
this.activateView()
}
});
}
async onunload() {
this.app.workspace.detachLeavesOfType(VIEW_TYPE_MAIN);
}
async activateView() {
this.app.workspace.detachLeavesOfType(VIEW_TYPE_MAIN);
await this.app.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE_MAIN,
active: true,
});
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(VIEW_TYPE_MAIN)[0]
);
}
}