From c71dbbc9f206651705964138393d4fa4c11b4b65 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Fri, 10 Jul 2026 23:44:17 -0700 Subject: [PATCH] Notifications app checks for and requests notifications access --- app/g2/dashboard-controller.ts | 7 +++++++ app/native/notification-access.ts | 33 +++++++++++++++++++++++++++++++ app/ui/notifications.ts | 9 ++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/native/notification-access.ts diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 704fd496..2d5e4a67 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -8,6 +8,7 @@ import { startForegroundNotification, stopForegroundNotification, updateForegrou import { mediaControllerBridge } from "../native/media-controller"; import { nightscoutBridge } from "../native/nightscout-bridge"; import { onAndroidNotificationPosted } from "../native/notification-icons"; +import { isNotificationListenerEnabled, requestNotificationListenerAccess } from "../native/notification-access"; import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict"; import { grayImageToPreviewSource } from "../native/gray-image-preview"; import { firmwareIncompatibilityMessage } from "./firmware-compat"; @@ -863,6 +864,12 @@ class DashboardController { return; } if (appId === "notifications") { + // Without notification-listener access the tray reads as empty; prompt + // the user on the phone so the on-glasses "grant permission" message is + // actionable. The app still opens to show that message. + if (!isNotificationListenerEnabled()) { + requestNotificationListenerAccess(); + } await this.launchInProcessApp(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow); return; } diff --git a/app/native/notification-access.ts b/app/native/notification-access.ts new file mode 100644 index 00000000..3925e139 --- /dev/null +++ b/app/native/notification-access.ts @@ -0,0 +1,33 @@ +import { Utils } from "@nativescript/core"; + +declare const com: any; + +/** + * Notification-listener access ("read notifications") checks. Faceclaw reads + * the phone's active notifications through + * FaceclawMediaNotificationListenerService to mirror them onto the glasses + * (top-bar icons and the Notifications app). That service only connects once + * the user grants notification access in system settings; until then it never + * binds, so getActiveNotifications() returns nothing and the mirror is blank. + * + * The underlying check/launch live in FaceclawEvenAppDetector (which also uses + * them to detect the stock Even app's notification-service conflict); these are + * thin wrappers so the Notifications app can gate on the permission without + * reaching through the Even-app-conflict API. + */ + +/** True when the user has granted Faceclaw notification-listener access. */ +export function isNotificationListenerEnabled(): boolean { + if (!global.isAndroid) return true; + const context = Utils.android.getApplicationContext(); + if (!context) return false; + return Boolean(com.faceclaw.app.FaceclawEvenAppDetector.isNotificationAccessEnabled(context)); +} + +/** Open the system screen where the user grants Faceclaw notification access. */ +export function requestNotificationListenerAccess(): void { + if (!global.isAndroid) return; + const context = Utils.android.getApplicationContext(); + if (!context) return; + com.faceclaw.app.FaceclawEvenAppDetector.openNotificationAccessSettings(context); +} diff --git a/app/ui/notifications.ts b/app/ui/notifications.ts index f6c0fea1..60315442 100644 --- a/app/ui/notifications.ts +++ b/app/ui/notifications.ts @@ -12,6 +12,7 @@ import { type AndroidNotification, type AndroidNotificationAction, } from "../native/notification-icons"; +import { isNotificationListenerEnabled } from "../native/notification-access"; import { noteStaleDataUsed, renderPassAllowsStaleData } from "../util/render-freshness"; import { type DashboardInputEvent, type Layer, type LayerContext, type PaintBelow } from "./layers"; @@ -81,7 +82,13 @@ export class NotificationsListLayer implements Layer { image.drawText(font, width - 96, PAGE_Y + 9, `${selectedIndex + 1}/${notifications.length}`, 150); if (!notifications.length) { - image.drawText(font, 24, 72, "No current Android notifications.", 190); + const message = isNotificationListenerEnabled() + ? "No current Android notifications." + : "Grant permission on your phone to view notifications on the glasses."; + const messageLines = wrapText(font, message, width - 48); + for (let index = 0; index < messageLines.length; index++) { + image.drawText(font, 24, 72 + index * LINE_HEIGHT, messageLines[index]!, 190); + } image.drawText(font, 24, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; }