Turn on screen when Android notifications are received

This commit is contained in:
James Babcock committed 2026-06-01 00:40:55 -07:00
1 parent 468291aac3
commit 5a92637537
7 files changed
+205 -12

No files matched your search

+26
View File
@@ -6,6 +6,7 @@ import { FaceclawCommunicatorBridge, type FrameMetrics, type RawInputEvent } fro
import { startForegroundNotification, stopForegroundNotification, updateForegroundNotification } from "../native/foreground-service";
import { mediaControllerBridge } from "../native/media-controller";
import { nightscoutBridge } from "../native/nightscout";
import { onAndroidNotificationPosted } from "../native/notification-icons";
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
import { grayImageToPreviewSource, grayImageToPreviewSourceWithBitmapFactory } from "../native/gray-image-preview";
import { voiceControlBridge } from "../native/voice-control";
@@ -18,6 +19,7 @@ import {
getDashboardSystemCardName,
isDashboardVoiceControlEnabled,
noteDashboardPhoneTextInput,
openAndroidNotificationFromSleep,
openTelepromptDocument,
receiveInput,
resetDashboardSleepTimerAndWake,
@@ -137,6 +139,7 @@ class DashboardController {
private offNightscout: (() => void) | null = null;
private offVoiceStatus: (() => void) | null = null;
private offVoiceWakeWord: (() => void) | null = null;
private offAndroidNotification: (() => void) | null = null;
private lastInput = "waiting...";
private lastSys = "none yet";
private renderInProgress = false;
@@ -160,6 +163,11 @@ class DashboardController {
startDedicatedVoiceInput: (mode) => this.startDedicatedVoiceInput(mode),
stopDedicatedVoiceInput: () => this.stopDedicatedVoiceInput(),
});
this.offAndroidNotification = onAndroidNotificationPosted((notificationKey) => {
void this.handleAndroidNotificationPosted(notificationKey).catch((error) => {
this.appendLog(`notification wake failed: ${this.formatError(error)}`);
});
});
}
subscribe(listener: DashboardListener): () => void {
@@ -701,6 +709,24 @@ class DashboardController {
}
}
private async handleAndroidNotificationPosted(notificationKey: string): Promise<void> {
const changed = openAndroidNotificationFromSleep(notificationKey);
if (!changed) {
if (this.phase === "connected" && this.communicator) {
await this.requestRender("interval");
}
return;
}
this.appendLog("android notification woke dashboard");
if (this.phase === "connected" && this.communicator) {
await this.requestRender("initial");
return;
}
const image = drawDashboard();
this.updateDisplayPreviewFromImage(image);
}
private startVoiceControlIfEnabled(): void {
if (!this.communicator) return;
if (!isDashboardVoiceControlEnabled()) return;
+40
View File
@@ -8,6 +8,8 @@ const ICON_CACHE_MS = 5_000;
let cachedIcons: GrayImage[] = [];
let cachedAtMs = 0;
let notificationListenerProxy: any | null = null;
const notificationPostedListeners = new Set<(notificationKey: string) => void>();
export type AndroidNotificationAction = {
index: number;
@@ -95,6 +97,17 @@ export function dismissNotification(notificationKey: string): boolean {
);
}
export function onAndroidNotificationPosted(listener: (notificationKey: string) => void): () => void {
notificationPostedListeners.add(listener);
ensureNotificationPostedListener();
return () => {
notificationPostedListeners.delete(listener);
if (notificationPostedListeners.size === 0) {
removeNotificationPostedListener();
}
};
}
function normalizeNotification(value: any): AndroidNotification | null {
if (!value || typeof value !== "object") return null;
const key = String(value.key ?? "");
@@ -120,6 +133,33 @@ function normalizeNotification(value: any): AndroidNotification | null {
};
}
function ensureNotificationPostedListener(): void {
if (!global.isAndroid || notificationListenerProxy) return;
notificationListenerProxy = new com.faceclaw.app.FaceclawNotificationListener({
onNotificationPosted: (notificationKey: string) => {
cachedAtMs = 0;
const key = String(notificationKey);
const listeners = Array.from(notificationPostedListeners);
setTimeout(() => {
for (const listener of listeners) {
listener(key);
}
}, 0);
},
});
com.faceclaw.app.FaceclawMediaNotificationListenerService.addNotificationListener(
notificationListenerProxy,
);
}
function removeNotificationPostedListener(): void {
if (!global.isAndroid || !notificationListenerProxy) return;
com.faceclaw.app.FaceclawMediaNotificationListenerService.removeNotificationListener(
notificationListenerProxy,
);
notificationListenerProxy = null;
}
function normalizeAction(value: any): AndroidNotificationAction | null {
if (!value || typeof value !== "object") return null;
const title = String(value.title ?? "");
+13 -1
View File
@@ -50,7 +50,7 @@ import {
import { Layer, LayerActions, LayerStack, type DashboardInputEvent, type LayerContext } from "./layers";
import { drawRightValueMenuItem, drawToggleMenuItem, MenuLayer } from "./menu";
import { StopwatchLayer } from "./apps/stopwatch";
import { NotificationsListLayer } from "./notifications";
import { NotificationsListLayer, SingleNotificationLayer } from "./notifications";
import { TranscribeLayer } from "./apps/transcribe";
import { TelepromptLayer } from "./apps/teleprompt";
import { ScreenTestLayer } from "./apps/screen-test";
@@ -268,6 +268,18 @@ export function openTelepromptDocument(text?: string): void {
dashboardLayers.push(new TelepromptLayer(dashboardState.telepromptDocumentText));
}
export function openAndroidNotificationFromSleep(notificationKey: string, nowMs = Date.now()): boolean {
if (!notificationKey || dashboardState.screenOn) return false;
dashboardState.lastInputAtMs = nowMs;
dashboardState.screenOn = true;
dashboardState.tiledWakePaintPending = dashboardState.wakeMode === "tiled";
dashboardLayers.clearToBase();
dashboardLayers.push(createRootMenuLayer());
dashboardLayers.push(new SingleNotificationLayer(notificationKey));
return true;
}
export function resetDashboardSleepTimerAndWake(nowMs = Date.now()): boolean {
dashboardState.lastInputAtMs = nowMs;
if (dashboardState.screenOn) return false;
+1 -1
View File
@@ -113,7 +113,7 @@ export class NotificationsListLayer implements Layer {
}
}
class SingleNotificationLayer implements Layer {
export class SingleNotificationLayer implements Layer {
private selectedMenuIndex = 0;
constructor(private readonly notificationKey: string) {}