diff --git a/Commands/CountNotesExoCommand.ts b/Commands/CountNotesExoCommand.ts index accd6b5..a84ff57 100644 --- a/Commands/CountNotesExoCommand.ts +++ b/Commands/CountNotesExoCommand.ts @@ -4,6 +4,7 @@ import NoteRepository from "../Domain/NoteRepository"; export default class CountNotesExoCommand implements ExoCommand { name: string = "Количество заметок"; + slug: string = "count-notes"; constructor(private app: App) { } diff --git a/Commands/ExoCommand.ts b/Commands/ExoCommand.ts index 9cbbcaa..231ad73 100644 --- a/Commands/ExoCommand.ts +++ b/Commands/ExoCommand.ts @@ -2,6 +2,7 @@ import {App} from "obsidian"; export default interface ExoCommand { name: string; + slug: string; execute(app: App): Promise; } diff --git a/Commands/ExoCommands.ts b/Commands/ExoCommands.ts index b64edae..749c725 100644 --- a/Commands/ExoCommands.ts +++ b/Commands/ExoCommands.ts @@ -10,4 +10,8 @@ export default class ExoCommands { new CountNotesExoCommand(app) ]; } + + static bySlug(app: App, slug: string): ExoCommand | undefined { + return ExoCommands.all(app).find(c => c.slug === slug); + } } diff --git a/Commands/OpenRandomNoteExoCommand.ts b/Commands/OpenRandomNoteExoCommand.ts index a7e4cf8..fecfe70 100644 --- a/Commands/OpenRandomNoteExoCommand.ts +++ b/Commands/OpenRandomNoteExoCommand.ts @@ -3,9 +3,9 @@ import {App, Notice} from "obsidian"; export default class OpenRandomNoteExoCommand implements ExoCommand { name: string = "Рандомная заметка из прошлого"; + slug: string = "open-random-note"; async execute(app: App): Promise { - const files = app.vault.getFiles(); const today = new Date(); const lastMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()).setHours(0, 0, 0, 0); // Дата месяц назад без времени diff --git a/ExoApi.ts b/ExoApi.ts new file mode 100644 index 0000000..00d1df9 --- /dev/null +++ b/ExoApi.ts @@ -0,0 +1,20 @@ +import {App, Notice} from "obsidian"; +import ExoCommands from "./Commands/ExoCommands"; + +export default class ExoApi { + + constructor(private app: App) { + } + + showNotice() { + new Notice("Hello from the API!"); + } + + commands(): ExoCommands[] { + return ExoCommands.all(this.app); + } + + commandBySlug(slug: string) { + return ExoCommands.bySlug(this.app, slug); + } +} diff --git a/main.ts b/main.ts index 032856d..3563f41 100644 --- a/main.ts +++ b/main.ts @@ -1,11 +1,21 @@ import {Plugin} from 'obsidian'; import {ExoCommandsModal} from "./Commands/ExoCommandsModal"; import "localforage"; +import ExoApi from "./ExoApi"; export default class ExoPlugin extends Plugin { + private api: ExoApi; + async onload() { this.addRibbonIcon('star', 'Exocortex Commands List', () => { new ExoCommandsModal(this.app).open(); }); + + this.api = new ExoApi(this.app); + (this.app as any).plugins.plugins["exo-api"] = this.api; + } + + onunload() { + delete (this.app as any).plugins.plugins["exo-api"]; } }