2026-04-20 04:04:19 +05:30
|
|
|
import { setIcon } from "obsidian";
|
2026-04-25 01:47:37 +05:30
|
|
|
import { STATUS_VISUALS } from "./status-visuals";
|
|
|
|
|
import type { StatusState } from "./types";
|
2026-04-20 04:04:19 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tiny status-bar adornment.
|
|
|
|
|
*
|
|
|
|
|
* Plain DOM (no HTML strings, no CSS-in-JS) so it stays cheap on mobile
|
|
|
|
|
* and Obsidian's lint doesn't complain about innerHTML.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export class StatusBar {
|
|
|
|
|
private readonly el: HTMLElement;
|
|
|
|
|
private readonly icon: HTMLElement;
|
|
|
|
|
private readonly text: HTMLElement;
|
|
|
|
|
|
2026-04-20 23:13:49 +05:30
|
|
|
constructor(host: HTMLElement, onClick?: () => void) {
|
2026-04-20 04:04:19 +05:30
|
|
|
this.el = host;
|
|
|
|
|
this.el.addClass("surfsense-status");
|
|
|
|
|
this.icon = this.el.createSpan({ cls: "surfsense-status__icon" });
|
|
|
|
|
this.text = this.el.createSpan({ cls: "surfsense-status__text" });
|
2026-04-20 23:13:49 +05:30
|
|
|
if (onClick) {
|
|
|
|
|
this.el.addClass("surfsense-status--clickable");
|
|
|
|
|
this.el.addEventListener("click", onClick);
|
|
|
|
|
}
|
2026-04-20 04:04:19 +05:30
|
|
|
this.update({ kind: "idle", queueDepth: 0 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update(state: StatusState): void {
|
2026-04-25 01:47:37 +05:30
|
|
|
const visual = STATUS_VISUALS[state.kind];
|
2026-04-25 01:07:02 +05:30
|
|
|
this.el.removeClass("surfsense-status--err");
|
2026-04-25 01:47:37 +05:30
|
|
|
if (visual.isError) this.el.addClass("surfsense-status--err");
|
2026-04-20 04:04:19 +05:30
|
|
|
setIcon(this.icon, visual.icon);
|
|
|
|
|
|
|
|
|
|
let label = `SurfSense: ${visual.label}`;
|
|
|
|
|
if (state.queueDepth > 0 && state.kind !== "idle") {
|
|
|
|
|
label += ` (${state.queueDepth})`;
|
|
|
|
|
}
|
|
|
|
|
this.text.setText(label);
|
|
|
|
|
this.el.setAttr(
|
|
|
|
|
"aria-label",
|
|
|
|
|
state.detail ? `${label} — ${state.detail}` : label,
|
|
|
|
|
);
|
|
|
|
|
this.el.setAttr("title", state.detail ?? label);
|
|
|
|
|
}
|
|
|
|
|
}
|