habitica-sync/main.ts

55 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2021-10-03 18:10:16 +05:30
import { Plugin } from "obsidian";
import { ExampleSettingsTab } from "./settings";
import { ExampleView, VIEW_TYPE_EXAMPLE} from "./view"
2020-10-25 16:55:59 -04:00
2021-10-03 18:10:16 +05:30
interface ExamplePluginSettings {
2021-10-10 21:08:13 -07:00
userID: string
apiToken: string
2020-12-22 11:24:00 -05:00
}
2021-10-03 18:10:16 +05:30
const DEFAULT_SETTINGS: Partial<ExamplePluginSettings> = {
2021-10-10 21:08:13 -07:00
userID: "",
apiToken: ""
2020-12-22 11:24:00 -05:00
}
2021-10-03 18:10:16 +05:30
export default class ExamplePlugin extends Plugin {
settings: ExamplePluginSettings;
view: ExampleView;
async onload() {
await this.loadSettings();
this.addSettingTab(new ExampleSettingsTab(this.app, this));
this.registerView(
VIEW_TYPE_EXAMPLE,
2021-10-11 12:40:42 +05:30
(leaf) => (this.view = new ExampleView(leaf, this))
2021-10-03 18:10:16 +05:30
);
this.addRibbonIcon("dice", "Open Habitica Pane", () => { //activate view
2021-10-03 18:10:16 +05:30
this.activateView();
});
}
async loadSettings() {
this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData())
}
async saveSettings() {
await this.saveData(this.settings);
}
async onunload() {
await this.view.onClose();
this.app.workspace
.getLeavesOfType(VIEW_TYPE_EXAMPLE)
.forEach((leaf) => leaf.detach());
}
async activateView() {
this.app.workspace.detachLeavesOfType(VIEW_TYPE_EXAMPLE);
await this.app.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE_EXAMPLE,
active: true,
});
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(VIEW_TYPE_EXAMPLE)[0]
);
}
2020-10-25 16:55:59 -04:00
}