Added source code files which were left out

This commit is contained in:
Leoh 2021-10-17 18:18:25 +05:30
parent 32f0e6bc98
commit 470157b672
12 changed files with 414 additions and 0 deletions

65
src/main.ts Normal file
View file

@ -0,0 +1,65 @@
import { Notice, Plugin } from "obsidian";
import { HabiticaSyncSettingsTab } from "./settings";
import { HabiticaSyncView, VIEW_TYPE} from "./view"
interface HabiticaSyncSettings {
userID: string
apiToken: string
}
const DEFAULT_SETTINGS: Partial<HabiticaSyncSettings> = {
userID: "",
apiToken: ""
}
export default class HabiticaSync extends Plugin {
settings: HabiticaSyncSettings;
view: HabiticaSyncView;
displayNotice(message: string){
new Notice(message)
}
async onload() {
await this.loadSettings();
this.addSettingTab(new HabiticaSyncSettingsTab(this.app, this));
this.registerView(
VIEW_TYPE,
(leaf) => (this.view = new HabiticaSyncView(leaf, this))
);
this.addRibbonIcon("popup-open", "Open Habitica Pane", () => { //activate view
this.activateView();
});
this.addCommand({
id: "habitica-view-open",
name: "Habitica: Open Pane",
hotkeys: [{ modifiers: ["Mod", "Shift"], key: "h"}],
callback: () => {
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)
.forEach((leaf) => leaf.detach());
}
async activateView() {
this.app.workspace.detachLeavesOfType(VIEW_TYPE);
await this.app.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE,
active: true,
});
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(VIEW_TYPE)[0]
);
}
}