mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-06 06:12:40 +02:00
- Introduced a new `status-visuals.ts` file to centralize status icons and labels for consistency across the plugin. - Updated connection indicator logic in the settings tab to utilize the new centralized visuals. - Removed deprecated connection visual methods to streamline the codebase. - Enhanced error handling in the status bar to reflect the new status visuals structure.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { setIcon } from "obsidian";
|
|
import { STATUS_VISUALS } from "./status-visuals";
|
|
import type { StatusState } from "./types";
|
|
|
|
/**
|
|
* 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;
|
|
|
|
constructor(host: HTMLElement, onClick?: () => void) {
|
|
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" });
|
|
if (onClick) {
|
|
this.el.addClass("surfsense-status--clickable");
|
|
this.el.addEventListener("click", onClick);
|
|
}
|
|
this.update({ kind: "idle", queueDepth: 0 });
|
|
}
|
|
|
|
update(state: StatusState): void {
|
|
const visual = STATUS_VISUALS[state.kind];
|
|
this.el.removeClass("surfsense-status--err");
|
|
if (visual.isError) this.el.addClass("surfsense-status--err");
|
|
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);
|
|
}
|
|
}
|