Implement notifications on iOS

This commit is contained in:
James Babcock committed 2026-09-19 11:07:37 -07:00
1 parent 64bf600ef9
commit 67823f66ef
19 files changed
+540 -65

No files matched your search

+1 -1
View File
@@ -134,7 +134,7 @@ export class IosBluetooth {
try { call(id) } catch (error) { clearTimeout(timer); this.pending.delete(id); reject(error) }
})
}
connect(identifier: string): Promise<ConnectionDetails> { return this.operation(identifier, id => this.native.connectRequestId(identifier, id), 20_000) }
connect(identifier: string, requiresANCS = false): Promise<ConnectionDetails> { return this.operation(identifier, id => this.native.connectRequiresANCSRequestId(identifier, requiresANCS, id), 20_000) }
async subscribe(identifier: string, characteristic: string): Promise<void> {
// R1 exposes two notification channels; one may never complete its CCCD
// request. Keep the link alive so the other channel can still be tried.
+4
View File
@@ -0,0 +1,4 @@
import { iosNotificationState, iosNotificationMessage } from './notification-icons.ios'
export function isNotificationListenerEnabled(): boolean { return iosNotificationState() === 'ready' }
export function requestNotificationListenerAccess(): void { /* iOS exposes no deep link to this Bluetooth setting. */ }
export function notificationEmptyMessage(): string { return iosNotificationMessage() }
+5
View File
@@ -31,3 +31,8 @@ export function requestNotificationListenerAccess(): void {
if (!context) return;
com.faceclaw.app.FaceclawEvenAppDetector.openNotificationAccessSettings(context);
}
export function notificationEmptyMessage(): string {
return isNotificationListenerEnabled() ? "No current Android notifications."
: "Grant permission on your phone to view notifications on the glasses.";
}
+44
View File
@@ -0,0 +1,44 @@
import { GrayImage } from '../graphics/image'
import { AncsClient, ANCS_CONNECT_MESSAGE, type AncsState } from '../g2/ancs-client'
import { rememberNotificationSources } from './notification-sources'
export type { AndroidNotification, AndroidNotificationAction } from './notification-types'
export type { NotificationIconsResult, NotificationIconResult } from './notification-icons'
export const ALL_NOTIFICATIONS = 0x7fffffff
let active: AncsClient | null = null
const listeners = new Set<(key: string) => void>()
const popups = new Set<(key: string) => void>()
export function bindIosNotifications(client: AncsClient): void { active = client }
export function iosNotificationsChanged(key?: string, popup = false): void {
const current = active
if (current) rememberNotificationSources(current.read(ALL_NOTIFICATIONS))
for (const listener of listeners) listener(key ?? '')
if (popup && key) for (const listener of popups) listener(key)
}
export function onIosNotificationPopup(listener: (key: string) => void): () => void {
popups.add(listener); return () => { popups.delete(listener) }
}
export function iosNotificationMessage(): string { return active?.statusMessage ?? ANCS_CONNECT_MESSAGE }
export function iosNotificationState(): AncsState { return active?.state ?? 'disconnected' }
export function readActiveNotifications(maxNotifications = 50) { return active?.read(maxNotifications) ?? [] }
export function invokeNotificationAction(key: string, index: number): boolean { return active?.action(key,index) ?? false }
export function dismissNotification(key: string): boolean { return active?.dismiss(key) ?? false }
export function onAndroidNotificationPosted(listener: (key: string) => void): () => void {
listeners.add(listener); return () => { listeners.delete(listener) }
}
// ANCS does not provide app icons. Use a local bell; never fetch notification
// sources or content from a third-party icon service.
function bell(): GrayImage {
const image = new GrayImage(24,24,0)
image.fillRoundedRect(6,5,12,13,220,5)
image.fillRect(4,17,16,2,220)
image.fillRect(10,20,4,2,220)
return image
}
export function readActiveNotificationIcons(maxIcons: number, _allowStale: boolean) {
const sources = new Set(readActiveNotifications(ALL_NOTIFICATIONS).map(n => n.packageName))
return {icons: Array.from(sources).slice(0,Math.max(0,maxIcons)).map(() => bell()),stale:false}
}
export function readNotificationIconByKey(key: string, _allowStale: boolean) {
return {icon: readActiveNotifications(ALL_NOTIFICATIONS).some(n => n.key === key) ? bell() : null,stale:false}
}
+2 -22
View File
@@ -28,28 +28,8 @@ function invalidateIconCaches(): void {
keyedIconCache.clear();
}
export type AndroidNotificationAction = {
index: number;
title: string;
enabled: boolean;
};
export type AndroidNotification = {
key: string;
packageName: string;
appName: string;
title: string;
text: string;
bigText: string;
subText: string;
infoText: string;
summaryText: string;
category: string;
lines: string[];
postTime: number;
when: number;
actions: AndroidNotificationAction[];
};
import type { AndroidNotification, AndroidNotificationAction } from "./notification-types";
export type { AndroidNotification, AndroidNotificationAction } from "./notification-types";
export type NotificationIconsResult = {
icons: GrayImage[];
+8
View File
@@ -0,0 +1,8 @@
/** Shared notification model; Android names are retained for existing callers. */
export type AndroidNotificationAction = { index: number; title: string; enabled: boolean };
export type AndroidNotification = {
key: string; packageName: string; appName: string; title: string; text: string;
bigText: string; subText: string; infoText: string; summaryText: string;
category: string; lines: string[]; postTime: number; when: number;
actions: AndroidNotificationAction[]; dismissLabel?: string;
};