forked from Blendman974/faceclaw
Add option to auto-dismiss notifications after a timer
This commit is contained in:
1 parent
9ba5c1988d
commit
448a057d2d
15 files changed
+329
-30
No files matched your search
@@ -14,7 +14,12 @@ const notificationsApp: AppDefinition = {
|
|||||||
if (listenerState === "no-access" || listenerState === "stuck") {
|
if (listenerState === "no-access" || listenerState === "stuck") {
|
||||||
requestNotificationListenerAccess();
|
requestNotificationListenerAccess();
|
||||||
}
|
}
|
||||||
return ctx.launchInProcessApp(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow);
|
return ctx.launchInProcessApp(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, (options) =>
|
||||||
|
createNotificationsAppWindow(options, (section) => {
|
||||||
|
void ctx.launchApp("settings", { section }).catch((error) => {
|
||||||
|
ctx.appendLog(`settings launch failed: ${error}`);
|
||||||
|
});
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { NotificationsListLayer } from "../../ui/notifications";
|
import { NotificationsListLayer } from "../../ui/notifications";
|
||||||
import { NotificationFilterLayer } from "../../ui/notification-filter";
|
import { NOTIFICATIONS_SETTINGS_SECTION } from "../../ui/dashboard/settings-menus";
|
||||||
import { onAndroidNotificationsChanged } from "../../native/notification-icons";
|
import { onAndroidNotificationsChanged } from "../../native/notification-icons";
|
||||||
import {
|
import {
|
||||||
createInProcessWindow,
|
createInProcessWindow,
|
||||||
@@ -14,9 +14,13 @@ export const NOTIFICATIONS_SURFACE_ID = "window:notifications";
|
|||||||
/**
|
/**
|
||||||
* The Notifications app: the Android-notification list (previously a
|
* The Notifications app: the Android-notification list (previously a
|
||||||
* dashboard page) in its own in-process window; selecting a notification
|
* dashboard page) in its own in-process window; selecting a notification
|
||||||
* opens the detail view with its quick actions.
|
* opens the detail view with its quick actions. `openSettings` opens a
|
||||||
|
* Settings section (the menu's "Settings" goes to Notifications).
|
||||||
*/
|
*/
|
||||||
export function createNotificationsAppWindow(options: InProcessAppOptions): InProcessWindow {
|
export function createNotificationsAppWindow(
|
||||||
|
options: InProcessAppOptions,
|
||||||
|
openSettings: (section: string) => void,
|
||||||
|
): InProcessWindow {
|
||||||
// Newly posted notifications repaint the list while the window is open.
|
// Newly posted notifications repaint the list while the window is open.
|
||||||
let offNotificationsChanged: (() => void) | null = null;
|
let offNotificationsChanged: (() => void) | null = null;
|
||||||
const created = createInProcessWindow({
|
const created = createInProcessWindow({
|
||||||
@@ -27,10 +31,10 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr
|
|||||||
icon: "bell",
|
icon: "bell",
|
||||||
closeable: true,
|
closeable: true,
|
||||||
menuItems: () => [{
|
menuItems: () => [{
|
||||||
label: "Notification filter",
|
label: "Settings",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
ctx.stack.push(new NotificationFilterLayer());
|
openSettings(NOTIFICATIONS_SETTINGS_SECTION);
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { mediaControllerBridge } from "../native/media-controller";
|
|||||||
import { nightscoutBridge } from "../native/nightscout-bridge";
|
import { nightscoutBridge } from "../native/nightscout-bridge";
|
||||||
import { weatherBridge } from "../native/weather";
|
import { weatherBridge } from "../native/weather";
|
||||||
import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, onAndroidNotificationRemoved, readActiveNotifications } from "../native/notification-icons";
|
import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, onAndroidNotificationRemoved, readActiveNotifications } from "../native/notification-icons";
|
||||||
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
|
||||||
import { watchNotificationListenerBinding } from "../native/notification-access";
|
import { watchNotificationListenerBinding } from "../native/notification-access";
|
||||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||||
import { defaultRingName, setGlassesRingLink } from "../native/ring-status";
|
import { defaultRingName, setGlassesRingLink } from "../native/ring-status";
|
||||||
@@ -78,7 +77,7 @@ import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-a
|
|||||||
import { appViewportRect, isOnSwitcherEdge, screenHeight, screenWidth, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
|
import { appViewportRect, isOnSwitcherEdge, screenHeight, screenWidth, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
|
||||||
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
|
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
|
||||||
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
|
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
|
||||||
import { appSwitcherPositionSetting, glassesTypeSetting, 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, effectiveRingConnectionMode, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
import { appSwitcherPositionSetting, glassesTypeSetting, 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, effectiveRingConnectionMode, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, shouldPopUpNewNotification, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||||
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||||
import {
|
import {
|
||||||
getInstalledEvenHubAppById,
|
getInstalledEvenHubAppById,
|
||||||
@@ -449,7 +448,8 @@ class DashboardController {
|
|||||||
this.emit();
|
this.emit();
|
||||||
},
|
},
|
||||||
openNotificationsWindow: () =>
|
openNotificationsWindow: () =>
|
||||||
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow),
|
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID,
|
||||||
|
(options) => createNotificationsAppWindow(options, (section) => this.openSettings(section))),
|
||||||
onSwitcherBarHeightChanged: () => this.applySwitcherBarHeight(),
|
onSwitcherBarHeightChanged: () => this.applySwitcherBarHeight(),
|
||||||
onScreenStateChanged: (on) => {
|
onScreenStateChanged: (on) => {
|
||||||
// Any wake of the regular UI replaces a showing Glanceboard.
|
// Any wake of the regular UI replaces a showing Glanceboard.
|
||||||
@@ -2644,11 +2644,7 @@ class DashboardController {
|
|||||||
setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible),
|
setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible),
|
||||||
removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId),
|
removeSurface: (surfaceId) => this.removeWindowSurface(surfaceId),
|
||||||
requestShellRender: () => this.requestShellRender(),
|
requestShellRender: () => this.requestShellRender(),
|
||||||
openSettings: (section) => {
|
openSettings: (section) => this.openSettings(section),
|
||||||
void this.launchApp("settings", { section }).catch((error) => {
|
|
||||||
this.appendLog(`settings launch failed: ${this.formatError(error)}`);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
startTextSettingEdit: (settingId) => {
|
startTextSettingEdit: (settingId) => {
|
||||||
const setting = getStringSettingById(settingId);
|
const setting = getStringSettingById(settingId);
|
||||||
if (setting) {
|
if (setting) {
|
||||||
@@ -2732,6 +2728,13 @@ class DashboardController {
|
|||||||
this.requestShellRender();
|
this.requestShellRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Open or focus the Settings app, optionally on a section (by label). */
|
||||||
|
private openSettings(section?: string): void {
|
||||||
|
void this.launchApp("settings", { section }).catch((error) => {
|
||||||
|
this.appendLog(`settings launch failed: ${this.formatError(error)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch an app by id: the launcher grid, assistant tools, window-menu
|
* Launch an app by id: the launcher grid, assistant tools, window-menu
|
||||||
* Settings item, and open-apps restore all come through here. Apps with an
|
* Settings item, and open-apps restore all come through here. Apps with an
|
||||||
@@ -2948,7 +2951,7 @@ class DashboardController {
|
|||||||
// The tray shows the notification at once; its popup waits out a short
|
// The tray shows the notification at once; its popup waits out a short
|
||||||
// delay, so one withdrawn right away (see NotificationPopupDelay) never shows.
|
// delay, so one withdrawn right away (see NotificationPopupDelay) never shows.
|
||||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
||||||
if (notification && shouldShowNotificationOnGlasses(notification.packageName)) {
|
if (notification && shouldPopUpNewNotification(notification.packageName)) {
|
||||||
this.notificationPopups.post(notificationKey, notificationPopupDelayMs(notification));
|
this.notificationPopups.post(notificationKey, notificationPopupDelayMs(notification));
|
||||||
}
|
}
|
||||||
this.requestShellRender();
|
this.requestShellRender();
|
||||||
@@ -2970,7 +2973,7 @@ class DashboardController {
|
|||||||
private popUpAndroidNotification(notificationKey: string): void {
|
private popUpAndroidNotification(notificationKey: string): void {
|
||||||
try {
|
try {
|
||||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
||||||
if (!notification || !shouldShowNotificationOnGlasses(notification.packageName)) return;
|
if (!notification || !shouldPopUpNewNotification(notification.packageName)) return;
|
||||||
// New notifications open a shell modal over the app viewport; if the
|
// New notifications open a shell modal over the app viewport; if the
|
||||||
// screen was off, wake for it and go back to sleep when it is closed.
|
// screen was off, wake for it and go back to sleep when it is closed.
|
||||||
// Waking while already on would steal focus, so only wake from sleep.
|
// Waking while already on would steal focus, so only wake from sleep.
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { startRemoteInput } from "../remote/service"
|
|||||||
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
|
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
|
||||||
import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
|
import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
|
||||||
import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup, readActiveNotifications } from '../native/notification-icons.ios'
|
import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup, readActiveNotifications } from '../native/notification-icons.ios'
|
||||||
import { shouldShowNotificationOnGlasses } from '../native/notification-sources'
|
|
||||||
import { launcherEntries } from '../apps/launcher'
|
import { launcherEntries } from '../apps/launcher'
|
||||||
import { discardZeroedEvenHubPackage, getInstalledEvenHubAppById, installedEvenHubPackageId, uninstallEvenHubPackage } from '../apps/evenhub/installed-apps'
|
import { discardZeroedEvenHubPackage, getInstalledEvenHubAppById, installedEvenHubPackageId, uninstallEvenHubPackage } from '../apps/evenhub/installed-apps'
|
||||||
import { isInstalledPackagePresent } from '../apps/evenhub/updates'
|
import { isInstalledPackagePresent } from '../apps/evenhub/updates'
|
||||||
@@ -54,7 +53,7 @@ import { onAnySettingChanged,
|
|||||||
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
|
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
|
||||||
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
|
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
|
||||||
openAiApiKeySetting, sonioxApiKeySetting, whisperServerApiKeySetting, whisperServerLanguageSetting,
|
openAiApiKeySetting, sonioxApiKeySetting, whisperServerApiKeySetting, whisperServerLanguageSetting,
|
||||||
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting, glassesTypeSetting } from '../ui/dashboard-settings'
|
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting, glassesTypeSetting, shouldPopUpNewNotification } from '../ui/dashboard-settings'
|
||||||
import { transcriptionKey, type VoiceProviderSelection } from '../native/cloud-stt-provider'
|
import { transcriptionKey, type VoiceProviderSelection } from '../native/cloud-stt-provider'
|
||||||
import type { PhoneGesture } from '../phone-ui/phone-gestures'
|
import type { PhoneGesture } from '../phone-ui/phone-gestures'
|
||||||
import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from '../apps/onboarding/onboarding-progress'
|
import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from '../apps/onboarding/onboarding-progress'
|
||||||
@@ -216,7 +215,8 @@ export class IosPreviewController {
|
|||||||
requestShellRender: () => this.requestShellRender(),
|
requestShellRender: () => this.requestShellRender(),
|
||||||
onWindowsChanged: () => { this.requestShellRender(); this.syncEvenHubPhoneUi(); this.wearRemote?.schedulePublish() },
|
onWindowsChanged: () => { this.requestShellRender(); this.syncEvenHubPhoneUi(); this.wearRemote?.schedulePublish() },
|
||||||
openNotificationsWindow: () =>
|
openNotificationsWindow: () =>
|
||||||
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow),
|
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID,
|
||||||
|
options => createNotificationsAppWindow(options, section => { void this.launchApp('settings', { section }) })),
|
||||||
onSwitcherBarHeightChanged: () => {
|
onSwitcherBarHeightChanged: () => {
|
||||||
this.relayout()
|
this.relayout()
|
||||||
shell.foregroundWindow()?.requestRender()
|
shell.foregroundWindow()?.requestRender()
|
||||||
@@ -248,7 +248,7 @@ export class IosPreviewController {
|
|||||||
shell.focusWindow(launcher.windowId)
|
shell.focusWindow(launcher.windowId)
|
||||||
onIosNotificationPopup(key => {
|
onIosNotificationPopup(key => {
|
||||||
const notification = readActiveNotifications(128).find(n => n.key === key)
|
const notification = readActiveNotifications(128).find(n => n.key === key)
|
||||||
if (this.glassesLocked || !notification || !shouldShowNotificationOnGlasses(notification.packageName)) return
|
if (this.glassesLocked || !notification || !shouldPopUpNewNotification(notification.packageName)) return
|
||||||
const woke = !shell.isScreenOn() && shell.wake('sidebar')
|
const woke = !shell.isScreenOn() && shell.wake('sidebar')
|
||||||
shell.openNotificationModal(key, woke)
|
shell.openNotificationModal(key, woke)
|
||||||
this.requestShellRender()
|
this.requestShellRender()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
type AssistantModel,
|
type AssistantModel,
|
||||||
} from "~/assistant/models";
|
} from "~/assistant/models";
|
||||||
import { isLocalModelReady } from "../native/local-llm";
|
import { isLocalModelReady } from "../native/local-llm";
|
||||||
|
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
||||||
import { normalizeWhisperServerUrl } from "../native/whisper-server-stt";
|
import { normalizeWhisperServerUrl } from "../native/whisper-server-stt";
|
||||||
import { normalizeOpenAiCompatibleUrl } from "../native/openai-chat";
|
import { normalizeOpenAiCompatibleUrl } from "../native/openai-chat";
|
||||||
import { isValidSpotifyClientId, SPOTIFY_CLIENT_ID_KEY } from "../native/spotify-auth";
|
import { isValidSpotifyClientId, SPOTIFY_CLIENT_ID_KEY } from "../native/spotify-auth";
|
||||||
@@ -40,6 +41,8 @@ export type TimeFormat = "24h" | "12h";
|
|||||||
export type TemperatureUnit = "fahrenheit" | "celsius";
|
export type TemperatureUnit = "fahrenheit" | "celsius";
|
||||||
export type DistanceUnit = "miles" | "kilometers";
|
export type DistanceUnit = "miles" | "kilometers";
|
||||||
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "3m" | "never";
|
export type ScreenTimeoutSetting = "15s" | "30s" | "1m" | "3m" | "never";
|
||||||
|
/** Whether new phone notifications pop up on the glasses, and for how long without interaction. */
|
||||||
|
export type NewNotificationDisplay = "off" | "until-dismissed" | "5s" | "15s" | "1m";
|
||||||
// Auto runs Faceclaw's light curve. Numeric values use the calibrated firmware
|
// Auto runs Faceclaw's light curve. Numeric values use the calibrated firmware
|
||||||
// scale, clamped to 2–100; 2 is also the endpoint for screen fades.
|
// scale, clamped to 2–100; 2 is also the endpoint for screen fades.
|
||||||
export const BRIGHTNESS_VALUES = ["auto", "2", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"] as const;
|
export const BRIGHTNESS_VALUES = ["auto", "2", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"] as const;
|
||||||
@@ -663,6 +666,23 @@ export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>(
|
|||||||
description: "How long the display stays on after the last input before turning itself off. \"Never\" keeps it on until turned off manually.",
|
description: "How long the display stays on after the last input before turning itself off. \"Never\" keeps it on until turned off manually.",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const newNotificationDisplaySetting = new ConfigSettingEnum<NewNotificationDisplay>({
|
||||||
|
id: "new-notification-display",
|
||||||
|
label: "Display new notifications",
|
||||||
|
storageKey: "notifications.newNotificationDisplay",
|
||||||
|
defaultValue: "15s",
|
||||||
|
values: ["off", "until-dismissed", "5s", "15s", "1m"],
|
||||||
|
formatValue: newNotificationDisplayLabel,
|
||||||
|
description:
|
||||||
|
"Pop up new phone notifications on the glasses. A timed popup closes once left untouched that long; " +
|
||||||
|
"the notification stays on the phone and in the status bar.",
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Whether a newly posted phone notification from this app pops up on the glasses (the global setting, then the app's filter toggle). */
|
||||||
|
export function shouldPopUpNewNotification(packageName: string): boolean {
|
||||||
|
return newNotificationDisplaySetting.get() !== "off" && shouldShowNotificationOnGlasses(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
export const lockScreenEnabledSetting = new ConfigSettingBoolean({
|
export const lockScreenEnabledSetting = new ConfigSettingBoolean({
|
||||||
id: "lock-screen-enabled",
|
id: "lock-screen-enabled",
|
||||||
label: "Enable lock screen",
|
label: "Enable lock screen",
|
||||||
@@ -1571,6 +1591,34 @@ export function screenTimeoutSettingToMs(value: ScreenTimeoutSetting): number |
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** How long an untouched new-notification popup stays up; null keeps it until dismissed (and for "off", which never opens one). */
|
||||||
|
export function newNotificationDisplayTimeoutMs(value: NewNotificationDisplay): number | null {
|
||||||
|
switch (value) {
|
||||||
|
case "5s":
|
||||||
|
return 5_000;
|
||||||
|
case "15s":
|
||||||
|
return 15_000;
|
||||||
|
case "1m":
|
||||||
|
return 60_000;
|
||||||
|
case "off":
|
||||||
|
case "until-dismissed":
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function newNotificationDisplayLabel(value: NewNotificationDisplay): string {
|
||||||
|
switch (value) {
|
||||||
|
case "off":
|
||||||
|
return "Off";
|
||||||
|
case "until-dismissed":
|
||||||
|
return "Until dismissed";
|
||||||
|
case "1m":
|
||||||
|
return "1min";
|
||||||
|
default:
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function brightnessLabel(value: BrightnessSetting): string {
|
export function brightnessLabel(value: BrightnessSetting): string {
|
||||||
return value === "auto" ? "Auto" : value;
|
return value === "auto" ? "Auto" : value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ import {
|
|||||||
firmwareDebugFlagsSetting,
|
firmwareDebugFlagsSetting,
|
||||||
lockScreenEnabledSetting,
|
lockScreenEnabledSetting,
|
||||||
menuAnimationSetting,
|
menuAnimationSetting,
|
||||||
|
newNotificationDisplaySetting,
|
||||||
saveVoiceRecordingsSetting,
|
saveVoiceRecordingsSetting,
|
||||||
showBleBandwidthSetting,
|
showBleBandwidthSetting,
|
||||||
suspendEvenHubWhenScreenOffSetting,
|
suspendEvenHubWhenScreenOffSetting,
|
||||||
@@ -100,9 +101,13 @@ import {
|
|||||||
import { wearBridge } from "../../native/wear-bridge";
|
import { wearBridge } from "../../native/wear-bridge";
|
||||||
import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from "./settings-panel";
|
import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from "./settings-panel";
|
||||||
import { uiFontPickerMenuItem } from "../font-picker";
|
import { uiFontPickerMenuItem } from "../font-picker";
|
||||||
|
import { NotificationFilterLayer } from "../notification-filter";
|
||||||
import { compatibleModelDiscoveryMenuItem } from "../openai-compatible-model-picker";
|
import { compatibleModelDiscoveryMenuItem } from "../openai-compatible-model-picker";
|
||||||
import { isVeniceApiBaseUrl } from "../../native/openai-chat";
|
import { isVeniceApiBaseUrl } from "../../native/openai-chat";
|
||||||
|
|
||||||
|
/** The Settings section the Notifications app's "Settings" menu item opens. */
|
||||||
|
export const NOTIFICATIONS_SETTINGS_SECTION = "Notifications";
|
||||||
|
|
||||||
/** The Settings app's master-detail panel (sections on the left, contents on the right). */
|
/** The Settings app's master-detail panel (sections on the left, contents on the right). */
|
||||||
export function createSettingsPanelLayer(): SettingsPanelLayer {
|
export function createSettingsPanelLayer(): SettingsPanelLayer {
|
||||||
return new SettingsPanelLayer(settingsSections());
|
return new SettingsPanelLayer(settingsSections());
|
||||||
@@ -138,6 +143,14 @@ function settingsSections(): SettingsSection[] {
|
|||||||
return customizationItems();
|
return customizationItems();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Also opened from the Notifications app's menu (deep link by label).
|
||||||
|
label: NOTIFICATIONS_SETTINGS_SECTION,
|
||||||
|
items: [
|
||||||
|
enumSettingMenuItem(newNotificationDisplaySetting),
|
||||||
|
notificationFilterMenuItem(),
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "Voice",
|
label: "Voice",
|
||||||
items: [
|
items: [
|
||||||
@@ -334,6 +347,17 @@ function customizationRows(): () => MenuItem[] {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Notifications > Notification filter: per-app toggles for which notifications pop up. */
|
||||||
|
function notificationFilterMenuItem(): MenuItem {
|
||||||
|
return submenuItem(
|
||||||
|
"Notification filter",
|
||||||
|
(ctx) => {
|
||||||
|
ctx.stack.push(new NotificationFilterLayer());
|
||||||
|
},
|
||||||
|
{ description: "Choose which apps' new notifications pop up on the glasses. All of them still appear in the Notifications app." },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function autoBrightnessMenuItem(): MenuItem {
|
function autoBrightnessMenuItem(): MenuItem {
|
||||||
return submenuItem(
|
return submenuItem(
|
||||||
"Auto-brightness",
|
"Auto-brightness",
|
||||||
|
|||||||
@@ -40,12 +40,21 @@ export function modalRect(): { x: number; y: number; width: number; height: numb
|
|||||||
export class ShellModalLayer implements Layer {
|
export class ShellModalLayer implements Layer {
|
||||||
private readonly stack: LayerStack;
|
private readonly stack: LayerStack;
|
||||||
|
|
||||||
constructor(baseLayer: Layer, actions: LayerActions, private readonly removed?: () => void) {
|
constructor(
|
||||||
|
baseLayer: Layer,
|
||||||
|
actions: LayerActions,
|
||||||
|
private readonly hooks: {
|
||||||
|
/** The modal left the shell stack, however it went. */
|
||||||
|
removed?: () => void;
|
||||||
|
/** Input reached the modal (before its inner stack handles it). */
|
||||||
|
input?: (event: InputEvent) => void;
|
||||||
|
} = {},
|
||||||
|
) {
|
||||||
this.stack = new LayerStack(baseLayer, actions, modalInterior());
|
this.stack = new LayerStack(baseLayer, actions, modalInterior());
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemoved(): void {
|
onRemoved(): void {
|
||||||
this.removed?.();
|
this.hooks.removed?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||||
@@ -73,6 +82,7 @@ export class ShellModalLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleInput(event: InputEvent, _ctx: LayerContext): Promise<void> {
|
async handleInput(event: InputEvent, _ctx: LayerContext): Promise<void> {
|
||||||
|
this.hooks.input?.(event);
|
||||||
await this.stack.handleInput(event);
|
await this.stack.handleInput(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ export function notificationPopupDelayMs(notification: { foregroundService?: boo
|
|||||||
/** Runs `run` after `delayMs`; returns a function that cancels it. */
|
/** Runs `run` after `delayMs`; returns a function that cancels it. */
|
||||||
export type ScheduleFn = (run: () => void, delayMs: number) => () => void;
|
export type ScheduleFn = (run: () => void, delayMs: number) => () => void;
|
||||||
|
|
||||||
const scheduleTimeout: ScheduleFn = (run, delayMs) => {
|
export const scheduleTimeout: ScheduleFn = (run, delayMs) => {
|
||||||
const timer = setTimeout(run, delayMs);
|
const timer = setTimeout(run, delayMs);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { scheduleTimeout, type ScheduleFn } from "./notification-popup-delay";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a new-notification popup that is left untouched for its timeout
|
||||||
|
* ("Display new notifications"). The host restarts the countdown when the
|
||||||
|
* popup opens and on each interaction with it (any input, including moving
|
||||||
|
* its menu selection), and stops it when the popup goes away.
|
||||||
|
*/
|
||||||
|
export class NotificationPopupTimeout {
|
||||||
|
private cancel: (() => void) | null = null;
|
||||||
|
|
||||||
|
/** `timeoutMs` null never expires (the popup stays until dismissed). */
|
||||||
|
constructor(
|
||||||
|
private readonly timeoutMs: number | null,
|
||||||
|
private readonly expired: () => void,
|
||||||
|
private readonly schedule: ScheduleFn = scheduleTimeout,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/** Start the countdown over. */
|
||||||
|
restart(): void {
|
||||||
|
this.stop();
|
||||||
|
if (this.timeoutMs === null) return;
|
||||||
|
this.cancel = this.schedule(() => {
|
||||||
|
this.cancel = null;
|
||||||
|
this.expired();
|
||||||
|
}, this.timeoutMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(): void {
|
||||||
|
this.cancel?.();
|
||||||
|
this.cancel = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether a countdown is running (for tests). */
|
||||||
|
isRunning(): boolean {
|
||||||
|
return this.cancel !== null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
-5
@@ -45,8 +45,11 @@ import {
|
|||||||
veniceWebSearchSetting,
|
veniceWebSearchSetting,
|
||||||
batteryIndicatorSettingsKey,
|
batteryIndicatorSettingsKey,
|
||||||
brightnessSetting,
|
brightnessSetting,
|
||||||
|
newNotificationDisplaySetting,
|
||||||
|
newNotificationDisplayTimeoutMs,
|
||||||
onAnySettingChanged,
|
onAnySettingChanged,
|
||||||
openAiApiKeySetting,
|
openAiApiKeySetting,
|
||||||
|
shouldPopUpNewNotification,
|
||||||
statusBarPositionSetting,
|
statusBarPositionSetting,
|
||||||
statusBarVisibilitySetting,
|
statusBarVisibilitySetting,
|
||||||
timeFormatSetting,
|
timeFormatSetting,
|
||||||
@@ -65,8 +68,8 @@ import {
|
|||||||
} from "./chrome-layer";
|
} from "./chrome-layer";
|
||||||
import { ShellModalLayer } from "./modal-layer";
|
import { ShellModalLayer } from "./modal-layer";
|
||||||
import { NotificationModalQueue } from "./notification-modal-queue";
|
import { NotificationModalQueue } from "./notification-modal-queue";
|
||||||
|
import { NotificationPopupTimeout } from "./notification-popup-timeout";
|
||||||
import { ALL_NOTIFICATIONS, readActiveNotifications } from "../../native/notification-icons";
|
import { ALL_NOTIFICATIONS, readActiveNotifications } from "../../native/notification-icons";
|
||||||
import { shouldShowNotificationOnGlasses } from "../../native/notification-sources";
|
|
||||||
import { ToolDebugMenuLayer } from "./tool-debug-layer";
|
import { ToolDebugMenuLayer } from "./tool-debug-layer";
|
||||||
import type { InProcessWindow } from "./in-process-window";
|
import type { InProcessWindow } from "./in-process-window";
|
||||||
import { BrightnessPickerLayer } from "./brightness-picker-layer";
|
import { BrightnessPickerLayer } from "./brightness-picker-layer";
|
||||||
@@ -483,7 +486,7 @@ class Shell {
|
|||||||
isAvailable: (notificationKey) => {
|
isAvailable: (notificationKey) => {
|
||||||
if (this.appNotifications.has(notificationKey)) return true;
|
if (this.appNotifications.has(notificationKey)) return true;
|
||||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
|
||||||
return !!notification && shouldShowNotificationOnGlasses(notification.packageName);
|
return !!notification && shouldPopUpNewNotification(notification.packageName);
|
||||||
},
|
},
|
||||||
sleep: () => this.sleep(),
|
sleep: () => this.sleep(),
|
||||||
});
|
});
|
||||||
@@ -929,18 +932,36 @@ class Shell {
|
|||||||
const content = appNotification
|
const content = appNotification
|
||||||
? null
|
? null
|
||||||
: new SingleNotificationLayer(notificationKey, { origin: "new-notification-modal", onClose: close });
|
: new SingleNotificationLayer(notificationKey, { origin: "new-notification-modal", onClose: close });
|
||||||
|
// A phone notification's popup closes once left untouched for the
|
||||||
|
// "Display new notifications" time, as if closed by hand: the notification
|
||||||
|
// stays on the phone and in the status bar. An app's own notification
|
||||||
|
// (e.g. a Nightscout alert) is nowhere else to be found, so it stays up.
|
||||||
|
const timeout = new NotificationPopupTimeout(
|
||||||
|
appNotification ? null : newNotificationDisplayTimeoutMs(newNotificationDisplaySetting.get()),
|
||||||
|
() => {
|
||||||
|
// Something over the popup (a voice dialog, the system menu) is in
|
||||||
|
// use; count that as interaction rather than closing underneath it.
|
||||||
|
if (this.stack.topMatches((layer) => layer === popup.modal)) close();
|
||||||
|
else timeout.restart();
|
||||||
|
},
|
||||||
|
);
|
||||||
const popup: NotificationPopup = {
|
const popup: NotificationPopup = {
|
||||||
content,
|
content,
|
||||||
modal: new ShellModalLayer(
|
modal: new ShellModalLayer(
|
||||||
appNotification ? appNotification.createLayer(close) : content!,
|
appNotification ? appNotification.createLayer(close) : content!,
|
||||||
this.config.actions,
|
this.config.actions,
|
||||||
() => {
|
{
|
||||||
this.appNotifications.delete(notificationKey);
|
removed: () => {
|
||||||
this.notificationModals.removed(popup, this.screenOn);
|
timeout.stop();
|
||||||
|
this.appNotifications.delete(notificationKey);
|
||||||
|
this.notificationModals.removed(popup, this.screenOn);
|
||||||
|
},
|
||||||
|
input: () => timeout.restart(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
this.stack.push(popup.modal);
|
this.stack.push(popup.modal);
|
||||||
|
timeout.restart();
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
|||||||
'../notifications': {}, '../dashboard-settings': settings, './ambient-cards': {},
|
'../notifications': {}, '../dashboard-settings': settings, './ambient-cards': {},
|
||||||
'./chrome-layer': { ShellChromeLayer: class {} }, './modal-layer': {}, './tool-debug-layer': {},
|
'./chrome-layer': { ShellChromeLayer: class {} }, './modal-layer': {}, './tool-debug-layer': {},
|
||||||
'./brightness-picker-layer': {}, './notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts', {}),
|
'./brightness-picker-layer': {}, './notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts', {}),
|
||||||
|
'./notification-popup-timeout': {},
|
||||||
'../../native/notification-icons': {}, '../../native/notification-sources': {},
|
'../../native/notification-icons': {}, '../../native/notification-sources': {},
|
||||||
'../../assistant/tool-registry': {}, './geometry': {
|
'../../assistant/tool-registry': {}, './geometry': {
|
||||||
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
|
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ function settingsEnv(initialUrl = '', initialModel = 'openai-compatible') {
|
|||||||
openSettingsSubMenu() {},
|
openSettingsSubMenu() {},
|
||||||
},
|
},
|
||||||
'../font-picker': { uiFontPickerMenuItem: () => ({ label: 'Font' }) },
|
'../font-picker': { uiFontPickerMenuItem: () => ({ label: 'Font' }) },
|
||||||
|
'../notification-filter': { NotificationFilterLayer: class {} },
|
||||||
'../openai-compatible-model-picker': {
|
'../openai-compatible-model-picker': {
|
||||||
compatibleModelDiscoveryMenuItem: () => ({ label: 'Discover models' }),
|
compatibleModelDiscoveryMenuItem: () => ({ label: 'Discover models' }),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,6 +23,41 @@ function store(settings = new Map()) {
|
|||||||
}
|
}
|
||||||
const mail = { packageName: 'com.mail', appName: 'Mail' };
|
const mail = { packageName: 'com.mail', appName: 'Mail' };
|
||||||
|
|
||||||
|
/** dashboard-settings.ts over the same in-memory store, with `prefs` as its notification-sources. */
|
||||||
|
function dashboardSettings(settings, prefs) {
|
||||||
|
return evaluate(source('app/ui/dashboard-settings.ts'), (id) => {
|
||||||
|
if (id.includes('settings-store')) return {
|
||||||
|
onSettingsStoreChanged() {}, getStringSetting: (key, fallback) => settings.get(key) ?? fallback,
|
||||||
|
setStringSetting: (key, value) => settings.set(key, value),
|
||||||
|
getBooleanSetting: (key, fallback) => settings.get(key) ?? fallback, setBooleanSetting: (key, value) => settings.set(key, value),
|
||||||
|
};
|
||||||
|
if (id.includes('notification-sources')) return prefs;
|
||||||
|
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
|
||||||
|
if (id.includes('animation-speed')) return require('../.test-build/app/ui/animation-speed.js');
|
||||||
|
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
|
||||||
|
}, { global: { isIOS: false } });
|
||||||
|
}
|
||||||
|
|
||||||
|
test('"Display new notifications" defaults to 15s; Off stops every popup, the filter still mutes single apps', () => {
|
||||||
|
const settings = new Map();
|
||||||
|
const prefs = store(settings);
|
||||||
|
const api = dashboardSettings(settings, prefs);
|
||||||
|
assert.equal(api.newNotificationDisplaySetting.get(), '15s');
|
||||||
|
// Array.from: the module's arrays come from its own VM realm.
|
||||||
|
const values = Array.from(api.newNotificationDisplaySetting.values);
|
||||||
|
assert.deepEqual(values.map((value) => api.newNotificationDisplaySetting.displayValue(value)),
|
||||||
|
['Off', 'Until dismissed', '5s', '15s', '1min']);
|
||||||
|
assert.deepEqual(values.map(api.newNotificationDisplayTimeoutMs), [null, null, 5_000, 15_000, 60_000]);
|
||||||
|
assert.equal(api.shouldPopUpNewNotification(mail.packageName), true);
|
||||||
|
prefs.setNotificationSourceEnabled(mail, false);
|
||||||
|
assert.equal(api.shouldPopUpNewNotification(mail.packageName), false);
|
||||||
|
assert.equal(api.shouldPopUpNewNotification('com.other'), true);
|
||||||
|
api.newNotificationDisplaySetting.set('off');
|
||||||
|
assert.equal(api.shouldPopUpNewNotification('com.other'), false);
|
||||||
|
api.newNotificationDisplaySetting.set('until-dismissed');
|
||||||
|
assert.equal(api.shouldPopUpNewNotification('com.other'), true);
|
||||||
|
});
|
||||||
|
|
||||||
test('sources default on and retain per-package choices and names across restart and rediscovery', () => {
|
test('sources default on and retain per-package choices and names across restart and rediscovery', () => {
|
||||||
const settings = new Map();
|
const settings = new Map();
|
||||||
let prefs = store(settings);
|
let prefs = store(settings);
|
||||||
@@ -194,14 +229,16 @@ test('controller filters before waking or opening a popup, and still refreshes t
|
|||||||
const members = ['handleAndroidNotificationPosted', 'handleAndroidNotificationRemoved', 'popUpAndroidNotification']
|
const members = ['handleAndroidNotificationPosted', 'handleAndroidNotificationRemoved', 'popUpAndroidNotification']
|
||||||
.map((name) => controller.members.find((node) => node.name?.getText(file) === name).getText(file));
|
.map((name) => controller.members.find((node) => node.name?.getText(file) === name).getText(file));
|
||||||
const { NotificationPopupDelay, notificationPopupDelayMs } = require('../.test-build/app/ui/shell/notification-popup-delay.js');
|
const { NotificationPopupDelay, notificationPopupDelayMs } = require('../.test-build/app/ui/shell/notification-popup-delay.js');
|
||||||
const prefs = store();
|
const settings = new Map();
|
||||||
|
const prefs = store(settings);
|
||||||
|
const { newNotificationDisplaySetting, shouldPopUpNewNotification } = dashboardSettings(settings, prefs);
|
||||||
let active = [{ ...mail, key: 'key' }];
|
let active = [{ ...mail, key: 'key' }];
|
||||||
let wakes = 0, popups = 0, renders = 0;
|
let wakes = 0, popups = 0, renders = 0;
|
||||||
const removed = [];
|
const removed = [];
|
||||||
const { Harness } = evaluate(`export class Harness { ${members.join('\n')} }`, null, {
|
const { Harness } = evaluate(`export class Harness { ${members.join('\n')} }`, null, {
|
||||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||||
readActiveNotifications: () => active,
|
readActiveNotifications: () => active,
|
||||||
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
|
shouldPopUpNewNotification,
|
||||||
notificationPopupDelayMs,
|
notificationPopupDelayMs,
|
||||||
shell: {
|
shell: {
|
||||||
isScreenOn: () => false,
|
isScreenOn: () => false,
|
||||||
@@ -253,4 +290,16 @@ test('controller filters before waking or opening a popup, and still refreshes t
|
|||||||
prefs.setNotificationSourceEnabled(mail, false);
|
prefs.setNotificationSourceEnabled(mail, false);
|
||||||
elapse();
|
elapse();
|
||||||
assert.equal(popups, 1);
|
assert.equal(popups, 1);
|
||||||
|
|
||||||
|
// "Display new notifications: Off" holds back every app's popup, also once the delay is over.
|
||||||
|
prefs.setNotificationSourceEnabled(mail, true);
|
||||||
|
newNotificationDisplaySetting.set('off');
|
||||||
|
instance.handleAndroidNotificationPosted('key');
|
||||||
|
elapse();
|
||||||
|
newNotificationDisplaySetting.set('15s');
|
||||||
|
instance.handleAndroidNotificationPosted('key');
|
||||||
|
newNotificationDisplaySetting.set('off');
|
||||||
|
elapse();
|
||||||
|
assert.equal(wakes, 1);
|
||||||
|
assert.equal(popups, 1);
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
const test = require("node:test");
|
||||||
|
const assert = require("node:assert/strict");
|
||||||
|
|
||||||
|
const { NotificationPopupTimeout } = require("../.test-build/app/ui/shell/notification-popup-timeout.js");
|
||||||
|
|
||||||
|
/** A manual clock: schedule() queues timers that advance() fires when due. */
|
||||||
|
function makeClock() {
|
||||||
|
const clock = {
|
||||||
|
nowMs: 0,
|
||||||
|
timers: [],
|
||||||
|
schedule(run, delayMs) {
|
||||||
|
const timer = { dueAtMs: clock.nowMs + delayMs, run, cancelled: false };
|
||||||
|
clock.timers.push(timer);
|
||||||
|
return () => { timer.cancelled = true; };
|
||||||
|
},
|
||||||
|
advance(ms) {
|
||||||
|
const until = clock.nowMs + ms;
|
||||||
|
for (;;) {
|
||||||
|
const due = clock.timers.filter((timer) => !timer.cancelled && timer.dueAtMs <= until)
|
||||||
|
.sort((a, b) => a.dueAtMs - b.dueAtMs)[0];
|
||||||
|
if (!due) break;
|
||||||
|
clock.nowMs = due.dueAtMs;
|
||||||
|
due.cancelled = true;
|
||||||
|
due.run();
|
||||||
|
}
|
||||||
|
clock.nowMs = until;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeTimeout(timeoutMs) {
|
||||||
|
const clock = makeClock();
|
||||||
|
let expiries = 0;
|
||||||
|
const timeout = new NotificationPopupTimeout(timeoutMs, () => { expiries++; }, clock.schedule);
|
||||||
|
return { clock, timeout, expiries: () => expiries };
|
||||||
|
}
|
||||||
|
|
||||||
|
test("an untouched popup expires once its timeout passes", () => {
|
||||||
|
const { clock, timeout, expiries } = makeTimeout(15_000);
|
||||||
|
timeout.restart();
|
||||||
|
clock.advance(14_999);
|
||||||
|
assert.equal(expiries(), 0);
|
||||||
|
clock.advance(1);
|
||||||
|
assert.equal(expiries(), 1);
|
||||||
|
assert.equal(timeout.isRunning(), false);
|
||||||
|
clock.advance(60_000);
|
||||||
|
assert.equal(expiries(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("each interaction starts the countdown over", () => {
|
||||||
|
const { clock, timeout, expiries } = makeTimeout(5_000);
|
||||||
|
timeout.restart();
|
||||||
|
clock.advance(4_000);
|
||||||
|
timeout.restart(); // e.g. scrolling the action menu
|
||||||
|
clock.advance(4_000);
|
||||||
|
assert.equal(expiries(), 0);
|
||||||
|
clock.advance(1_000);
|
||||||
|
assert.equal(expiries(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a popup that goes away first never expires", () => {
|
||||||
|
const { clock, timeout, expiries } = makeTimeout(5_000);
|
||||||
|
timeout.restart();
|
||||||
|
clock.advance(2_000);
|
||||||
|
timeout.stop();
|
||||||
|
clock.advance(10_000);
|
||||||
|
assert.equal(expiries(), 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("until-dismissed (no timeout) never schedules anything", () => {
|
||||||
|
const { clock, timeout, expiries } = makeTimeout(null);
|
||||||
|
timeout.restart();
|
||||||
|
assert.equal(timeout.isRunning(), false);
|
||||||
|
assert.equal(clock.timers.length, 0);
|
||||||
|
clock.advance(1_000_000);
|
||||||
|
assert.equal(expiries(), 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the expiry callback can restart the countdown (something was over the popup)", () => {
|
||||||
|
const clock = makeClock();
|
||||||
|
let expiries = 0;
|
||||||
|
const timeout = new NotificationPopupTimeout(5_000, () => {
|
||||||
|
expiries++;
|
||||||
|
if (expiries === 1) timeout.restart();
|
||||||
|
}, clock.schedule);
|
||||||
|
timeout.restart();
|
||||||
|
clock.advance(5_000);
|
||||||
|
assert.equal(expiries, 1);
|
||||||
|
assert.equal(timeout.isRunning(), true);
|
||||||
|
clock.advance(5_000);
|
||||||
|
assert.equal(expiries, 2);
|
||||||
|
assert.equal(timeout.isRunning(), false);
|
||||||
|
});
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
"../app/g2/glance-state.ts",
|
"../app/g2/glance-state.ts",
|
||||||
"../app/ui/shell/notification-modal-queue.ts",
|
"../app/ui/shell/notification-modal-queue.ts",
|
||||||
"../app/ui/shell/notification-popup-delay.ts",
|
"../app/ui/shell/notification-popup-delay.ts",
|
||||||
|
"../app/ui/shell/notification-popup-timeout.ts",
|
||||||
"../app/apps/glanceboard/layout.ts",
|
"../app/apps/glanceboard/layout.ts",
|
||||||
"../app/apps/files/video-layout.ts",
|
"../app/apps/files/video-layout.ts",
|
||||||
"../app/g2/pairing-candidates.ts",
|
"../app/g2/pairing-candidates.ts",
|
||||||
|
|||||||
Reference in new issue
Block a user