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 {
|
export default class CountNotesExoCommand implements ExoCommand {
|
||||||
name: string = "Количество заметок";
|
name: string = "Количество заметок";
|
||||||
|
slug: string = "count-notes";
|
||||||
|
|
||||||
constructor(private app: App) {
|
constructor(private app: App) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {App} from "obsidian";
|
||||||
|
|
||||||
export default interface ExoCommand {
|
export default interface ExoCommand {
|
||||||
name: string;
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
|
||||||
execute(app: App): Promise<void>;
|
execute(app: App): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,8 @@ export default class ExoCommands {
|
||||||
new CountNotesExoCommand(app)
|
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 {
|
export default class OpenRandomNoteExoCommand implements ExoCommand {
|
||||||
name: string = "Рандомная заметка из прошлого";
|
name: string = "Рандомная заметка из прошлого";
|
||||||
|
slug: string = "open-random-note";
|
||||||
|
|
||||||
async execute(app: App): Promise<void> {
|
async execute(app: App): Promise<void> {
|
||||||
|
|
||||||
const files = app.vault.getFiles();
|
const files = app.vault.getFiles();
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const lastMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()).setHours(0, 0, 0, 0); // Дата месяц назад без времени
|
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 {Plugin} from 'obsidian';
|
||||||
import {ExoCommandsModal} from "./Commands/ExoCommandsModal";
|
import {ExoCommandsModal} from "./Commands/ExoCommandsModal";
|
||||||
import "localforage";
|
import "localforage";
|
||||||
|
import ExoApi from "./ExoApi";
|
||||||
|
|
||||||
export default class ExoPlugin extends Plugin {
|
export default class ExoPlugin extends Plugin {
|
||||||
|
private api: ExoApi;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
this.addRibbonIcon('star', 'Exocortex Commands List', () => {
|
this.addRibbonIcon('star', 'Exocortex Commands List', () => {
|
||||||
new ExoCommandsModal(this.app).open();
|
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