forked from Blendman974/faceclaw
feat: separate per-app keep awake from full screen
This commit is contained in:
7 files changed
+105
-21
No files matched your search
@@ -164,6 +164,23 @@ export function appFullscreenSetting(appId: string): ConfigSettingBoolean {
|
||||
return setting;
|
||||
}
|
||||
|
||||
const appKeepAwakeSettings = new Map<string, ConfigSettingBoolean>();
|
||||
|
||||
/** Independent of full screen; applies only while this app is visible. */
|
||||
export function appKeepAwakeSetting(appId: string): ConfigSettingBoolean {
|
||||
let setting = appKeepAwakeSettings.get(appId);
|
||||
if (!setting) {
|
||||
setting = new ConfigSettingBoolean({
|
||||
id: `app-keep-awake-${appId}`, label: "Keep screen awake",
|
||||
description: "Prevent automatic sleep while this app is visible, in any display mode.",
|
||||
storageKey: `display.keepAwake.${appId}`, defaultValue: false,
|
||||
reportInAnalytics: false,
|
||||
});
|
||||
appKeepAwakeSettings.set(appId, setting);
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
|
||||
type ConfigSettingEnumOptions<TValue extends string, TId extends string> = ConfigSettingOptions<TValue, TId> & {
|
||||
values: readonly TValue[];
|
||||
normalize?: (value: string | null | undefined) => TValue;
|
||||
|
||||
+13
-5
@@ -32,6 +32,8 @@ import { SingleNotificationLayer } from "../notifications";
|
||||
import {
|
||||
anthropicApiKeySetting,
|
||||
appFullscreenSetting,
|
||||
appKeepAwakeSetting,
|
||||
toggleSettingMenuItem,
|
||||
assistantHermesKeySetting,
|
||||
assistantHermesUrlSetting,
|
||||
assistantBackendSetting,
|
||||
@@ -74,8 +76,6 @@ import { BrightnessPickerLayer } from "./brightness-picker-layer";
|
||||
import { toolRegistry } from "../../assistant/tool-registry";
|
||||
import {
|
||||
appViewportRect,
|
||||
displayLayout,
|
||||
isImmersive,
|
||||
minWindowTop,
|
||||
sidebarWidth,
|
||||
switcherPosition,
|
||||
@@ -228,7 +228,7 @@ export type ShellConfig = {
|
||||
onSwitcherBarHeightChanged?: () => void;
|
||||
/** A per-app full-screen choice changed the viewport and compositor geometry. */
|
||||
onWindowLayoutChanged?: () => void;
|
||||
/** Full screen must not keep the lock screen awake. */
|
||||
/** An app's keep-awake preference must not keep the lock screen awake. */
|
||||
isLocked?: () => boolean;
|
||||
/**
|
||||
* The Notifications app's window, opened in the background (neither
|
||||
@@ -882,7 +882,7 @@ class Shell {
|
||||
if (this.activeVoiceLayer || this.activeKeyboardLayer || this.assistantSession?.isTurnActive() ||
|
||||
foreground?.isVoiceCapturing?.() || foreground?.keepsScreenOn?.() ||
|
||||
(foreground?.closeable && !this.config.isLocked?.() &&
|
||||
(isImmersive(foreground.appId) || displayLayout(foreground.appId) === "fullscreen"))) {
|
||||
appKeepAwakeSetting(foreground.appId).get())) {
|
||||
this.lastInputAtMs = nowMs;
|
||||
return false;
|
||||
}
|
||||
@@ -1993,7 +1993,7 @@ class Shell {
|
||||
const fullscreen = appFullscreenSetting(foreground.appId);
|
||||
items.push({
|
||||
label: fullscreen.get() ? "Exit full screen" : "Enter full screen",
|
||||
description: "Use the whole display and keep it awake while this app is visible.",
|
||||
description: "Use the whole display for this app.",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.pop();
|
||||
if (!this.windows.some(window => window.windowId === foreground.windowId)) return;
|
||||
@@ -2004,6 +2004,14 @@ class Shell {
|
||||
this.config.requestShellRender();
|
||||
},
|
||||
});
|
||||
items.push(toggleSettingMenuItem(appKeepAwakeSetting(foreground.appId), {
|
||||
onChange: (ctx) => {
|
||||
ctx.stack.pop();
|
||||
this.noteUserActivity();
|
||||
this.focusWindow(foreground.windowId);
|
||||
this.config.requestShellRender();
|
||||
},
|
||||
}));
|
||||
}
|
||||
if (brightnessSetting.get() !== "auto") {
|
||||
items.push({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Per-app full screen
|
||||
# Per-app full screen and keep awake
|
||||
|
||||
Long-press opens the system menu. Closeable apps offer Enter full screen / Exit
|
||||
full screen. The choice persists per app through the existing settings store,
|
||||
@@ -7,14 +7,22 @@ Full screen fills the 640x480 panel, hides chrome while the app has focus, and
|
||||
resizes existing in-process and worker windows without restarting the app.
|
||||
The switcher remains accessible through the system menu.
|
||||
|
||||
Automatic idle sleep is suspended while a closeable full-screen/immersive app
|
||||
is in the foreground. A background full-screen app does not hold the display
|
||||
awake. The lock screen and explicit sleep still work. The inactivity countdown
|
||||
starts fresh after leaving a kept-awake app.
|
||||
Keep screen awake is a separate On/Off switch immediately after the full-screen
|
||||
action in the system menu. It defaults off and persists per app independently
|
||||
of full screen. Existing full-screen preferences remain unchanged and do not
|
||||
implicitly enable keep awake.
|
||||
|
||||
Automatic idle sleep is suspended only while an app with Keep screen awake
|
||||
enabled is in the foreground, in any display mode. A background app does not
|
||||
hold the display awake. Full screen alone does not suppress idle sleep.
|
||||
The lock screen and explicit sleep still work. The inactivity countdown starts
|
||||
fresh after disabling keep awake or leaving a kept-awake app. Existing automatic
|
||||
holds for voice capture, assistant turns and video playback remain in effect.
|
||||
|
||||
Software regressions cover geometry with every switcher position, preserving
|
||||
other display settings and persistence after reload, captured menu targets,
|
||||
exit, foreground/background idle behavior, lock timeout and manual sleep.
|
||||
exit, independent keep-awake persistence, foreground/background idle behavior,
|
||||
lock timeout and manual sleep.
|
||||
|
||||
On glasses, verify entry/exit from both in-process apps and worker apps,
|
||||
reflow, state retention, idle timeout, app switching, lock/off-head behavior,
|
||||
|
||||
@@ -268,6 +268,8 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
||||
const voiceDialogs = [];
|
||||
const settings = { wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
|
||||
appFullscreenSetting: () => ({ get: () => false }),
|
||||
appKeepAwakeSetting: () => ({ label: 'Keep screen awake', get: () => false }),
|
||||
toggleSettingMenuItem: setting => ({ label: setting.label }),
|
||||
assistantSkipConfirmationSetting: { get: () => skipConfirmation } };
|
||||
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
|
||||
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
|
||||
|
||||
@@ -18,6 +18,7 @@ function fixture(options = {}) {
|
||||
selectItem(index) { this.selectedIndex = index; }
|
||||
}
|
||||
const fullscreen = new Map();
|
||||
const keepAwake = new Map();
|
||||
const context = {
|
||||
exports: {}, MenuLayer, console: { warn: () => {} },
|
||||
appViewportRect: () => ({ x: 0, y: 0, width: 576 }), CONTEXT_MENU_DIM: 0.5,
|
||||
@@ -25,7 +26,10 @@ function fixture(options = {}) {
|
||||
GESTURE_SHORT_THEN_LONG_PRESS: 'tap-hold', makeInputEvent: event => event,
|
||||
isWatchInput: event => event.source === 'watch', isDirectionalInput: () => false,
|
||||
appFullscreenSetting: id => ({ get: () => fullscreen.get(id) ?? false, set: value => fullscreen.set(id, value) }),
|
||||
isImmersive: id => fullscreen.get(id) ?? false, displayLayout: () => 'band-middle',
|
||||
appKeepAwakeSetting: id => ({ label: 'Keep screen awake', get: () => keepAwake.get(id) ?? false, set: value => keepAwake.set(id, value) }),
|
||||
toggleSettingMenuItem: (setting, options) => ({ label: setting.label, onSelect(ctx) {
|
||||
setting.set(!setting.get()); options.onChange(ctx);
|
||||
} }),
|
||||
};
|
||||
vm.runInNewContext(ts.transpileModule(`${overlay.getText(source)}\nexport class Shell { ${methods.map(node => node.getText(source)).join('\n')} }`, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
@@ -69,10 +73,10 @@ function fixture(options = {}) {
|
||||
assert.ok(item, label);
|
||||
item.onSelect({ stack: s.stack });
|
||||
};
|
||||
return { s, input, menu, choose, closed, delivered, warnings, renders, launcher, app, background, window, fullscreen };
|
||||
return { s, input, menu, choose, closed, delivered, warnings, renders, launcher, app, background, window, fullscreen, keepAwake };
|
||||
}
|
||||
|
||||
test('full screen targets the captured app and keeps only the visible app awake', async () => {
|
||||
test('full screen targets the captured app without inhibiting idle sleep', async () => {
|
||||
const h = fixture();
|
||||
h.s.config.getScreenTimeoutMs = () => 1000;
|
||||
let relayouts = 0;
|
||||
@@ -84,10 +88,7 @@ test('full screen targets the captured app and keeps only the visible app awake'
|
||||
assert.equal(h.s.foregroundWindow().windowId, 'current');
|
||||
assert.equal(h.s.focus, 'window');
|
||||
assert.equal(relayouts, 1);
|
||||
assert.equal(h.s.applyScreenTimeout(5000), false);
|
||||
h.s.focusWindow('background');
|
||||
assert.equal(h.s.applyScreenTimeout(5500), false);
|
||||
assert.equal(h.s.applyScreenTimeout(6000), true);
|
||||
assert.equal(h.s.applyScreenTimeout(5000), true);
|
||||
h.s.screenOn = true;
|
||||
h.s.focusWindow('current');
|
||||
await h.input('long-press');
|
||||
@@ -97,9 +98,37 @@ test('full screen targets the captured app and keeps only the visible app awake'
|
||||
assert.equal(h.s.applyScreenTimeout(7000), true);
|
||||
});
|
||||
|
||||
test('full screen does not suppress lock timeout or manual sleep, and is absent for the launcher', async () => {
|
||||
test('keep awake is independent of full screen and applies only to the visible app', async () => {
|
||||
const h = fixture();
|
||||
h.s.config.getScreenTimeoutMs = () => 1000;
|
||||
await h.input('long-press');
|
||||
const labels = h.menu().items.map(item => item.label);
|
||||
assert.equal(labels.indexOf('Keep screen awake'), labels.indexOf('Enter full screen') + 1);
|
||||
h.s.selectedIndex = 2;
|
||||
h.choose('Keep screen awake');
|
||||
assert.equal(h.keepAwake.get('current'), true);
|
||||
assert.equal(h.fullscreen.get('current'), undefined);
|
||||
assert.equal(h.s.foregroundWindow().windowId, 'current');
|
||||
assert.equal(h.s.applyScreenTimeout(5000), false);
|
||||
h.s.focusWindow('background');
|
||||
assert.equal(h.s.applyScreenTimeout(5500), false);
|
||||
assert.equal(h.s.applyScreenTimeout(6000), true);
|
||||
h.s.screenOn = true;
|
||||
h.s.focusWindow('current');
|
||||
await h.input('long-press'); h.choose('Enter full screen');
|
||||
assert.equal(h.s.applyScreenTimeout(7000), false);
|
||||
await h.input('long-press'); h.choose('Exit full screen');
|
||||
assert.equal(h.keepAwake.get('current'), true);
|
||||
assert.equal(h.s.applyScreenTimeout(8000), false);
|
||||
await h.input('long-press'); h.choose('Keep screen awake');
|
||||
assert.equal(h.keepAwake.get('current'), false);
|
||||
assert.equal(h.s.applyScreenTimeout(9000), true);
|
||||
});
|
||||
|
||||
test('keep awake does not suppress lock timeout or manual sleep, and options are absent for the launcher', async () => {
|
||||
const h = fixture();
|
||||
h.fullscreen.set('current', true);
|
||||
h.keepAwake.set('current', true);
|
||||
h.s.config.getScreenTimeoutMs = () => 1000;
|
||||
h.s.config.isLocked = () => true;
|
||||
assert.equal(h.s.applyScreenTimeout(5000), true);
|
||||
@@ -111,6 +140,7 @@ test('full screen does not suppress lock timeout or manual sleep, and is absent
|
||||
h.s.selectedIndex = 0;
|
||||
await h.input('long-press');
|
||||
assert.ok(!h.menu().items.some(item => /full screen/.test(item.label)));
|
||||
assert.ok(!h.menu().items.some(item => item.label === 'Keep screen awake'));
|
||||
});
|
||||
|
||||
test('switcher opens its menu on hold or tap-hold even for an app claiming holds or hold-to-talk', async () => {
|
||||
|
||||
@@ -40,6 +40,8 @@ function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height:
|
||||
let value = initial, writes = 0, closed = 0;
|
||||
const settings = {
|
||||
appFullscreenSetting: () => ({ get: () => false }),
|
||||
appKeepAwakeSetting: () => ({ label: 'Keep screen awake', get: () => false }),
|
||||
toggleSettingMenuItem: setting => ({ label: setting.label }),
|
||||
brightnessSetting: { get: () => value, set: (next) => { value = next; writes++; } },
|
||||
brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value),
|
||||
};
|
||||
@@ -121,13 +123,14 @@ test('system menu hides brightness in Auto and opens its picker between Voice in
|
||||
shell.openSystemMenu('test');
|
||||
let opened = shell.stack.layers.at(-1);
|
||||
assert.deepEqual(Array.from(opened.items, (item) => item.label),
|
||||
['Close current app', 'Focus app switcher', 'Voice input', 'Close all apps', 'Enter full screen', 'Debug']);
|
||||
['Close current app', 'Focus app switcher', 'Voice input', 'Close all apps', 'Enter full screen', 'Keep screen awake', 'Debug']);
|
||||
shell.stack.clearToBase();
|
||||
f.settings.brightnessSetting.set('40');
|
||||
shell.openSystemMenu('test');
|
||||
opened = shell.stack.layers.at(-1);
|
||||
assert.deepEqual(Array.from(opened.items, (item) => item.label),
|
||||
['Close current app', 'Focus app switcher', 'Voice input', 'Close all apps', 'Enter full screen', 'Brightness', 'Debug']);
|
||||
['Close current app', 'Focus app switcher', 'Voice input', 'Close all apps', 'Enter full screen', 'Keep screen awake', 'Brightness', 'Debug']);
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
|
||||
@@ -77,3 +77,19 @@ test('per-app full screen defaults off, persists across restart and preserves di
|
||||
assert.equal(restarted.displayLayoutSetting.get(), 'band-low');
|
||||
assert.equal(store.get('terminal.displayLayout'), 'tall');
|
||||
});
|
||||
|
||||
test('keep awake persists per app independently of full screen, including existing full-screen choices', () => {
|
||||
const store = new Map([['display.fullscreen.terminal', true]]);
|
||||
let prefs = settingsFixture(store);
|
||||
assert.equal(prefs.appFullscreenSetting('terminal').get(), true);
|
||||
assert.equal(prefs.appKeepAwakeSetting('terminal').get(), false);
|
||||
prefs.appKeepAwakeSetting('terminal').set(true);
|
||||
prefs = settingsFixture(store);
|
||||
assert.equal(prefs.appKeepAwakeSetting('terminal').get(), true);
|
||||
assert.equal(prefs.appKeepAwakeSetting('other').get(), false);
|
||||
prefs.appFullscreenSetting('terminal').set(false);
|
||||
assert.equal(prefs.appKeepAwakeSetting('terminal').get(), true);
|
||||
prefs.appKeepAwakeSetting('terminal').set(false);
|
||||
prefs = settingsFixture(store);
|
||||
assert.equal(prefs.appKeepAwakeSetting('terminal').get(), false);
|
||||
});
|
||||
Reference in new issue
Block a user