mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-13 01:32:40 +02:00
feat: enhance Obsidian plugin with folder management features, including inclusion/exclusion settings and a status modal for real-time updates
This commit is contained in:
parent
2251e464c7
commit
28d3c628f1
11 changed files with 267 additions and 154 deletions
82
surfsense_obsidian/src/status-modal.ts
Normal file
82
surfsense_obsidian/src/status-modal.ts
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import { type App, Modal, Notice, Setting } from "obsidian";
|
||||
import type SurfSensePlugin from "./main";
|
||||
|
||||
/**
|
||||
* Read-only status panel. Mirrors what the settings tab used to embed inline,
|
||||
* but as a modal so it's reachable from the status bar / command palette.
|
||||
*
|
||||
* Subscribes to plugin status changes while open so the numbers stay live;
|
||||
* unsubscribes on close.
|
||||
*/
|
||||
export class StatusModal extends Modal {
|
||||
private readonly plugin: SurfSensePlugin;
|
||||
private readonly onChange = (): void => this.render();
|
||||
|
||||
constructor(app: App, plugin: SurfSensePlugin) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
this.titleEl.setText("SurfSense status");
|
||||
this.plugin.onStatusChange(this.onChange);
|
||||
this.render();
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
this.plugin.offStatusChange(this.onChange);
|
||||
this.contentEl.empty();
|
||||
}
|
||||
|
||||
private render(): void {
|
||||
const { contentEl, plugin } = this;
|
||||
contentEl.empty();
|
||||
const s = plugin.settings;
|
||||
|
||||
const rows: Array<[string, string]> = [
|
||||
["Status", plugin.lastStatus.kind],
|
||||
[
|
||||
"Last sync",
|
||||
s.lastSyncAt ? new Date(s.lastSyncAt).toLocaleString() : "—",
|
||||
],
|
||||
[
|
||||
"Last reconcile",
|
||||
s.lastReconcileAt
|
||||
? new Date(s.lastReconcileAt).toLocaleString()
|
||||
: "—",
|
||||
],
|
||||
["Files synced", String(s.filesSynced ?? 0)],
|
||||
["Queue depth", String(plugin.queueDepth)],
|
||||
[
|
||||
"Capabilities",
|
||||
plugin.serverCapabilities.length
|
||||
? plugin.serverCapabilities.join(", ")
|
||||
: "(not yet handshaken)",
|
||||
],
|
||||
];
|
||||
for (const [label, value] of rows) {
|
||||
new Setting(contentEl).setName(label).setDesc(value);
|
||||
}
|
||||
|
||||
new Setting(contentEl)
|
||||
.addButton((btn) =>
|
||||
btn
|
||||
.setButtonText("Re-sync entire vault")
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
btn.setDisabled(true);
|
||||
try {
|
||||
await plugin.engine.maybeReconcile(true);
|
||||
new Notice("SurfSense: re-sync requested.");
|
||||
} catch (err) {
|
||||
new Notice(
|
||||
`SurfSense: re-sync failed — ${(err as Error).message}`,
|
||||
);
|
||||
} finally {
|
||||
btn.setDisabled(false);
|
||||
}
|
||||
}),
|
||||
)
|
||||
.addButton((btn) => btn.setButtonText("Close").onClick(() => this.close()));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue