Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe87e75fc2
|
||
|
|
f029e3ce91
|
||
|
|
5929259d84
|
No files matched your search
@@ -249,6 +249,8 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre
|
||||
|
||||
fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState()
|
||||
|
||||
fun configureHeadUpWake(enabled: Int, angle: Int) = core.configureHeadUpWake(enabled, angle)
|
||||
|
||||
fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean =
|
||||
core.startBandwidthBenchmark(messageSize, windowSize, durationMs)
|
||||
|
||||
|
||||
-12
@@ -504,18 +504,6 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun dismissAllNotifications(): Boolean {
|
||||
val service = activeService ?: return false
|
||||
return try {
|
||||
service.cancelAllNotifications()
|
||||
true
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "failed to dismiss all notifications", t)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun emitNotificationPosted(key: String?) {
|
||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NotificationsListLayer } from "../../ui/notifications";
|
||||
import { NotificationFilterLayer } from "../../ui/notification-filter";
|
||||
import { ALL_NOTIFICATIONS, dismissAllNotifications, onAndroidNotificationsChanged, readActiveNotifications } from "../../native/notification-icons";
|
||||
import { onAndroidNotificationsChanged } from "../../native/notification-icons";
|
||||
import {
|
||||
createInProcessWindow,
|
||||
YieldAtRootLayer,
|
||||
@@ -32,15 +32,6 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr
|
||||
ctx.stack.pop();
|
||||
ctx.stack.push(new NotificationFilterLayer());
|
||||
},
|
||||
}, {
|
||||
label: "Dismiss all notifications",
|
||||
description: "Dismiss notifications on the phone and glasses. System-protected notifications may remain.",
|
||||
disabled: () => readActiveNotifications(ALL_NOTIFICATIONS).length === 0,
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.pop();
|
||||
dismissAllNotifications();
|
||||
created.requestRender();
|
||||
},
|
||||
}],
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new NotificationsListLayer()),
|
||||
|
||||
@@ -78,7 +78,7 @@ import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-a
|
||||
import { appViewportRect, isOnSwitcherEdge, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
|
||||
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
|
||||
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
|
||||
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, getHeadUpPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||
import {
|
||||
getInstalledEvenHubAppById,
|
||||
@@ -296,6 +296,7 @@ class DashboardController {
|
||||
private silentMode = false;
|
||||
// Brightness value last pushed to the glasses; see pushBrightness.
|
||||
private lastPushedBrightness: string | null = null;
|
||||
private lastPushedHeadUp: string | null = null;
|
||||
// Last battery level the glasses reported, kept across disconnects so a
|
||||
// drop-off right after a low reading can be explained as a flat battery.
|
||||
private lastHeadsetBattery: number | null = null;
|
||||
@@ -476,6 +477,7 @@ class DashboardController {
|
||||
// Apply a firmware-debug-flags toggle live while connected (Java dedups).
|
||||
this.pushFirmwareDebugFlags();
|
||||
this.pushBrightness();
|
||||
this.pushHeadUpPreferences();
|
||||
this.syncEvenHubScreenOffSetting();
|
||||
// Display mode size first: a reflow repositions every surface too, so
|
||||
// the band-position check after it then has nothing left to do.
|
||||
@@ -1084,6 +1086,19 @@ class DashboardController {
|
||||
});
|
||||
}
|
||||
|
||||
private pushHeadUpPreferences(force = false): void {
|
||||
if (!global.isAndroid || !this.communicator) return;
|
||||
const { enabled, angle } = getHeadUpPreferences();
|
||||
if (enabled < 0 && angle < 0) return;
|
||||
const value = JSON.stringify({ enabled, angle });
|
||||
if (!force && value === this.lastPushedHeadUp) return;
|
||||
this.lastPushedHeadUp = value;
|
||||
void this.communicator.configureHeadUpWake(enabled, angle).catch(error => {
|
||||
this.lastPushedHeadUp = null;
|
||||
this.appendLog(`head-up configuration failed: ${this.formatError(error)}`);
|
||||
});
|
||||
}
|
||||
|
||||
/** Save the occupied part of the composited screen as a 4-bit grayscale PNG. */
|
||||
saveScreenshot(): string {
|
||||
const path = this.display?.saveScreenshot(shell.screenshotCropRect()) ?? "";
|
||||
@@ -1533,6 +1548,7 @@ class DashboardController {
|
||||
// ahead of them. Mirrors ensurePreviewDisplay.
|
||||
await communicator.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT);
|
||||
await communicator.configureBrightness(getBrightnessPreferences());
|
||||
this.pushHeadUpPreferences(true);
|
||||
this.offState = communicator.onStateChange((state) => {
|
||||
if (state.phase !== "connected") resetRingInputFilter();
|
||||
if (isHaltedSessionPhase(state.phase)) {
|
||||
@@ -1570,6 +1586,7 @@ class DashboardController {
|
||||
// mode-7 control message once the dashboard container is warmed up.
|
||||
this.pushFirmwareDebugFlags();
|
||||
this.pushBrightness(true);
|
||||
this.pushHeadUpPreferences(true);
|
||||
this.handRingBackToGlassesIfNeeded();
|
||||
}
|
||||
if (mappedPhase !== "connected" && mappedPhase !== "charging") {
|
||||
|
||||
@@ -519,6 +519,11 @@ export class FaceclawCommunicatorBridge {
|
||||
await this.enqueueJavaCall(() => this.communicator.enableWearDetectionAndRequestState());
|
||||
}
|
||||
|
||||
/** -1 leaves a field unchanged. The native session retains explicit values across reconnects. */
|
||||
async configureHeadUpWake(enabled: number, angle: number): Promise<void> {
|
||||
await this.enqueueJavaCall(() => this.communicator.configureHeadUpWake(enabled, angle));
|
||||
}
|
||||
|
||||
/** Whether the transport prelude has finished (each arm reports "connected" before it). */
|
||||
isSessionReady(): boolean {
|
||||
return Boolean(this.communicator.isSessionReady());
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { GrayImage } from '../graphics/image'
|
||||
import { pebbleIcon } from '../graphics/pebble-icons'
|
||||
import { AncsClient, ANCS_CONNECT_MESSAGE, type AncsState } from '../g2/ancs-client'
|
||||
import { notificationAppIcon, notificationCategoryIcon } from './notification-app-icons'
|
||||
import { rememberNotificationSources, shouldShowNotificationOnGlasses } from './notification-sources'
|
||||
import { rememberNotificationSources } from './notification-sources'
|
||||
import type { AndroidNotification } from './notification-types'
|
||||
export type { AndroidNotification, AndroidNotificationAction } from './notification-types'
|
||||
export type { NotificationIconsResult, NotificationIconResult, NotificationImageResult } from './notification-icons'
|
||||
@@ -24,23 +24,8 @@ export function onIosNotificationPopup(listener: (key: string) => void): () => v
|
||||
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 readVisibleNotifications(maxNotifications = 50) {
|
||||
return readActiveNotifications(ALL_NOTIFICATIONS)
|
||||
.filter(notification => shouldShowNotificationOnGlasses(notification.packageName))
|
||||
.slice(0, Math.max(0, 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 dismissAllNotifications(): boolean {
|
||||
const client = active
|
||||
if (!client) return false
|
||||
// Snapshot: removals may arrive while dismissal requests are being sent.
|
||||
let accepted = true
|
||||
for (const notification of [...client.read(ALL_NOTIFICATIONS)]) {
|
||||
if (!client.dismiss(notification.key)) accepted = false
|
||||
}
|
||||
return accepted
|
||||
}
|
||||
export function onAndroidNotificationPosted(listener: (key: string) => void): () => void {
|
||||
listeners.add(listener); return () => { listeners.delete(listener) }
|
||||
}
|
||||
@@ -59,7 +44,7 @@ function notificationIcon(notification: AndroidNotification): GrayImage {
|
||||
export function readActiveNotificationIcons(maxIcons: number, _allowStale: boolean) {
|
||||
// One icon per source, standing for its first notification.
|
||||
const sources = new Map<string, AndroidNotification>()
|
||||
for (const n of readVisibleNotifications(ALL_NOTIFICATIONS)) if (!sources.has(n.packageName)) sources.set(n.packageName, n)
|
||||
for (const n of readActiveNotifications(ALL_NOTIFICATIONS)) if (!sources.has(n.packageName)) sources.set(n.packageName, n)
|
||||
const shown = Array.from(sources.values()).slice(0,Math.max(0,maxIcons))
|
||||
return {icons: shown.map(notificationIcon),keys: shown.map(n => n.key),stale:false}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { GrayImage } from "../graphics/image";
|
||||
import { logCurrent, spanCurrent } from "./frame-timings";
|
||||
import { toUint8Array } from "../util/array-util";
|
||||
import { rememberNotificationSources, shouldShowNotificationOnGlasses } from "./notification-sources";
|
||||
import { rememberNotificationSources } from "./notification-sources";
|
||||
import { PHOTO_TONE, grayImageFromPacket } from "./image-files";
|
||||
import { NOTIFICATION_ICON_SIZE } from "./notification-types";
|
||||
|
||||
@@ -21,7 +21,6 @@ const ICON_CACHE_MS = 60_000;
|
||||
|
||||
let cachedIcons: GrayImage[] = [];
|
||||
let cachedKeys: string[] = [];
|
||||
let cachedPackages = new Map<string, string>();
|
||||
let cachedAtMs = 0;
|
||||
const keyedIconCache = new Map<string, { icon: GrayImage | null; atMs: number }>();
|
||||
const KEYED_ICON_CACHE_MAX = 128;
|
||||
@@ -96,7 +95,6 @@ export function readActiveNotificationIcons(maxIcons: number, allowStale: boolea
|
||||
keys.push(index < keyList.size() ? String(keyList.get(index)) : "");
|
||||
}
|
||||
|
||||
cachedPackages = new Map(readActiveNotifications(ALL_NOTIFICATIONS).map(n => [n.key, n.packageName]));
|
||||
cachedIcons = icons;
|
||||
cachedKeys = keys;
|
||||
cachedAtMs = now;
|
||||
@@ -105,12 +103,7 @@ export function readActiveNotificationIcons(maxIcons: number, allowStale: boolea
|
||||
|
||||
/** Copies of the first maxIcons cached icons, with their keys. */
|
||||
function cachedIconsResult(maxIcons: number, stale: boolean): NotificationIconsResult {
|
||||
// Reapply preferences even to a warm/stale cache: toggles take effect immediately.
|
||||
const indices = cachedKeys.map((_, index) => index).filter(index => {
|
||||
const packageName = cachedPackages.get(cachedKeys[index]!);
|
||||
return packageName !== undefined && shouldShowNotificationOnGlasses(packageName);
|
||||
}).slice(0, maxIcons);
|
||||
return { icons: indices.map(index => cachedIcons[index]!.clone()), keys: indices.map(index => cachedKeys[index]!), stale };
|
||||
return { icons: cachedIcons.slice(0, maxIcons).map(icon => icon.clone()), keys: cachedKeys.slice(0, maxIcons), stale };
|
||||
}
|
||||
|
||||
export type NotificationIconResult = {
|
||||
@@ -325,13 +318,6 @@ export function readActiveNotifications(maxNotifications = 50): AndroidNotificat
|
||||
}
|
||||
}
|
||||
|
||||
/** Glasses display only; discover all sources and filter before the display limit. */
|
||||
export function readVisibleNotifications(maxNotifications = 50): AndroidNotification[] {
|
||||
return readActiveNotifications(ALL_NOTIFICATIONS)
|
||||
.filter(notification => shouldShowNotificationOnGlasses(notification.packageName))
|
||||
.slice(0, Math.max(0, maxNotifications));
|
||||
}
|
||||
|
||||
export function invokeNotificationAction(notificationKey: string, actionIndex: number): boolean {
|
||||
if (!global.isAndroid || !notificationKey) return false;
|
||||
invalidateIconCaches();
|
||||
@@ -351,13 +337,6 @@ export function dismissNotification(notificationKey: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
/** Explicit user action: dismiss on the phone as well as on the glasses. */
|
||||
export function dismissAllNotifications(): boolean {
|
||||
if (!global.isAndroid) return false;
|
||||
invalidateIconCaches();
|
||||
return Boolean(com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissAllNotifications());
|
||||
}
|
||||
|
||||
export function onAndroidNotificationPosted(listener: (notificationKey: string) => void): () => void {
|
||||
return addNotificationListener(notificationPostedListeners, listener);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
import { getStringSetting, setStringSetting } from "./settings-store";
|
||||
|
||||
const SOURCES_KEY = "notifications.sources";
|
||||
const DEFAULT_KEY = "notifications.newAppsEnabledByDefault";
|
||||
|
||||
/** Unset preserves the behavior of existing installations. */
|
||||
export function newNotificationAppsEnabledByDefault(): boolean {
|
||||
return getStringSetting(DEFAULT_KEY, "true") !== "false";
|
||||
}
|
||||
|
||||
export function setNewNotificationAppsEnabledByDefault(enabled: boolean): void {
|
||||
setStringSetting(DEFAULT_KEY, String(enabled));
|
||||
}
|
||||
|
||||
export type NotificationSource = {
|
||||
packageName: string;
|
||||
@@ -18,15 +8,8 @@ export type NotificationSource = {
|
||||
showOnGlasses: boolean;
|
||||
};
|
||||
|
||||
type SavedSource = Omit<NotificationSource, "showOnGlasses"> & { showOnGlasses?: boolean };
|
||||
|
||||
/** Sources outlive their active notifications so a muted app can always be re-enabled. */
|
||||
export function readNotificationSources(): NotificationSource[] {
|
||||
const enabled = newNotificationAppsEnabledByDefault();
|
||||
return readSavedSources().map((source) => ({ ...source, showOnGlasses: source.showOnGlasses ?? enabled }));
|
||||
}
|
||||
|
||||
function readSavedSources(): SavedSource[] {
|
||||
try {
|
||||
const parsed = JSON.parse(getStringSetting(SOURCES_KEY, "[]"));
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
@@ -34,7 +17,7 @@ function readSavedSources(): SavedSource[] {
|
||||
.map((source) => ({
|
||||
packageName: source.packageName,
|
||||
appName: typeof source.appName === "string" && source.appName ? source.appName : source.packageName,
|
||||
showOnGlasses: typeof source.showOnGlasses === "boolean" ? source.showOnGlasses : undefined,
|
||||
showOnGlasses: source.showOnGlasses !== false,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
@@ -42,7 +25,7 @@ function readSavedSources(): SavedSource[] {
|
||||
}
|
||||
|
||||
export function rememberNotificationSources(notifications: { packageName: string; appName: string }[]): void {
|
||||
const sources = new Map(readSavedSources().map((source) => [source.packageName, source]));
|
||||
const sources = new Map(readNotificationSources().map((source) => [source.packageName, source]));
|
||||
let changed = false;
|
||||
for (const notification of notifications) {
|
||||
if (!notification.packageName) continue;
|
||||
@@ -52,7 +35,7 @@ export function rememberNotificationSources(notifications: { packageName: string
|
||||
sources.set(notification.packageName, {
|
||||
packageName: notification.packageName,
|
||||
appName,
|
||||
showOnGlasses: previous?.showOnGlasses,
|
||||
showOnGlasses: previous?.showOnGlasses ?? true,
|
||||
});
|
||||
changed = true;
|
||||
}
|
||||
@@ -61,13 +44,12 @@ export function rememberNotificationSources(notifications: { packageName: string
|
||||
}
|
||||
|
||||
export function shouldShowNotificationOnGlasses(packageName: string): boolean {
|
||||
return readNotificationSources().find((source) => source.packageName === packageName)?.showOnGlasses
|
||||
?? newNotificationAppsEnabledByDefault();
|
||||
return readNotificationSources().find((source) => source.packageName === packageName)?.showOnGlasses ?? true;
|
||||
}
|
||||
|
||||
export function setNotificationSourceEnabled(source: { packageName: string; appName: string }, enabled: boolean): void {
|
||||
if (!source.packageName) return;
|
||||
const sources = new Map(readSavedSources().map((item) => [item.packageName, item]));
|
||||
const sources = new Map(readNotificationSources().map((item) => [item.packageName, item]));
|
||||
sources.set(source.packageName, {
|
||||
packageName: source.packageName,
|
||||
appName: source.appName || source.packageName,
|
||||
@@ -75,10 +57,3 @@ export function setNotificationSourceEnabled(source: { packageName: string; appN
|
||||
});
|
||||
setStringSetting(SOURCES_KEY, JSON.stringify(Array.from(sources.values())));
|
||||
}
|
||||
|
||||
/** Set explicit choices only for sources already discovered; leave the future default alone. */
|
||||
export function setAllNotificationSourcesEnabled(enabled: boolean): void {
|
||||
setStringSetting(SOURCES_KEY, JSON.stringify(readSavedSources().map((source) => ({
|
||||
...source, showOnGlasses: enabled,
|
||||
}))));
|
||||
}
|
||||
@@ -555,6 +555,38 @@ export const brightnessSetting = new ConfigSettingEnum<BrightnessSetting>({
|
||||
description: "Auto uses Faceclaw's ambient-light curve; numbers set a fixed level. 2 is the dimmest level.",
|
||||
});
|
||||
|
||||
/** String storage distinguishes an untouched firmware preference from explicit ON/OFF. */
|
||||
class HeadUpWakeSetting extends ConfigSettingBoolean {
|
||||
get(): boolean { return getStringSetting(this.storageKey, "true") !== "false"; }
|
||||
set(value: boolean): boolean { setStringSetting(this.storageKey, String(value)); return value; }
|
||||
}
|
||||
|
||||
export const headUpWakeSetting = new HeadUpWakeSetting({
|
||||
id: "head-up-wake", label: "Head-up wake", storageKey: "display.headUpWake", defaultValue: true,
|
||||
description: "Enable waking the glasses when you look up. Until changed, the glasses keep their current setting. Glanceboard's Show on head tilt chooses what appears after waking.",
|
||||
});
|
||||
|
||||
export function normalizeHeadUpAngle(value: string | null | undefined): string {
|
||||
if (value == null || value.trim() === "" || !Number.isFinite(Number(value))) return "30";
|
||||
return String(Math.max(0, Math.min(60, Math.round(Number(value)))));
|
||||
}
|
||||
|
||||
export const headUpAngleSetting = new ConfigSettingEnum({
|
||||
id: "head-up-angle", label: "Head-up angle", storageKey: "display.headUpAngle", defaultValue: "30",
|
||||
values: Array.from({ length: 61 }, (_, angle) => String(angle)),
|
||||
normalize: normalizeHeadUpAngle,
|
||||
formatValue: angle => `${angle}°`,
|
||||
description: "Look-up trigger angle, 0–60 degrees. Until changed, the glasses keep their current angle. Requires validation on your Faceclaw firmware.",
|
||||
});
|
||||
|
||||
/** -1 means leave that firmware field unchanged; no writes on an untouched installation. */
|
||||
export function getHeadUpPreferences(): { enabled: number; angle: number } {
|
||||
const enabled = getStringSetting("display.headUpWake", "");
|
||||
const angle = getStringSetting("display.headUpAngle", "");
|
||||
return { enabled: enabled === "true" ? 1 : enabled === "false" ? 0 : -1,
|
||||
angle: angle === "" ? -1 : Number(normalizeHeadUpAngle(angle)) };
|
||||
}
|
||||
|
||||
const AUTO_BRIGHTNESS_LEVELS = ["2", "5", "10", "20", "25", "30", "40", "50", "60", "70", "80", "90", "100"] as const;
|
||||
export const autoBrightnessMinSetting = new ConfigSettingEnum({
|
||||
id: "autoBrightnessMin", label: "Auto minimum", storageKey: "display.autoBrightnessMin",
|
||||
|
||||
@@ -49,6 +49,8 @@ import {
|
||||
veniceWebSearchSetting,
|
||||
batteryDisplayModeSetting,
|
||||
brightnessSetting,
|
||||
headUpWakeSetting,
|
||||
headUpAngleSetting,
|
||||
autoBrightnessMinSetting,
|
||||
autoBrightnessMaxSetting,
|
||||
autoBrightnessCurveSetting,
|
||||
@@ -118,6 +120,7 @@ function settingsSections(): SettingsSection[] {
|
||||
// the dashboard controller when changed and on each connect.
|
||||
enumSettingMenuItem(brightnessSetting),
|
||||
autoBrightnessMenuItem(),
|
||||
...(!global.isIOS ? [toggleSettingMenuItem(headUpWakeSetting), enumSettingMenuItem(headUpAngleSetting)] : []),
|
||||
enumSettingMenuItem(screenTimeoutSetting, {
|
||||
onChange: () => {
|
||||
shell.noteUserActivity();
|
||||
|
||||
@@ -2,7 +2,7 @@ import { getDefaultSmallFont } from "../graphics/ui-fonts";
|
||||
import { GrayImage } from "../graphics/image";
|
||||
import { truncateText } from "../graphics/textwrap";
|
||||
import { ALL_NOTIFICATIONS, readActiveNotifications } from "../native/notification-icons";
|
||||
import { newNotificationAppsEnabledByDefault, setNewNotificationAppsEnabledByDefault, setAllNotificationSourcesEnabled, readNotificationSources, setNotificationSourceEnabled, shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
||||
import { readNotificationSources, setNotificationSourceEnabled, shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
||||
import { type InputEvent } from "./gestures";
|
||||
import { type Layer, type LayerContext, type PaintBelow } from "./layers";
|
||||
import { drawToggleMenuItem, MenuLayer, type MenuItem } from "./menu";
|
||||
@@ -11,26 +11,14 @@ import { drawToggleMenuItem, MenuLayer, type MenuItem } from "./menu";
|
||||
export class NotificationFilterLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
private menuWidth = 0;
|
||||
/** Stable row keys, including controls, parallel to the menu's items. */
|
||||
/** The package behind each current row, parallel to the menu's items. */
|
||||
private packages: string[] = [];
|
||||
|
||||
private currentMenu(ctx: LayerContext): MenuLayer {
|
||||
readActiveNotifications(ALL_NOTIFICATIONS);
|
||||
const sources = readNotificationSources().sort((a, b) =>
|
||||
a.appName.localeCompare(b.appName) || a.packageName.localeCompare(b.packageName));
|
||||
const items: MenuItem[] = [{
|
||||
label: "New apps enabled by default",
|
||||
onSelect: () => setNewNotificationAppsEnabledByDefault(!newNotificationAppsEnabledByDefault()),
|
||||
render: ({ image, x, y, width, selected }) => {
|
||||
const font = getDefaultSmallFont();
|
||||
drawToggleMenuItem(image, font, x, y, width,
|
||||
truncateText(font, "New apps enabled by default", width - 48), newNotificationAppsEnabledByDefault(), selected);
|
||||
},
|
||||
}, {
|
||||
label: "Enable all", onSelect: () => setAllNotificationSourcesEnabled(true),
|
||||
}, {
|
||||
label: "Disable all", onSelect: () => setAllNotificationSourcesEnabled(false),
|
||||
}, ...sources.map<MenuItem>((source) => ({
|
||||
const items: MenuItem[] = sources.map((source) => ({
|
||||
label: source.appName,
|
||||
onSelect: () => setNotificationSourceEnabled(source, !shouldShowNotificationOnGlasses(source.packageName)),
|
||||
render: ({ image, x, y, width, selected }) => {
|
||||
@@ -38,11 +26,11 @@ export class NotificationFilterLayer implements Layer {
|
||||
drawToggleMenuItem(image, font, x, y, width, truncateText(font, source.appName, width - 48),
|
||||
shouldShowNotificationOnGlasses(source.packageName), selected);
|
||||
},
|
||||
}))];
|
||||
if (!sources.length) items.push({ label: "No notification sources discovered yet.", disabled: true, onSelect: () => {} });
|
||||
}));
|
||||
if (!items.length) items.push({ label: "No notification sources discovered yet.", disabled: true, onSelect: () => {} });
|
||||
const selectedPackage = this.menu?.selectedIndex != null ? this.packages[this.menu.selectedIndex] : undefined;
|
||||
this.packages = ["default", "enable-all", "disable-all", ...sources.map((source) => `source:${source.packageName}`)];
|
||||
const index = selectedPackage === undefined ? 0 : this.packages.indexOf(selectedPackage);
|
||||
const index = sources.findIndex((source) => source.packageName === selectedPackage);
|
||||
this.packages = sources.map((source) => source.packageName);
|
||||
|
||||
const width = ctx.stack.getBaseSize().width;
|
||||
if (!this.menu || width !== this.menuWidth) {
|
||||
@@ -50,7 +38,7 @@ export class NotificationFilterLayer implements Layer {
|
||||
this.menu = new MenuLayer("Notification filter", items, {
|
||||
x: 8, y: 8, width: width - 16,
|
||||
opaque: true, showBorder: false,
|
||||
footer: "On = show notifications on glasses",
|
||||
footer: "On = show popups on glasses",
|
||||
}).selectItem(Math.max(0, index));
|
||||
} else {
|
||||
this.menu.setItems(items, index >= 0 ? index : undefined);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ALL_NOTIFICATIONS,
|
||||
dismissNotification,
|
||||
invokeNotificationAction,
|
||||
readVisibleNotifications,
|
||||
readActiveNotifications,
|
||||
readNotificationCustomView,
|
||||
readNotificationIconByKey,
|
||||
readNotificationLargeIcon,
|
||||
@@ -141,7 +141,7 @@ export class NotificationsListLayer implements Layer {
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const cardWidth = width - 2 * CARD_X;
|
||||
const cardTextWidth = cardWidth - CARD_TEXT_X - 14;
|
||||
const notifications = readVisibleNotifications(MAX_NOTIFICATIONS);
|
||||
const notifications = readActiveNotifications(MAX_NOTIFICATIONS);
|
||||
const selectedIndex = this.resolveSelectedIndex(notifications);
|
||||
const layouts = notifications.map((notification, index) =>
|
||||
buildNotificationCardLayout(font, notification, index === selectedIndex, cardTextWidth),
|
||||
@@ -185,7 +185,7 @@ export class NotificationsListLayer implements Layer {
|
||||
}
|
||||
|
||||
handleInput(event: InputEvent, ctx: LayerContext): void {
|
||||
const notifications = readVisibleNotifications(MAX_NOTIFICATIONS);
|
||||
const notifications = readActiveNotifications(MAX_NOTIFICATIONS);
|
||||
const selectedIndex = this.resolveSelectedIndex(notifications);
|
||||
if (event.type === "double-click") {
|
||||
// At the app's root this is intercepted by the yield wrapper; reached
|
||||
@@ -252,7 +252,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const notification = readVisibleNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
|
||||
if (!notification) {
|
||||
return this.closeUnavailableNotification(ctx, paintBelow);
|
||||
@@ -273,7 +273,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
else await menu.handleInput(event);
|
||||
return;
|
||||
}
|
||||
const notification = readVisibleNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
if (!notification) {
|
||||
this.closeUnavailableNotification(ctx);
|
||||
return;
|
||||
@@ -297,7 +297,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
this.close(ctx);
|
||||
} else if (item.kind === "action") {
|
||||
invokeNotificationAction(this.notificationKey, item.action.index);
|
||||
if (!readVisibleNotifications(ALL_NOTIFICATIONS).some((active) => active.key === this.notificationKey)) {
|
||||
if (!readActiveNotifications(ALL_NOTIFICATIONS).some((active) => active.key === this.notificationKey)) {
|
||||
this.closeUnavailableNotification(ctx);
|
||||
}
|
||||
} else if (item.kind === "dismiss") {
|
||||
@@ -310,7 +310,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
menu: new Menu<ConfirmationItem>({
|
||||
items: [
|
||||
{ label: "Cancel", run: (runCtx) => this.close(runCtx) },
|
||||
{ label: "Hide on glasses", run: (runCtx) => {
|
||||
{ label: "Turn off popups", run: (runCtx) => {
|
||||
setNotificationSourceEnabled(notification, false);
|
||||
this.close(runCtx);
|
||||
} },
|
||||
@@ -341,7 +341,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
};
|
||||
menu.paint(image, menuBox, ctx.stack.isFocused());
|
||||
const top = menuBox.y + menuBox.height + CONFIRM_PROMPT_GAP;
|
||||
const prompt = `Hide notifications on glasses from ${source.appName || source.packageName}? You can turn them back on in the Notifications app's Notification filter.`;
|
||||
const prompt = `Turn off notification popups from ${source.appName || source.packageName}? You can turn them back on in the Notifications app's Notification filter.`;
|
||||
const lines = wrapText(font, prompt, width - 2 * CONFIRM_X);
|
||||
const maxLines = Math.max(1, Math.floor((height - top - 12) / lineStep(font)));
|
||||
for (let index = 0; index < Math.min(lines.length, maxLines); index++) {
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# Dismiss all notifications
|
||||
|
||||
The Notifications app menu offers Dismiss all notifications, disabled when the
|
||||
list is empty. This explicit action dismisses notifications on the phone too;
|
||||
popup filtering and source/default preferences remain independent.
|
||||
|
||||
Android uses NotificationListenerService.cancelAllNotifications, so dismissal
|
||||
is not limited to the 50 items displayed by the list and Android controls which
|
||||
notifications are removable. The normal removal callbacks update the list and
|
||||
popups. Missing listener access returns false without changing preferences.
|
||||
iOS uses the existing ANCS dismissal operation on a snapshot of all known keys;
|
||||
notifications without a negative action may remain.
|
||||
|
||||
Software tests cover menu action/disabled state, more than 50 notifications,
|
||||
native bridge dispatch, disconnected access and ANCS bulk dismissal.
|
||||
On a device, verify the permission-granted/revoked cases, protected or ongoing
|
||||
notifications, notification groups, and consistency with the phone's tray.
|
||||
Hardware validation remains pending.
|
||||
|
||||
Reference: https://developer.android.com/reference/android/service/notification/NotificationListenerService#cancelAllNotifications()
|
||||
@@ -0,0 +1,53 @@
|
||||
# Head-up wake: software and hardware validation
|
||||
|
||||
The Android Display settings now contain “Head-up wake” and “Head-up angle”.
|
||||
Glanceboard's “Show on head tilt” still only chooses which UI appears on wake.
|
||||
|
||||
Protocol reference: [OpenG2 Companion G2Protocol.swift](https://github.com/mmirman/open-g2-companion/blob/1400d1006ba045379a3ff34d0832add6fa10ced4/modules/ffs-ble/ios/G2Protocol.swift),
|
||||
`setHeadUpSwitch` / `setHeadUpAngle`; dispatch to both lenses in
|
||||
[`G2Central.swift`](https://github.com/mmirman/open-g2-companion/blob/1400d1006ba045379a3ff34d0832add6fa10ced4/modules/ffs-ble/ios/G2Central.swift).
|
||||
|
||||
Wire format uses Faceclaw's UI-settings sid 0x09, request flag, command 1, transaction
|
||||
magic, device-receive-info field 3 / head-up field 4. Switch (field 1) and
|
||||
angle (field 2) are sent in separate messages, including explicit zero values.
|
||||
Angles are clamped to the reference's 0–60 degree range. No firmware patch,
|
||||
firmware download or flash is needed by this implementation.
|
||||
|
||||
Untouched installations send neither field. The UI describes this inherited
|
||||
state; its displayed ON/30 degree fallback is not a read-back of device state.
|
||||
Changing just one control preserves the other device field. Explicit choices
|
||||
are persisted in the existing settings store and resent on every connection.
|
||||
The native session also retains them through transport reconnects and retries
|
||||
after setting ACK timeouts. ACK reception confirms transport, not physical wake.
|
||||
|
||||
Software checks:
|
||||
|
||||
- `tests/head-up-wake.test.cjs`: persistence, untouched fields, angle bounds,
|
||||
independence from Glanceboard, deduplication, reconnect and error recovery.
|
||||
- `HeadUpProtocolTest`: byte-for-byte settings messages, including OFF and 0°.
|
||||
- `GlassesSessionCoreTest`: both lenses, separate writes, pre-existing device
|
||||
settings preserved, angle clamp and automatic transport reconnection.
|
||||
|
||||
Hardware validation: **pending**. Implementation was requested without device
|
||||
access; protocol compatibility and physical effect on the target Faceclaw CFW
|
||||
are not established by these software tests. The reference targets stock
|
||||
2.2.6.10, while this repository normally uses newer Faceclaw firmware.
|
||||
|
||||
Source inspection of [Faceclaw's gesture forwarding](https://github.com/jimrandomh/g2flash/blob/845f665e0dfdcfd06b7d3a294388de6f17a5bd59/patches/gesture_fwd.c)
|
||||
confirms that head-up/down forwarding while a page owns the screen checks the
|
||||
stock `head_up_switch`. This supports using the existing setting rather than a
|
||||
firmware patch, but does not establish the physical angle or wake behavior.
|
||||
|
||||
On the target glasses, record both lens firmware versions and test:
|
||||
|
||||
1. Leave preferences untouched and verify prior wake behavior remains unchanged.
|
||||
2. Disable Head-up wake; sleep the display, raise the head repeatedly, and confirm
|
||||
no wake. Check taps still wake normally.
|
||||
3. Enable it and compare 0°, 30° and 60° trigger angles. Confirm other wake
|
||||
gestures remain usable, including at the extreme values.
|
||||
4. Reconnect Bluetooth, then restart the phone app; repeat ON/OFF and angle checks.
|
||||
5. Toggle Glanceboard and “Show on head tilt” independently; disabled wake should
|
||||
stay disabled, enabled wake should show the selected UI.
|
||||
6. Check both lenses remain synchronized, including reconnecting only one arm.
|
||||
|
||||
Do not change firmware to run these checks without explicit permission.
|
||||
@@ -1,35 +0,0 @@
|
||||
# Notification filter validation
|
||||
|
||||
Software: `npm test` and `bash lint.sh app/native/notification-sources.ts app/ui/notification-filter.ts`.
|
||||
The notification suite covers legacy preferences, reloads of the settings store,
|
||||
discovery, default changes without overwriting exceptions, both bulk actions,
|
||||
empty lists, stable menu selection and popup suppression before wake.
|
||||
|
||||
Hardware validation (pending; no glasses tested):
|
||||
|
||||
1. On an existing installation, check that enabled and muted applications retain
|
||||
their behavior before touching the new default.
|
||||
2. Turn “New apps enabled by default” off; restart the app. Send a notification
|
||||
from a previously unknown package: it must appear in the filter and on the
|
||||
phone, without waking the glasses or showing a glasses popup.
|
||||
3. Enable that package individually; send another notification and check its popup.
|
||||
4. Change the default in both directions; verify individual exceptions survive.
|
||||
5. Use “Disable all”, then discover another package: it follows the default.
|
||||
Repeat with “Enable all” while the default is off.
|
||||
6. Restart and repeat notifications from enabled and disabled sources. Check that
|
||||
bulk actions and filtering never dismiss notifications on the phone.
|
||||
|
||||
The same source preferences now filter glasses popups, the Notifications list,
|
||||
and the notification tray/status icons. Filtering happens before display limits;
|
||||
source discovery and the phone notification lifecycle remain unfiltered.
|
||||
Cached tray icons reapply the current preferences on each read, including stale
|
||||
reads, so a changed toggle cannot leave a muted icon visible.
|
||||
|
||||
Additional software coverage: Android list limits and warm/stale icon caches,
|
||||
Disable all / re-enable without a new post, and iOS list/tray filtering.
|
||||
|
||||
Additional hardware validation (pending): with mixed enabled/disabled sources,
|
||||
check the list and status bar together. Toggle a source while its notification
|
||||
is already active, then Disable all and Enable all. Verify immediate removal /
|
||||
restoration without a new notification, including after restart, and verify
|
||||
notifications remain available in the phone notification shade.
|
||||
@@ -497,6 +497,23 @@ class BleProtocol {
|
||||
)
|
||||
}
|
||||
|
||||
/** Stock HeadUpSetting: switch and angle are separate oneof writes (field 4 of device info). */
|
||||
@JvmStatic
|
||||
fun buildSetHeadUpWake(magic: Int, enabled: Boolean): ByteArray = concat(
|
||||
CollectionUtils.listOf(
|
||||
encodeVarintField(1, 1), encodeVarintField(2, magic),
|
||||
encodeMessageField(3, encodeMessageField(4, encodeVarintField(1, if (enabled) 1 else 0))),
|
||||
)
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
fun buildSetHeadUpAngle(magic: Int, angle: Int): ByteArray = concat(
|
||||
CollectionUtils.listOf(
|
||||
encodeVarintField(1, 1), encodeVarintField(2, magic),
|
||||
encodeMessageField(3, encodeMessageField(4, encodeVarintField(2, angle.coerceIn(0, 60)))),
|
||||
)
|
||||
)
|
||||
|
||||
/** Enable the firmware's wear detector (DeviceReceiveInfoFromAPP field 5). */
|
||||
@JvmStatic
|
||||
fun buildSetWearDetection(magic: Int, enabled: Boolean): ByteArray {
|
||||
|
||||
+11
@@ -188,6 +188,17 @@ class MessageBuilder {
|
||||
)
|
||||
}
|
||||
|
||||
fun headUpControl(leftArm: Boolean, enabled: Boolean?, angle: Int): OutboundMessage {
|
||||
val magic = magicPool.allocate()
|
||||
return OutboundMessage(
|
||||
"head-up-control", if (enabled == null) "head-up angle=$angle" else "head-up wake=$enabled",
|
||||
BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST, magic,
|
||||
if (enabled == null) BleProtocol.buildSetHeadUpAngle(magic, angle)
|
||||
else BleProtocol.buildSetHeadUpWake(magic, enabled),
|
||||
ACK_TIMEOUT_MS, -1, leftArm,
|
||||
)
|
||||
}
|
||||
|
||||
fun createLayout(): OutboundMessage {
|
||||
var magic: Int = magicPool.allocate()
|
||||
return OutboundMessage(
|
||||
|
||||
+12
@@ -304,6 +304,8 @@ class GlassesSessionCore(
|
||||
internal var brightnessSentLevel = -1
|
||||
internal var brightnessAlsStartedAt = -2000L
|
||||
internal var brightnessDemoPolling = false
|
||||
internal var headUpPreferences: Pair<Int, Int>? = null
|
||||
internal var headUpSent: Pair<Int, Int>? = null
|
||||
internal var cfwCleanupDelivered = false
|
||||
internal var lastCfwCleanupAckMagic = 0
|
||||
|
||||
@@ -920,6 +922,15 @@ class GlassesSessionCore(
|
||||
interruptibleSleep.interrupt()
|
||||
}
|
||||
|
||||
/** Explicit preferences only; -1 leaves the corresponding firmware field alone. */
|
||||
fun configureHeadUpWake(enabled: Int, angle: Int) {
|
||||
require(enabled in -1..1)
|
||||
monitor.withLock {
|
||||
headUpPreferences = Pair(enabled, if (angle < 0) -1 else angle.coerceIn(0, 60))
|
||||
}
|
||||
interruptibleSleep.interrupt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the stock wear detector, then ask CFW to emit its current cached
|
||||
* state. The queue order matters: the query must run after the setting is
|
||||
@@ -2232,6 +2243,7 @@ class GlassesSessionCore(
|
||||
shutdownRequested = false
|
||||
fixedLayoutCreated = false
|
||||
clearAllMessagesLocked("session ready")
|
||||
headUpSent = null
|
||||
displayedFingerprint = ""
|
||||
lastAckAtMs = now()
|
||||
lastIncomingAtMs = lastAckAtMs
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
/** Both arms receive separate stock settings messages; no CFW changes required. */
|
||||
internal fun GlassesSessionCore.enqueueHeadUpPreferencesLocked() {
|
||||
val desired = headUpPreferences ?: return
|
||||
if (!sessionReady || shutdownRequested || chargingMode || headUpSent == desired
|
||||
|| hasPendingOrInflightKindLocked("head-up-control")) return
|
||||
for (leftArm in listOf(true, false)) {
|
||||
// Set the angle before enabling wake. Omitted fields preserve device preferences.
|
||||
if (desired.second >= 0) {
|
||||
val message = messageBuilder.headUpControl(leftArm, null, desired.second)
|
||||
message.onTimeout = MessageCallback { headUpSent = null; logLine("head-up angle ack timeout") }
|
||||
pendingMessages.addLast(message)
|
||||
}
|
||||
if (desired.first >= 0) {
|
||||
val message = messageBuilder.headUpControl(leftArm, desired.first == 1, -1)
|
||||
message.onTimeout = MessageCallback { headUpSent = null; logLine("head-up wake ack timeout") }
|
||||
pendingMessages.addLast(message)
|
||||
}
|
||||
}
|
||||
headUpSent = desired
|
||||
}
|
||||
+1
@@ -74,6 +74,7 @@ internal fun GlassesSessionCore.driveSession(): Long {
|
||||
clearPendingMessagesLocked("after CFW cleanup")
|
||||
return 250
|
||||
}
|
||||
enqueueHeadUpPreferencesLocked()
|
||||
if (sessionReady
|
||||
&& now - lastFaceclawFramebufferLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS
|
||||
&& !hasPendingOrInflightKindLocked("framebuffer-lease-control")) {
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
test('Notifications menu dismisses all, including beyond the visible list, and leaves filters untouched', () => {
|
||||
let options, active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) }));
|
||||
let dismissals = 0, renders = 0, pops = 0;
|
||||
const load = loader({}, {
|
||||
'../../ui/notifications': { NotificationsListLayer: class {} },
|
||||
'../../ui/notification-filter': { NotificationFilterLayer: class {} },
|
||||
'../../native/notification-icons': {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications(max) { assert.equal(max, 0x7fffffff); return active; },
|
||||
dismissAllNotifications() { dismissals++; active = []; return true; },
|
||||
onAndroidNotificationsChanged: () => () => {},
|
||||
},
|
||||
'../../ui/shell/in-process-window': {
|
||||
YieldAtRootLayer: class {},
|
||||
createInProcessWindow(value) { options = value; return { requestRender() { renders++; } }; },
|
||||
},
|
||||
});
|
||||
load('app/apps/notifications/notifications-app.ts').createNotificationsAppWindow({});
|
||||
const items = options.menuItems();
|
||||
assert.equal(items[0].label, 'Notification filter');
|
||||
const action = items.find(x => x.label === 'Dismiss all notifications');
|
||||
assert.equal(action.disabled(), false);
|
||||
assert.equal(dismissals, 0);
|
||||
action.onSelect({ stack: { pop() { pops++; } } });
|
||||
assert.equal(dismissals, 1);
|
||||
assert.equal(pops, 1);
|
||||
assert.equal(renders, 1);
|
||||
assert.equal(action.disabled(), true);
|
||||
});
|
||||
|
||||
test('Android bulk action uses the native listener and propagates unavailable access', () => {
|
||||
let calls = 0, allowed = false;
|
||||
const load = loader({ global: { isAndroid: true }, com: { faceclaw: { app: {
|
||||
FaceclawMediaNotificationListenerService: { dismissAllNotifications() { calls++; return allowed; } },
|
||||
} } } }, {
|
||||
'../graphics/image': {}, './frame-timings': {}, '../util/array-util': {},
|
||||
'./notification-sources': {}, './image-files': { PHOTO_TONE: { gamma: 1 } }, './notification-types': { NOTIFICATION_ICON_SIZE: 24 },
|
||||
});
|
||||
const api = load('app/native/notification-icons.ts');
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
allowed = true;
|
||||
assert.equal(api.dismissAllNotifications(), true);
|
||||
assert.equal(calls, 2);
|
||||
});
|
||||
|
||||
test('iOS snapshots all ANCS keys and continues when a notification cannot be dismissed', () => {
|
||||
const load = loader({}, {
|
||||
'../graphics/pebble-icons': {}, '../g2/ancs-client': {}, './notification-app-icons': {}, './notification-sources': {},
|
||||
});
|
||||
const api = load('app/native/notification-icons.ios.ts');
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
const active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) })), attempted = [];
|
||||
api.bindIosNotifications({
|
||||
read(max) { assert.equal(max, api.ALL_NOTIFICATIONS); return active; },
|
||||
dismiss(key) {
|
||||
attempted.push(key);
|
||||
if (key === '1') return false;
|
||||
active.splice(active.findIndex(x => x.key === key), 1);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
assert.equal(attempted.length, 80);
|
||||
assert.deepEqual(active, [{ key: '1' }]);
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
const source = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||
function evaluate(code, globals) {
|
||||
const context = { exports: {}, ...globals };
|
||||
vm.runInNewContext(ts.transpileModule(code, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
return context.exports;
|
||||
}
|
||||
function settings(values = new Map()) {
|
||||
const file = ts.createSourceFile('settings.ts', source('app/ui/dashboard-settings.ts'), ts.ScriptTarget.Latest, true);
|
||||
const names = new Set(['ConfigSetting', 'ConfigSettingBoolean', 'ConfigSettingEnum', 'HeadUpWakeSetting',
|
||||
'headUpWakeSetting', 'normalizeHeadUpAngle', 'headUpAngleSetting', 'getHeadUpPreferences']);
|
||||
const code = file.statements.filter(node => names.has(node.name?.text) ||
|
||||
(ts.isVariableStatement(node) && node.declarationList.declarations.some(d => names.has(d.name.getText(file)))))
|
||||
.map(node => node.getText(file)).join('\n');
|
||||
return evaluate(code, {
|
||||
fixedChoiceSettings: new Map(),
|
||||
getStringSetting: (key, fallback) => values.get(key) ?? fallback,
|
||||
setStringSetting: (key, value) => values.set(key, value),
|
||||
});
|
||||
}
|
||||
|
||||
test('head-up preferences preserve untouched device fields and persist each explicit choice separately', () => {
|
||||
const values = new Map();
|
||||
let prefs = settings(values);
|
||||
assert.equal(prefs.getHeadUpPreferences().enabled, -1);
|
||||
assert.equal(prefs.getHeadUpPreferences().angle, -1);
|
||||
prefs.headUpWakeSetting.set(false);
|
||||
prefs = settings(values);
|
||||
assert.equal(prefs.headUpWakeSetting.get(), false);
|
||||
assert.equal(prefs.getHeadUpPreferences().enabled, 0);
|
||||
assert.equal(prefs.getHeadUpPreferences().angle, -1);
|
||||
prefs.headUpAngleSetting.set('75');
|
||||
prefs = settings(values);
|
||||
assert.equal(prefs.headUpAngleSetting.get(), '60');
|
||||
assert.equal(prefs.getHeadUpPreferences().enabled, 0);
|
||||
assert.equal(prefs.getHeadUpPreferences().angle, 60);
|
||||
for (const [input, expected] of [['-5', '0'], ['20.8', '21'], ['NaN', '30'], ['', '30']]) {
|
||||
assert.equal(prefs.headUpAngleSetting.set(input), expected);
|
||||
}
|
||||
assert.equal(values.has('glanceboard.showOnHeadTilt'), false);
|
||||
});
|
||||
|
||||
test('controller skips unset preferences, deduplicates changes and forces reconnect synchronization', async () => {
|
||||
const file = ts.createSourceFile('controller.ts', source('app/g2/dashboard-controller.ts'), ts.ScriptTarget.Latest, true);
|
||||
const controller = file.statements.find(node => ts.isClassDeclaration(node) && node.name.text === 'DashboardController');
|
||||
const method = controller.members.find(node => node.name?.getText(file) === 'pushHeadUpPreferences').getText(file);
|
||||
let prefs = { enabled: -1, angle: -1 };
|
||||
const { Harness } = evaluate(`export class Harness { ${method} }`, {
|
||||
global: { isAndroid: true }, getHeadUpPreferences: () => prefs,
|
||||
});
|
||||
const h = new Harness(), calls = [];
|
||||
h.communicator = { configureHeadUpWake: async (...args) => calls.push(args) };
|
||||
h.pushHeadUpPreferences(); assert.equal(calls.length, 0);
|
||||
prefs = { enabled: 0, angle: 25 };
|
||||
h.pushHeadUpPreferences(); h.pushHeadUpPreferences();
|
||||
assert.deepEqual(calls, [[0, 25]]);
|
||||
h.pushHeadUpPreferences(true); assert.equal(calls.length, 2);
|
||||
prefs = { enabled: 1, angle: 40 }; h.pushHeadUpPreferences();
|
||||
assert.deepEqual(calls.at(-1), [1, 40]);
|
||||
let failures = 0;
|
||||
h.communicator.configureHeadUpWake = async () => { throw new Error('offline'); };
|
||||
h.appendLog = () => failures++;
|
||||
h.formatError = error => error.message;
|
||||
h.pushHeadUpPreferences(true);
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
assert.equal(h.lastPushedHeadUp, null); assert.equal(failures, 1);
|
||||
const connect = controller.members.find(node => node.name?.getText(file) === 'connect').getText(file);
|
||||
assert.match(connect, /pushHeadUpPreferences\(true\)/);
|
||||
});
|
||||
@@ -9,7 +9,7 @@ const generator = require('../scripts/generate-pebble-icons.cjs');
|
||||
function setup(notifications) {
|
||||
const load = loader({}, {
|
||||
'../g2/ancs-client': { AncsClient: class {}, ANCS_CONNECT_MESSAGE: '' },
|
||||
'./notification-sources': { rememberNotificationSources() {}, shouldShowNotificationOnGlasses: packageName => packageName !== "muted" },
|
||||
'./notification-sources': { rememberNotificationSources() {} },
|
||||
});
|
||||
const icons = load('app/native/notification-icons.ios.ts');
|
||||
icons.bindIosNotifications({ read: () => notifications });
|
||||
@@ -106,11 +106,3 @@ test('the icon generator inverts Pebble art: black ink lights up, white fills hi
|
||||
const decoded = loader({}, { './pebble-icons-data': loader({}, {})(dataFile) })('app/graphics/pebble-icons.ts').pebbleIcon('probe');
|
||||
assert.deepEqual([...decoded.pixels], [...pixels]);
|
||||
});
|
||||
|
||||
test('muted sources are hidden before list and icon limits without removing phone notifications', () => {
|
||||
const notifications = [notification('hidden', 'muted', '0'), notification('shown', 'allowed', '0')];
|
||||
const { icons } = setup(notifications);
|
||||
assert.deepEqual([...icons.readVisibleNotifications(1)].map(n => n.key), ['shown']);
|
||||
assert.deepEqual([...icons.readActiveNotificationIcons(1, false).keys], ['shown']);
|
||||
assert.equal(icons.readActiveNotifications(10).length, 2);
|
||||
});
|
||||
@@ -316,6 +316,33 @@ private class Session {
|
||||
}
|
||||
|
||||
class GlassesSessionCoreTest {
|
||||
@Test fun headUpWritesOnlyExplicitFieldsToBothArmsAndResendsAfterReconnect() {
|
||||
val s = Session()
|
||||
try {
|
||||
s.startAndAwaitLayout()
|
||||
fun writes() = s.link.writes.filter { it.kind == "head-up-control" }
|
||||
assertEquals(0, writes().size, "untouched firmware preferences must not be written")
|
||||
s.core.configureHeadUpWake(0, 30)
|
||||
assertTrue(waitUntil(5_000) { writes().size == 4 })
|
||||
for (arm in listOf(LEFT, RIGHT)) {
|
||||
val commands = writes().filter { it.address == arm }
|
||||
assertContentEquals(BleProtocol.buildSetHeadUpAngle(commands[0].magic, 30), commands[0].pb)
|
||||
assertContentEquals(BleProtocol.buildSetHeadUpWake(commands[1].magic, false), commands[1].pb)
|
||||
}
|
||||
s.core.handleTransportFailure("head-up reconnect test")
|
||||
assertTrue(waitUntil(5_000) { !s.layoutCreated() })
|
||||
s.platform.offsetMs += 10_000
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
assertTrue(waitUntil(5_000) { s.layoutCreated() && writes().size == 8 }, s.host.logs().takeLast(10).toString())
|
||||
s.core.configureHeadUpWake(-1, 100)
|
||||
assertTrue(waitUntil(5_000) { writes().size == 10 })
|
||||
assertTrue(writes().takeLast(2).all { it.label == "head-up angle=60" })
|
||||
s.core.configureHeadUpWake(1, -1)
|
||||
assertTrue(waitUntil(5_000) { writes().size == 12 })
|
||||
assertTrue(writes().takeLast(2).all { it.label == "head-up wake=true" })
|
||||
} finally { s.core.close() }
|
||||
}
|
||||
|
||||
@Test fun brightnessConfigPrecedesFirstFrameAndSleepWakeFollowsComposites() {
|
||||
val s = Session()
|
||||
s.core.configureBrightness(false, 70, 2, 100, "0:0,1000:100", 280)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
|
||||
class HeadUpProtocolTest {
|
||||
private fun bytes(hex: String) = hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
|
||||
@Test fun separateSwitchAndAngleMessagesMatchReferenceWireFormat() {
|
||||
// G2SettingPackage{1=1, 2=magic, 3={4=HeadUpSetting{1=switch | 2=angle}}}.
|
||||
assertContentEquals(bytes("080110071a0422020800"), BleProtocol.buildSetHeadUpWake(7, false))
|
||||
assertContentEquals(bytes("080110071a0422020801"), BleProtocol.buildSetHeadUpWake(7, true))
|
||||
assertContentEquals(bytes("080110071a042202101e"), BleProtocol.buildSetHeadUpAngle(7, 30))
|
||||
assertContentEquals(bytes("080110071a0422021000"), BleProtocol.buildSetHeadUpAngle(7, -10))
|
||||
assertContentEquals(bytes("080110071a042202103c"), BleProtocol.buildSetHeadUpAngle(7, 100))
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,6 @@ function ui(fontSize = 12) {
|
||||
const native = {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => { prefs.rememberNotificationSources(active); return active; },
|
||||
readVisibleNotifications: () => { prefs.rememberNotificationSources(active); return active.filter(n => prefs.shouldShowNotificationOnGlasses(n.packageName)); },
|
||||
dismissNotification: () => { dismissals++; active = []; return true; },
|
||||
readNotificationIconByKey: () => ({ icon: null, stale: false }),
|
||||
};
|
||||
@@ -166,7 +165,6 @@ test('cancel and back dismiss the popup without changing source preferences', as
|
||||
test('filter toggles persist after notifications disappear and discovers new sources while open', async () => {
|
||||
const app = ui();
|
||||
app.paint(app.filter);
|
||||
for (let i = 0; i < 3; i++) await app.input(app.filter, 'scroll-down');
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
app.active([{ packageName: 'com.alpha', appName: 'Alpha' }]);
|
||||
@@ -179,68 +177,6 @@ test('filter toggles persist after notifications disappear and discovers new sou
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses('com.alpha'), true);
|
||||
});
|
||||
|
||||
test('default persists without overwriting explicit choices, including legacy saved sources', () => {
|
||||
const settings = new Map([['notifications.sources', JSON.stringify([
|
||||
{ ...mail, showOnGlasses: true },
|
||||
{ packageName: 'muted', appName: 'Muted', showOnGlasses: false },
|
||||
])]]);
|
||||
let prefs = store(settings);
|
||||
prefs.rememberNotificationSources([{ packageName: 'discovered', appName: 'Discovered' }]);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(false);
|
||||
prefs = store(settings);
|
||||
assert.equal(prefs.newNotificationAppsEnabledByDefault(), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses(mail.packageName), true);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('muted'), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('discovered'), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), false);
|
||||
prefs.rememberNotificationSources([{ packageName: 'future', appName: 'Future' }]);
|
||||
prefs.setNotificationSourceEnabled({ packageName: 'future', appName: 'Future' }, true);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(true);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(false);
|
||||
assert.equal(store(settings).shouldShowNotificationOnGlasses('future'), true);
|
||||
});
|
||||
|
||||
test('bulk choices persist for known sources without changing the default for future sources', () => {
|
||||
const settings = new Map();
|
||||
let prefs = store(settings);
|
||||
prefs.rememberNotificationSources([mail]);
|
||||
prefs.setAllNotificationSourcesEnabled(false);
|
||||
prefs = store(settings);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), true);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(false);
|
||||
prefs.setAllNotificationSourcesEnabled(true);
|
||||
prefs = store(settings);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses(mail.packageName), true);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), false);
|
||||
prefs.rememberNotificationSources([{ packageName: 'future', appName: 'Future' }]);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), false);
|
||||
prefs.setAllNotificationSourcesEnabled(false);
|
||||
assert.ok(prefs.readNotificationSources().every(source => !source.showOnGlasses));
|
||||
});
|
||||
|
||||
test('filter controls work with an empty list and keep selection as sources arrive', async () => {
|
||||
const app = ui();
|
||||
app.active([]);
|
||||
const labels = app.paint(app.filter).texts.map(({ text }) => text);
|
||||
assert.ok(labels.includes('New apps enabled by default'));
|
||||
assert.ok(labels.includes('Enable all'));
|
||||
assert.ok(labels.includes('Disable all'));
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.newNotificationAppsEnabledByDefault(), false);
|
||||
app.active([mail]);
|
||||
app.paint(app.filter);
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
await app.input(app.filter, 'scroll-down');
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), true);
|
||||
assert.equal(app.prefs.newNotificationAppsEnabledByDefault(), false);
|
||||
await app.input(app.filter, 'scroll-down');
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
assert.equal(app.dismissals(), 0);
|
||||
});
|
||||
|
||||
test('popup action wraps fully and stays visible with small and large fonts', async () => {
|
||||
for (const size of [12, 20]) {
|
||||
const app = ui(size);
|
||||
@@ -318,33 +254,3 @@ test('controller filters before waking or opening a popup, and still refreshes t
|
||||
elapse();
|
||||
assert.equal(popups, 1);
|
||||
});
|
||||
|
||||
test('Android display filters before limits and reapplies preferences to cached tray icons', () => {
|
||||
const prefs = store();
|
||||
const active = [{ ...mail, key: 'hidden' }, { packageName: 'allowed', appName: 'Allowed', key: 'shown' }];
|
||||
const file = ts.createSourceFile('icons.ts', source('app/native/notification-icons.ts'), ts.ScriptTarget.Latest, true);
|
||||
const functions = file.statements.filter(node => ts.isFunctionDeclaration(node) &&
|
||||
['readVisibleNotifications', 'cachedIconsResult'].includes(node.name?.text)).map(node => node.getText(file));
|
||||
const { readVisibleNotifications, cachedIconsResult } = evaluate(functions.join('\n') + '\nexport { cachedIconsResult };', null, {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => { prefs.rememberNotificationSources(active); return active; },
|
||||
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
|
||||
cachedKeys: ['hidden', 'shown'],
|
||||
cachedPackages: new Map(active.map(n => [n.key, n.packageName])),
|
||||
cachedIcons: [{ clone: () => 'mail-icon' }, { clone: () => 'allowed-icon' }],
|
||||
});
|
||||
prefs.setNotificationSourceEnabled(mail, false);
|
||||
assert.deepEqual(Array.from(readVisibleNotifications(1), n => n.key), ['shown']);
|
||||
for (const stale of [false, true]) {
|
||||
const result = cachedIconsResult(1, stale);
|
||||
assert.deepEqual(Array.from(result.keys), ['shown']);
|
||||
assert.deepEqual(Array.from(result.icons), ['allowed-icon']);
|
||||
assert.equal(result.stale, stale);
|
||||
}
|
||||
prefs.setAllNotificationSourcesEnabled(false);
|
||||
assert.equal(cachedIconsResult(10, false).keys.length, 0);
|
||||
assert.equal(readVisibleNotifications(50).length, 0);
|
||||
prefs.setNotificationSourceEnabled(mail, true);
|
||||
assert.deepEqual(Array.from(cachedIconsResult(1, false).keys), ['hidden']);
|
||||
assert.equal(active.length, 2);
|
||||
});
|
||||
Reference in new issue
Block a user