forked from Blendman974/faceclaw
Notifications app checks for and requests notifications access
This commit is contained in:
1 parent
17cc0bba83
commit
c71dbbc9f2
3 files changed
+48
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user