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
@@ -4,7 +4,7 @@ import { type IconName } from "../graphics/icons";
|
||||
import { type LayerActions } from "../ui/layers";
|
||||
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
|
||||
import { WorkerAppHost } from "../ui/shell/worker-window";
|
||||
import { shell } from "../ui/shell/shell";
|
||||
import { shell, type TrayWidget } from "../ui/shell/shell";
|
||||
|
||||
/**
|
||||
* An app, as seen from outside while it isn't running. Each app directory's
|
||||
@@ -96,6 +96,17 @@ export type AppContext = {
|
||||
surfaceId: string,
|
||||
create: (options: InProcessAppOptions) => InProcessWindow,
|
||||
) => Promise<void>;
|
||||
/**
|
||||
* Open a main-thread singleton window in the background (neither
|
||||
* foregrounded nor focused) unless it is open already; `opened` says this
|
||||
* call opened it. For windows the shell brings forward itself, such as an
|
||||
* app widget's (see inProcessTrayWidget). Hosts that leave it out can't.
|
||||
*/
|
||||
openInProcessAppInBackground?: (
|
||||
windowId: string,
|
||||
surfaceId: string,
|
||||
create: (options: InProcessAppOptions) => InProcessWindow,
|
||||
) => { window: InProcessWindow; opened: boolean };
|
||||
/** Get this app's shared worker host, spawning the worker on first use. */
|
||||
ensureWorkerHost: (createWorker: () => Worker) => WorkerAppHost;
|
||||
/** Submit a window surface's painted frame, as planes (windows created outside launchInProcessApp). */
|
||||
@@ -120,6 +131,27 @@ export type TextEditorHost = {
|
||||
requestRender: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* A tray widget (see Shell.setTrayIcon) whose window is a main-thread
|
||||
* singleton app window, opened in the background while the switcher's
|
||||
* selection is on it; undefined on hosts that can't do that.
|
||||
*/
|
||||
export function inProcessTrayWidget(
|
||||
ctx: AppContext,
|
||||
windowId: string,
|
||||
surfaceId: string,
|
||||
create: (options: InProcessAppOptions) => InProcessWindow,
|
||||
): TrayWidget | undefined {
|
||||
const open = ctx.openInProcessAppInBackground;
|
||||
if (!open) return undefined;
|
||||
return {
|
||||
openWindow: () => {
|
||||
const { window, opened } = open(windowId, surfaceId, create);
|
||||
return { window: window.window, opened };
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch-or-focus flow shared by the worker-hosted apps: focus the app's
|
||||
* existing window if one is open, otherwise open a window in the app's shared
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type AppDefinition } from "../app-definition";
|
||||
import { inProcessTrayWidget, type AppDefinition } from "../app-definition";
|
||||
import { createWeatherAppWindow, WEATHER_SURFACE_ID, WEATHER_WINDOW_ID } from "./weather-app";
|
||||
import { startWeatherIndicators } from "./weather-indicators";
|
||||
|
||||
@@ -6,7 +6,10 @@ const weatherApp: AppDefinition = {
|
||||
appId: "weather",
|
||||
title: "Weather",
|
||||
icon: "cloud-sun",
|
||||
boot: () => startWeatherIndicators(),
|
||||
// Selected in the switcher, the status-bar indicator shows the app's window.
|
||||
boot: (ctx) => startWeatherIndicators(
|
||||
inProcessTrayWidget(ctx, WEATHER_WINDOW_ID, WEATHER_SURFACE_ID, createWeatherAppWindow),
|
||||
),
|
||||
launch: (ctx) => ctx.launchInProcessApp(WEATHER_WINDOW_ID, WEATHER_SURFACE_ID, createWeatherAppWindow),
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { weatherBridge } from "../../native/weather";
|
||||
import { onAnySettingChanged } from "../../ui/dashboard-settings";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { shell, type TrayWidget } from "../../ui/shell/shell";
|
||||
import { isSystemCardWidgetInUse } from "../glanceboard/configuration";
|
||||
import { drawWeatherReading, measureWeatherReading, weatherReading, type WeatherReading } from "./weather-icons";
|
||||
import { weatherShowInStatusBarSetting, weatherShowOnSystemCardSetting } from "./weather-settings";
|
||||
@@ -12,6 +12,7 @@ const TRAY_HEIGHT = 24;
|
||||
const TRAY_ICON_SIZE = 20;
|
||||
|
||||
let started = false;
|
||||
let trayWidget: TrayWidget | undefined;
|
||||
/** What the tray currently shows, to skip rebuilding an unchanged icon. */
|
||||
let trayShown: { key: string; font: UiFont } | null = null;
|
||||
|
||||
@@ -19,11 +20,13 @@ let trayShown: { key: string; font: UiFont } | null = null;
|
||||
* Shell-lifetime subscription: keeps the hourly background refresh running
|
||||
* while the status-bar indicator is enabled, or the system-card one is and
|
||||
* the system card is on an enabled Glanceboard, and the tray icon in sync.
|
||||
* The system card reads the bridge itself while it shows.
|
||||
* The system card reads the bridge itself while it shows. `widget` makes
|
||||
* the tray icon selectable in the switcher.
|
||||
*/
|
||||
export function startWeatherIndicators(): void {
|
||||
export function startWeatherIndicators(widget?: TrayWidget): void {
|
||||
if (started) return;
|
||||
started = true;
|
||||
trayWidget = widget;
|
||||
weatherBridge.onStateChange(syncWeatherIndicators);
|
||||
onAnySettingChanged(syncWeatherIndicators);
|
||||
}
|
||||
@@ -37,7 +40,7 @@ function syncWeatherIndicators(): void {
|
||||
const key = reading ? `${reading.condition}|${reading.isDaytime}|${reading.temperature}` : null;
|
||||
if (key === (trayShown?.key ?? null) && (!trayShown || trayShown.font === font)) return;
|
||||
trayShown = key === null ? null : { key, font };
|
||||
shell.setTrayIcon(TRAY_ICON_ID, reading ? buildWeatherTrayIcon(reading, font) : null);
|
||||
shell.setTrayIcon(TRAY_ICON_ID, reading ? buildWeatherTrayIcon(reading, font) : null, trayWidget);
|
||||
}
|
||||
|
||||
/** Condition icon and temperature, baked to a raster so the tray keeps one stable image. */
|
||||
|
||||
Reference in new issue
Block a user