mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
- Add explicit type casting for API call results - Fix regex escape sequences to use Unicode notation - Remove unused type imports across multiple services - Update file deletion to use FileManager.trashFile - Add missing switch case for folder modify events - Move CSS imports to ES6 import syntax
82 lines
No EOL
2.3 KiB
TypeScript
82 lines
No EOL
2.3 KiB
TypeScript
import { WorkspaceLeaf, Plugin } from "obsidian";
|
|
import { MainView, VIEW_TYPE_MAIN } from "Views/MainView";
|
|
import { RegisterDependencies, RegisterPlugin } from "Services/ServiceRegistration";
|
|
import { VaultkeeperAISettingTab } from "VaultkeeperAISettingTab";
|
|
import { Services } from "Services/Services";
|
|
import type { StatusBarService } from "Services/StatusBarService";
|
|
import { DeregisterAllServices, Resolve } from "Services/DependencyService";
|
|
import type { VaultService } from "Services/VaultService";
|
|
import { Path } from "Enums/Path";
|
|
import { Copy } from "Enums/Copy";
|
|
import type { SettingsService } from "Services/SettingsService";
|
|
|
|
import "katex/dist/katex.min.css";
|
|
import "./styles.css";
|
|
|
|
export default class VaultkeeperAIPlugin extends Plugin {
|
|
|
|
public async onload() {
|
|
await RegisterPlugin(this);
|
|
RegisterDependencies();
|
|
|
|
this.registerView(
|
|
VIEW_TYPE_MAIN,
|
|
(leaf) => new MainView(leaf)
|
|
);
|
|
|
|
this.addCommand({
|
|
id: "vaultkeeper-ai",
|
|
name: "Vaultkeeper AI",
|
|
callback: () => {
|
|
this.activateView();
|
|
}
|
|
});
|
|
|
|
this.addRibbonIcon("sparkles", "Vaultkeeper AI", (_: MouseEvent) => {
|
|
this.activateView();
|
|
});
|
|
|
|
this.addSettingTab(new VaultkeeperAISettingTab());
|
|
|
|
this.app.workspace.onLayoutReady(async () => {
|
|
await this.setup();
|
|
});
|
|
}
|
|
|
|
public async onunload() {
|
|
Resolve<StatusBarService>(Services.StatusBarService).removeStatusBarMessage();
|
|
DeregisterAllServices();
|
|
}
|
|
|
|
public async activateView() {
|
|
const { workspace } = this.app;
|
|
|
|
let leaf: WorkspaceLeaf | null = null;
|
|
const leaves = workspace.getLeavesOfType(VIEW_TYPE_MAIN);
|
|
|
|
if (leaves.length > 0) {
|
|
leaf = leaves[0];
|
|
} else {
|
|
leaf = workspace.getRightLeaf(false);
|
|
await leaf?.setViewState({ type: VIEW_TYPE_MAIN, active: true });
|
|
}
|
|
|
|
if (leaf != null) {
|
|
workspace.revealLeaf(leaf);
|
|
}
|
|
}
|
|
|
|
// create example user instruction (on first launch only)
|
|
private async setup() {
|
|
const settingsService = Resolve<SettingsService>(Services.SettingsService);
|
|
if (!settingsService.settings.firstTimeStart) {
|
|
return;
|
|
}
|
|
settingsService.settings.firstTimeStart = false;
|
|
await settingsService.saveSettings();
|
|
|
|
const vaultService: VaultService = Resolve<VaultService>(Services.VaultService);
|
|
|
|
await vaultService.create(Path.ExampleUserInstructions, Copy.EXAMPLE_USER_INSTRUCTION, true);
|
|
}
|
|
} |