-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ts
More file actions
45 lines (35 loc) · 1.18 KB
/
Copy pathmain.ts
File metadata and controls
45 lines (35 loc) · 1.18 KB
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
import { Plugin } from "obsidian";
import { KavCommandCenterView, VIEW_TYPE_KCC } from "./src/view";
import { DEFAULT_SETTINGS, KCCSettings, KCCSettingTab } from "./src/settings";
export default class KavCommandCenter extends Plugin {
settings!: KCCSettings;
async onload() {
await this.loadSettings();
this.registerView(VIEW_TYPE_KCC, (leaf) => new KavCommandCenterView(leaf, this));
this.addCommand({
id: "open-command-center",
name: "Open Command Center",
callback: () => this.activateView(),
});
this.addRibbonIcon("layout-dashboard", "Kav Command Center", () => {
this.activateView();
});
this.addSettingTab(new KCCSettingTab(this.app, this));
}
async onunload() {}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
async activateView() {
const { workspace } = this.app;
let leaf = workspace.getLeavesOfType(VIEW_TYPE_KCC)[0];
if (!leaf) {
leaf = workspace.getLeaf("tab");
await leaf.setViewState({ type: VIEW_TYPE_KCC, active: true });
}
workspace.revealLeaf(leaf);
}
}