Add API
This commit is contained in:
parent
d5fa7433e8
commit
5e01bbf24a
|
@ -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) {
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import {App} from "obsidian";
|
|||
|
||||
export default interface ExoCommand {
|
||||
name: string;
|
||||
slug: string;
|
||||
|
||||
execute(app: App): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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); // Дата месяц назад без времени
|
||||
|
|
|
@ -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
10
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"];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue