forked from Blendman974/faceclaw
Status bar widgets are selectable
This commit is contained in:
1 parent
8ae4b423b6
commit
132b90c21d
10 files changed
+383
-195
No files matched your search
@@ -1,11 +1,14 @@
|
||||
import { type AppDefinition } from "../app-definition";
|
||||
import { inProcessTrayWidget, type AppDefinition } from "../app-definition";
|
||||
import { createNightscoutAppWindow, startNightscoutTrayIcon, NIGHTSCOUT_SURFACE_ID, NIGHTSCOUT_WINDOW_ID } from "./nightscout-app";
|
||||
|
||||
const nightscoutApp: AppDefinition = {
|
||||
appId: "nightscout",
|
||||
title: "Nightscout",
|
||||
icon: "nightscout",
|
||||
boot: () => startNightscoutTrayIcon(),
|
||||
// Selected in the switcher, the tray readout shows the app's window.
|
||||
boot: (ctx) => startNightscoutTrayIcon(
|
||||
inProcessTrayWidget(ctx, NIGHTSCOUT_WINDOW_ID, NIGHTSCOUT_SURFACE_ID, createNightscoutAppWindow),
|
||||
),
|
||||
launch: (ctx) => ctx.launchInProcessApp(NIGHTSCOUT_WINDOW_ID, NIGHTSCOUT_SURFACE_ID, createNightscoutAppWindow),
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from "../../ui/shell/in-process-window";
|
||||
import { evaluateNightscoutAlerts } from "./nightscout-alerts";
|
||||
import { loadNightscoutThresholds, nightscoutAlwaysShowInTopBarSetting, onAnySettingChanged } from "../../ui/dashboard-settings";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { shell, type TrayWidget } from "../../ui/shell/shell";
|
||||
|
||||
export const NIGHTSCOUT_WINDOW_ID = "nightscout";
|
||||
export const NIGHTSCOUT_SURFACE_ID = "window:nightscout";
|
||||
@@ -23,11 +23,12 @@ const TRAY_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
|
||||
|
||||
const windowRenders = new Set<() => void>();
|
||||
let trayStarted = false;
|
||||
let trayWidget: TrayWidget | undefined;
|
||||
let trayTick: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function syncNightscout(): void {
|
||||
const visible = windowRenders.size > 0 || nightscoutAlwaysShowInTopBarSetting.get();
|
||||
shell.setTrayIcon(TRAY_ICON_ID, visible ? buildNightscoutTrayIcon(nightscoutBridge.snapshot()) : null);
|
||||
shell.setTrayIcon(TRAY_ICON_ID, visible ? buildNightscoutTrayIcon(nightscoutBridge.snapshot()) : null, trayWidget);
|
||||
for (const render of windowRenders) render();
|
||||
// Age warnings and stale glucose must advance even during a stalled fetch.
|
||||
if (visible && trayTick === null) trayTick = setInterval(syncNightscout, 60_000);
|
||||
@@ -37,8 +38,12 @@ function syncNightscout(): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** Shell-lifetime subscription so the tray can be enabled before any window opens. */
|
||||
export function startNightscoutTrayIcon(): void {
|
||||
/**
|
||||
* Shell-lifetime subscription so the tray can be enabled before any window
|
||||
* opens; `widget` makes it selectable in the switcher.
|
||||
*/
|
||||
export function startNightscoutTrayIcon(widget?: TrayWidget): void {
|
||||
trayWidget ??= widget;
|
||||
if (trayStarted) return;
|
||||
trayStarted = true;
|
||||
nightscoutBridge.onStateChange(syncNightscout);
|
||||
|
||||
Reference in new issue
Block a user