-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
81 lines (68 loc) · 2.2 KB
/
main.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Plugin, Notice, PluginSettingTab, Setting, App } from "obsidian";
import { optimizeTasks } from "./src/index";
import { ObsidianDataViewData } from "./src/types";
import { logger } from "./src/utils/logger";
import { OptimizeTasksSettings, DEFAULT_SETTINGS } from "./src/types/settings";
export default class OptimizeTasksPlugin extends Plugin {
settings!: OptimizeTasksSettings;
async onload() {
await this.loadSettings();
logger.setLogLevel(this.settings.logLevel);
logger.log("Loading OptimizeTasks plugin");
this.addSettingTab(new OptimizeTasksSettingTab(this.app, this));
try {
this.addCommand({
id: "test-optimize-tasks",
name: "Test Optimize Tasks",
callback: () => {
new Notice("OptimizeTasks plugin is working!");
},
});
(window as any).optimizeTasks = (data: ObsidianDataViewData) => {
return optimizeTasks(data);
};
} catch (error) {
logger.error("Error loading OptimizeTasks plugin:", error);
}
}
onunload() {
logger.log("Unloading OptimizeTasks plugin");
delete (window as any).optimizeTasks;
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
logger.setLogLevel(this.settings.logLevel);
}
}
class OptimizeTasksSettingTab extends PluginSettingTab {
plugin: OptimizeTasksPlugin;
constructor(app: App, plugin: OptimizeTasksPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName("Log Level")
.setDesc("Set the level of logging for the plugin")
.addDropdown((dropdown) =>
dropdown
.addOptions({
off: "Off",
errors: "Errors only",
normal: "Normal",
verbose: "Verbose",
})
.setValue(this.plugin.settings.logLevel)
.onChange(async (value: string) => {
this.plugin.settings.logLevel =
value as OptimizeTasksSettings["logLevel"];
await this.plugin.saveSettings();
})
);
}
}