experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat tile-preload: add context aliases setMode/getMode/watchMode/getWindowsInSpace

+45
+45
backend/electron/tile-preload.cts
··· 1247 1247 ? contextStrict.windowsInSpace(spaceId as string) 1248 1248 : contextCompat.windowsInSpace(spaceId as string); 1249 1249 }, 1250 + 1251 + // ── Convenience aliases ────────────────────────────────────────── 1252 + // These wrap the generic get/set/subscribe surface for the common 1253 + // 'mode' key, mirroring v1 preload.js api.context.setMode / getMode 1254 + // / watchMode / getWindowsInSpace. 1255 + 1256 + setMode: (mode: unknown) => hasContextCapability() 1257 + ? contextStrict.set('mode', mode) 1258 + : contextCompat.set('mode', mode), 1259 + 1260 + getMode: () => hasContextCapability() 1261 + ? contextStrict.get('mode', null) 1262 + : contextCompat.get('mode', null), 1263 + 1264 + /** 1265 + * Watch for mode changes. 1266 + * Subscribes to `context:changed` and fires callback with the new mode 1267 + * value whenever the 'mode' key changes. Also performs an initial get so 1268 + * the caller receives the current value immediately. 1269 + * Returns an unsubscribe function. 1270 + */ 1271 + watchMode: (callback: (mode: unknown, entry?: unknown) => void) => { 1272 + const unsubscribe = subscribeImpl('context:changed', (msg: unknown) => { 1273 + const m = msg as { key?: string; value?: unknown }; 1274 + if (m.key === 'mode') { 1275 + callback(m.value ?? null, m); 1276 + } 1277 + }); 1278 + // Fire initial value so caller doesn't have to do a separate getMode(). 1279 + const getPromise = hasContextCapability() 1280 + ? contextStrict.get('mode', null) 1281 + : contextCompat.get('mode', null); 1282 + (getPromise as Promise<unknown>).then((result: unknown) => { 1283 + const r = result as { success?: boolean; data?: unknown; value?: unknown } | null; 1284 + const value = r && typeof r === 'object' ? (('data' in r) ? (r as { data: unknown }).data : (r as { value: unknown }).value) : null; 1285 + callback(value ?? null, null); 1286 + }).catch(() => { 1287 + callback(null, null); 1288 + }); 1289 + return unsubscribe; 1290 + }, 1291 + 1292 + getWindowsInSpace: (spaceId: unknown) => hasContextCapability() 1293 + ? contextStrict.windowsInSpace(spaceId as string) 1294 + : contextCompat.windowsInSpace(spaceId as string), 1250 1295 }; 1251 1296 1252 1297 // ── Dialogs ───────────────────────────────────────────────────────