This commit is contained in:
kitelev 2024-12-30 21:20:55 +05:00
parent d5fa7433e8
commit 5e01bbf24a
6 changed files with 37 additions and 1 deletions

View File

@ -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) {
}

View File

@ -2,6 +2,7 @@ import {App} from "obsidian";
export default interface ExoCommand {
name: string;
slug: string;
execute(app: App): Promise<void>;
}

View File

@ -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);
}
}

View File

@ -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<void> {
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); // Дата месяц назад без времени

20
ExoApi.ts Normal file
View File

@ -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);
}
}

10
main.ts
View File

@ -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"];
}
}