Files
fflow/src/main.ts
T

37 lines
1.2 KiB
TypeScript

import { Plugin } from "obsidian";
import { FlowCommands } from "./flows";
import { DEFAULT_SETTINGS, FflowSettings, NEW_RULE } from "./settings";
import { FflowSettingTab } from "./settings-tab";
import { TriggerSuggest, ValueIndex } from "./suggest";
export default class FflowPlugin extends Plugin {
settings!: FflowSettings;
private flowCommands = new FlowCommands(this);
async onload(): Promise<void> {
await this.loadSettings();
const index = new ValueIndex(this.app);
this.registerEvent(this.app.metadataCache.on("changed", () => index.invalidate()));
this.registerEvent(this.app.metadataCache.on("deleted", () => index.invalidate()));
this.registerEditorSuggest(new TriggerSuggest(this.app, this, index));
this.flowCommands.sync();
this.addSettingTab(new FflowSettingTab(this.app, this));
}
async loadSettings(): Promise<void> {
const saved = ((await this.loadData()) ?? {}) as Partial<FflowSettings>;
this.settings = {
// Fill fields added after a rule was saved (e.g. flowId in 0.2.0).
rules: (saved.rules ?? DEFAULT_SETTINGS.rules).map((r) => ({ ...NEW_RULE, ...r })),
flows: saved.flows ?? [],
};
}
async saveSettings(): Promise<void> {
await this.saveData(this.settings);
this.flowCommands.sync();
}
}