iOS: Notifications are selectable via the task switcher

This commit is contained in:
James Babcock committed 2026-10-31 13:22:55 -07:00
1 parent 032797f0f6
commit 12c24529fb
3 files changed
+82 -11

No files matched your search

+1
View File
@@ -6,6 +6,7 @@
* Make BLE benchmark work on iOS
* Ensure connection is re-set to 2M on reconnect
* Add support for embedded icons and custom layouts in Android notifications
* iOS: Notifications are selectable via the task switcher
## 0.8.5 - 2026-10-25
+42 -10
View File
@@ -32,6 +32,7 @@ import { firmwareIncompatibilityMessage, hasCompatibleFirmware } from './firmwar
import { isHaltedSessionPhase, suppressAutoReconnect } from './reconnect-policy'
import { deviceAddressError } from './ios-peripheral-identity'
import { createLauncherWindow, LAUNCHER_SURFACE_ID } from '../apps/launcher/launcher-app'
import { createNotificationsAppWindow, NOTIFICATIONS_SURFACE_ID, NOTIFICATIONS_WINDOW_ID } from '../apps/notifications/notifications-app'
import { ALL_APPS } from '../apps/all-apps'
import type { AppContext, AppDefinition, AppLaunchParams } from '../apps/app-definition'
import { WorkerAppHost } from '../ui/shell/worker-window'
@@ -210,6 +211,8 @@ export class IosPreviewController {
getScreenTimeoutMs: () => null,
requestShellRender: () => this.requestShellRender(),
onWindowsChanged: () => { this.requestShellRender(); this.syncEvenHubPhoneUi() },
openNotificationsWindow: () =>
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow),
onSwitcherBarHeightChanged: () => {
this.relayout()
shell.foregroundWindow()?.requestRender()
@@ -623,6 +626,7 @@ export class IosPreviewController {
const { nx, ny } = mirrorToPanelFraction(this.previewCrop, mirrorNx, mirrorNy)
const x = Math.max(0, Math.min(639, Math.floor(nx * 640)))
const y = Math.max(0, Math.min(479, Math.floor(ny * 480)))
if (!shell.hasOverlay() && shell.focusStatusItemAt(x, y)) { this.requestShellRender(); return }
const window = shell.foregroundWindow()
if (!shell.hasOverlay() && sidebarStripVisible(shell.getFocus(), window?.appId)
&& isOnSwitcherEdge(x, y, window?.heightMode ?? 'min', window?.appId)) {
@@ -684,6 +688,7 @@ export class IosPreviewController {
appId: app.appId, apps: ALL_APPS, actions: this.actions,
launchApp: (id, params) => this.launchApp(id, params), uninstallApp: id => this.uninstallApp(id),
launchInProcessApp: (id, surface, create) => this.launchInProcessApp(id, surface, create),
openInProcessAppInBackground: (id, surface, create) => this.openInProcessAppInBackground(id, surface, create),
ensureWorkerHost: create => this.ensureWorkerHost(app.appId, create),
submitWindowFrame: (id, planes) => this.submit(id, planes),
setWindowSurfaceVisible: (id, visible) => this.setWindowSurfaceVisible(id, visible),
@@ -695,14 +700,44 @@ export class IosPreviewController {
create: (options: InProcessAppOptions) => InProcessWindow): Promise<void> {
const existing = this.inProcessApps.get(windowId)
if (existing) { shell.focusWindow(windowId); existing.requestRender(); this.requestShellRender(); return }
// Apps can request a render while their factory runs (Nightscout's tray
// subscription does). The surface only exists once the factory returns.
// The explicit render below supplies a fresh frame after configuration.
let surfaceReady = false
const { app, surface } = this.createInProcessApp(windowId, surfaceId, create)
await this.configureWindow(app.window)
surface.ready = true
shell.registerWindow(app.window); shell.focusWindow(windowId)
app.requestRender(); this.requestShellRender()
}
/**
* An in-process singleton app's window, opened in the background (neither
* foregrounded nor focused) unless it is open already, for the shell to
* bring forward itself: the Notifications window under a notification
* selected in the switcher, or an app widget's window under the widget.
* Display calls run in order and frames wait on displayReady before
* queueing, so the surface configure queued here lands ahead of any frame
* and of the shell foregrounding the window, which it may do at once.
*/
private openInProcessAppInBackground(windowId: string, surfaceId: string,
create: (options: InProcessAppOptions) => InProcessWindow): { window: InProcessWindow; opened: boolean } {
const existing = this.inProcessApps.get(windowId)
if (existing) return { window: existing, opened: false }
const { app, surface } = this.createInProcessApp(windowId, surfaceId, create)
void this.configureWindow(app.window).catch(error => this.fail(error))
surface.ready = true
shell.registerWindow(app.window)
return { window: app, opened: true }
}
/**
* Create an in-process singleton app's window (not yet registered with the
* shell). Its frames reach the compositor only while `surface.ready`: apps
* can request a render while their factory runs (Nightscout's tray
* subscription does), before the caller has configured the surface.
*/
private createInProcessApp(windowId: string, surfaceId: string,
create: (options: InProcessAppOptions) => InProcessWindow): { app: InProcessWindow; surface: { ready: boolean } } {
const surface = { ready: false }
const app = create({
actions: this.actions, submitFrame: planes => surfaceReady ? this.submit(surfaceId, planes, () => surfaceReady) : Promise.resolve(),
actions: this.actions, submitFrame: planes => surface.ready ? this.submit(surfaceId, planes, () => surface.ready) : Promise.resolve(),
setSurfaceVisible: visible => this.setWindowSurfaceVisible(surfaceId, visible),
removeSurface: () => { surfaceReady = false; this.removeWindowSurface(surfaceId) },
removeSurface: () => { surface.ready = false; this.removeWindowSurface(surfaceId) },
reconfigureSurface: () => {
const window = shell.getWindows().find(w => w.windowId === windowId)
if (window) void this.configureWindow(window).catch(error => this.fail(error))
@@ -711,10 +746,7 @@ export class IosPreviewController {
onClosed: () => { this.inProcessApps.delete(windowId) },
})
this.inProcessApps.set(windowId, app)
await this.configureWindow(app.window)
surfaceReady = true
shell.registerWindow(app.window); shell.focusWindow(windowId)
app.requestRender(); this.requestShellRender()
return { app, surface }
}
private ensureWorkerHost(appId: string, create: () => Worker): WorkerAppHost {
const existing = this.appHosts.get(appId)
+39 -1
View File
@@ -28,6 +28,7 @@ function fixture() {
const battery = {};
const tasks = new Map(), sent = [], previews = [], received = [], errors = [];
const boardStats = { starts: 0, stops: 0, paints: 0 };
const registered = [], inProcessApps = [];
const settings = { lock: true, enabled: true, tap: true, hold: true, tilt: true, duration: 3000, depth: 0 };
const clock = { Date: class extends Date { static now() { return now; } },
setTimeout: (fn, ms) => { tasks.set(++nextTask, { fn, at: now + ms }); return nextTask; },
@@ -44,7 +45,7 @@ function fixture() {
// The launcher repaints into whichever display target the controller has after a switch.
requestRender() { void controller?.displayReady.then(() => controller.display?.submitSurfaceFrame('launcher', launcherPixels, fullRect, 'launcher')); }, setScreenOn() {} };
const shell = {
configure: options => { shellOptions = options; }, registerWindow() {}, focusWindow() {},
configure: options => { shellOptions = options; }, registerWindow: window => registered.push(window), focusWindow() {},
wake: () => { screenOn = true; shellOptions.onScreenStateChanged(true); },
sleep: () => { screenOn = false; shellOptions.onScreenStateChanged(false); },
isScreenOn: () => screenOn, getWindows: () => [window], foregroundWindow: () => window,
@@ -138,6 +139,7 @@ function fixture() {
'../native/notification-icons.ios': { bindIosNotifications() {}, iosNotificationsChanged() {}, onIosNotificationPopup: () => () => {}, readActiveNotifications: () => [] },
'../native/notification-sources': { shouldShowNotificationOnGlasses: () => true },
"../native/compass.ios": { bindCompassSession() {}, receiveCompassEvent() {} },
'../native/bandwidth-benchmark.ios': { bindBandwidthBenchmarkSession() {} },
'@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) },
knownFolders: { documents: () => ({ path: '/tmp' }) }, path },
'../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {}, setRawSession() {}, onSpeechEnd: () => () => {} } },
@@ -159,6 +161,12 @@ function fixture() {
'../apps/evenhub/installed-apps': {}, '../apps/evenhub/manager': { onPhoneShownChanged: () => () => {}, phoneUiButton: () => null },
'../apps/evenhub/updates': {}, '../apps/evenhub': {},
'../apps/launcher/launcher-app': { createLauncherWindow: () => window, LAUNCHER_SURFACE_ID: 'launcher' },
'../apps/notifications/notifications-app': { NOTIFICATIONS_SURFACE_ID: 'window:notifications', NOTIFICATIONS_WINDOW_ID: 'notifications',
createNotificationsAppWindow: options => {
const app = { options, window: { windowId: 'notifications', surfaceId: 'window:notifications', appId: 'notifications', heightMode: 'min' } };
inProcessApps.push(app);
return app;
} },
'../apps/all-apps': { ALL_APPS: [{ appId: 'glanceboard', glanceboard: provider }] },
'../apps/onboarding/onboarding-progress': { claimGlassesOnboardingAutoLaunch: () => false },
'../ui/shell/worker-window': {}, '../ui/shell/in-process-window': {},
@@ -205,6 +213,7 @@ function fixture() {
async function phone(type, origin = 'ring') { controller.gesture(type, origin); await render(); }
async function connect() { await controller.connect(); await render(); }
return { controller, shell, battery, remoteHost, keyboardChanged: session => shellOptions.onKeyboardInputChanged(session), settings, phoneState, observers,
get shellOptions() { return shellOptions; }, registered, inProcessApps,
get bridge() { return bridge; }, connect, wear: wearing => bridge.emitWear(wearing), settingsChanged: () => settingsChanged(), sent, previews, received, boardStats, hardware, phone, advance, render };
}
const assertBlank = pixels => assert.ok(pixels.every(p => p === 0));
@@ -258,3 +267,32 @@ test('ring battery reported through the glasses reaches the shell while connecte
await f.controller.disconnect(); await f.render();
assert.deepEqual([f.battery.ring, f.battery.ringCharging], [null, null]);
});
test('the switcher can open the Notifications window in the background, once, with a live surface', async () => {
const f = fixture();
await f.render();
const opened = f.shellOptions.openNotificationsWindow();
assert.equal(opened.opened, true);
const [app] = f.inProcessApps;
assert.equal(opened.window, app);
assert.ok(f.registered.includes(app.window), 'registered with the shell for the switcher to foreground');
// A frame painted at once (the shell foregrounds and repaints the window
// straight away) lands on the surface configured ahead of it.
void app.options.submitFrame([{ image: new images.GrayImage(640, 480, 90), x: 0, y: 0 }], 0, 1);
await f.render();
const surface = f.controller.display.surfaces.get('window:notifications');
assert.ok(surface, 'surface configured');
assert.equal(surface.pixels[0], 90);
assert.equal(surface.visible, false, 'stays hidden until the shell foregrounds it');
// Already open: the same window, nothing new created or registered.
const registeredBefore = f.registered.length;
const again = f.shellOptions.openNotificationsWindow();
assert.deepEqual([again.opened, again.window, f.inProcessApps.length, f.registered.length], [false, app, 1, registeredBefore]);
// Closed (the selection moved on): frames stop, and the next open makes a new window.
app.options.removeSurface(); app.options.onClosed();
void app.options.submitFrame([{ image: new images.GrayImage(640, 480, 90), x: 0, y: 0 }], 0, 2);
await f.render();
assert.equal(f.controller.display.surfaces.has('window:notifications'), false);
assert.equal(f.shellOptions.openNotificationsWindow().opened, true);
assert.equal(f.inProcessApps.length, 2);
});