ObsidianSimpleTimeTracker/src/main.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-09-27 16:06:40 +02:00
import { ButtonComponent, MarkdownView, Plugin, TextComponent } from "obsidian";
2022-09-27 15:36:00 +02:00
import { defaultSettings, SimpleTimeTrackerSettings } from "./settings";
import { SimpleTimeTrackerSettingsTab } from "./settings-tab";
2022-09-27 16:06:40 +02:00
import { Tracker } 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 15:36:00 +02:00
e.empty();
e.addClass("simple-time-tracker");
2022-09-27 16:06:40 +02:00
let tracker = Tracker.load(s);
let name = new TextComponent(e)
.setPlaceholder("Name this segment");
new ButtonComponent(e)
.setButtonText("Start")
.onClick(() => {
tracker.start(name.getValue());
// TODO how do we save to the code block??
tracker.save();
});
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);
}
}