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,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