ObsidianSimpleTimeTracker/src/main.ts

38 lines
1 KiB
TypeScript
Raw Normal View History

2022-09-27 21:44:28 +02:00
import { Plugin } from "obsidian";
2022-09-27 15:36:00 +02:00
import { defaultSettings, SimpleTimeTrackerSettings } from "./settings";
import { SimpleTimeTrackerSettingsTab } from "./settings-tab";
2022-09-27 21:44:28 +02:00
import { displayTracker, loadTracker } from "./tracker";
2022-09-27 15:36:00 +02:00
export default class SimpleTimeTrackerPlugin extends Plugin {
settings: SimpleTimeTrackerSettings;
async onload(): Promise<void> {
await this.loadSettings();
this.addSettingTab(new SimpleTimeTrackerSettingsTab(this.app, this));
2022-09-27 16:06:40 +02:00
this.registerMarkdownCodeBlockProcessor("simple-time-tracker", (s, e, i) => {
2022-09-27 17:03:44 +02:00
let tracker = loadTracker(s);
2022-09-27 21:44:28 +02:00
e.empty();
2022-09-28 13:18:37 +02:00
displayTracker(tracker, e, () => i.getSectionInfo(e), this.settings);
2022-09-27 15:36:00 +02:00
});
2022-09-27 21:52:02 +02:00
this.addCommand({
id: `insert-simple-time-tracker`,
2022-09-27 22:15:16 +02:00
name: `Insert Time Tracker`,
2022-09-27 21:52:02 +02:00
editorCallback: (e, _) => {
e.replaceSelection("```simple-time-tracker\n```\n");
}
});
2022-09-27 15:36:00 +02:00
}
async loadSettings() {
this.settings = Object.assign({}, defaultSettings, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}