forked from Blendman974/faceclaw
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfda10d47f
|
||
|
|
55bd5f891c
|
No files matched your search
@@ -4,7 +4,7 @@
|
|||||||
* makes the content area exactly the 576x288 surface EvenHub apps expect.
|
* makes the content area exactly the 576x288 surface EvenHub apps expect.
|
||||||
*/
|
*/
|
||||||
import { GrayImage } from "../../graphics/image";
|
import { GrayImage } from "../../graphics/image";
|
||||||
import { EVENHUB_SCREEN_WIDTH } from "./compositor";
|
import { EVENHUB_SCREEN_WIDTH, EVENHUB_SCREEN_HEIGHT } from "./compositor";
|
||||||
import { directionalFallback, isDirectionalInput, type InputEvent } from "../../ui/gestures";
|
import { directionalFallback, isDirectionalInput, type InputEvent } from "../../ui/gestures";
|
||||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||||
import {
|
import {
|
||||||
@@ -24,22 +24,27 @@ class EvenHubAppLayer implements Layer {
|
|||||||
* extension's source field should see that they came from the watch.
|
* extension's source field should see that they came from the watch.
|
||||||
*/
|
*/
|
||||||
readonly acceptsDirectional = true;
|
readonly acceptsDirectional = true;
|
||||||
|
private tallCanvas = false;
|
||||||
|
|
||||||
constructor(private readonly session: EvenHubSession) {}
|
constructor(private readonly session: EvenHubSession) {}
|
||||||
|
|
||||||
|
setTallCanvas(tall: boolean): void {
|
||||||
|
this.tallCanvas = tall;
|
||||||
|
}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
const size = ctx.stack.getBaseSize();
|
const size = ctx.stack.getBaseSize();
|
||||||
// EvenHub apps lay out for the stock 576-wide surface. In the Full
|
// Host full screen hides chrome; it does not enlarge the stock app canvas.
|
||||||
// Screen display mode the window is 640 wide; paint at stock width and
|
// Only the app's explicit Faceclaw extended-layout request opts into height.
|
||||||
// centre it rather than leaving all the slack on the right.
|
const canvas = { width: EVENHUB_SCREEN_WIDTH, height: this.tallCanvas ? size.height : EVENHUB_SCREEN_HEIGHT };
|
||||||
if (size.width > EVENHUB_SCREEN_WIDTH) {
|
const content = this.session.paint(canvas, ctx.stack.isFocused());
|
||||||
const content = this.session.paint({ width: EVENHUB_SCREEN_WIDTH, height: size.height }, ctx.stack.isFocused());
|
if (size.width === canvas.width && size.height === canvas.height) return content;
|
||||||
const image = new GrayImage(size.width, size.height, 0);
|
const image = new GrayImage(size.width, size.height, 0);
|
||||||
content.composeInto(image, Math.floor((size.width - EVENHUB_SCREEN_WIDTH) / 2), 0);
|
// Clip text to its logical canvas before placing it in the larger host window.
|
||||||
|
image.bitBlt(content.withDrawsBaked(), Math.max(0, Math.floor((size.width - canvas.width) / 2)),
|
||||||
|
Math.max(0, Math.floor((size.height - canvas.height) / 2)));
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
return this.session.paint(size, ctx.stack.isFocused());
|
|
||||||
}
|
|
||||||
|
|
||||||
handleInput(event: InputEvent): void {
|
handleInput(event: InputEvent): void {
|
||||||
// Everything goes to the app; the menu gestures never reach here (the
|
// Everything goes to the app; the menu gestures never reach here (the
|
||||||
@@ -60,6 +65,7 @@ export function createEvenHubWindow(
|
|||||||
requestShellRender: () => void,
|
requestShellRender: () => void,
|
||||||
): InProcessWindow {
|
): InProcessWindow {
|
||||||
const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E");
|
const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E");
|
||||||
|
const appLayer = new EvenHubAppLayer(session);
|
||||||
const created = createInProcessWindow({
|
const created = createInProcessWindow({
|
||||||
appId,
|
appId,
|
||||||
windowId,
|
windowId,
|
||||||
@@ -91,7 +97,7 @@ export function createEvenHubWindow(
|
|||||||
{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } },
|
{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } },
|
||||||
],
|
],
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
baseLayer: new EvenHubAppLayer(session),
|
baseLayer: appLayer,
|
||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
setSurfaceVisible: options.setSurfaceVisible,
|
setSurfaceVisible: options.setSurfaceVisible,
|
||||||
removeSurface: options.removeSurface,
|
removeSurface: options.removeSurface,
|
||||||
@@ -109,7 +115,10 @@ export function createEvenHubWindow(
|
|||||||
pushOverlay: (layer) => created.stack.push(layer),
|
pushOverlay: (layer) => created.stack.push(layer),
|
||||||
// The extended layout uses the full 576x452 app area ("max"); stock apps
|
// The extended layout uses the full 576x452 app area ("max"); stock apps
|
||||||
// stay in the 576x288 band ("medium").
|
// stay in the 576x288 band ("medium").
|
||||||
setTallCanvas: (tall) => created.setHeightMode(tall ? "max" : "medium"),
|
setTallCanvas: (tall) => {
|
||||||
|
appLayer.setTallCanvas(tall);
|
||||||
|
created.setHeightMode(tall ? "max" : "medium");
|
||||||
|
},
|
||||||
setAttention: (attention) => shell.setWindowAttention(windowId, attention),
|
setAttention: (attention) => shell.setWindowAttention(windowId, attention),
|
||||||
// Only while the app listens for text: otherwise the shell's Type Into App
|
// Only while the app listens for text: otherwise the shell's Type Into App
|
||||||
// destinations (voice dialog, phone keyboard, watch) would send into a void.
|
// destinations (voice dialog, phone keyboard, watch) would send into a void.
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ import { IconGrid, ICON_GRID_BAND_INSET_X, ICON_GRID_HIGHLIGHT_INSET_Y, ICON_GRI
|
|||||||
import { Layer, LayerActions, LayerContext } from "../../ui/layers";
|
import { Layer, LayerActions, LayerContext } from "../../ui/layers";
|
||||||
import { MenuLayer, type MenuItem } from "../../ui/menu";
|
import { MenuLayer, type MenuItem } from "../../ui/menu";
|
||||||
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
|
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
|
||||||
import {
|
import { onAnySettingChanged } from "../../ui/dashboard-settings";
|
||||||
onAnySettingChanged, launcherLayoutSetting, enumSettingMenuItem,
|
|
||||||
ConfigSettingString, EditTextSettingLayer,
|
|
||||||
} from "../../ui/dashboard-settings";
|
|
||||||
import { getLauncherLayoutFingerprint, orderLauncherEntries, moveLauncherEntry } from "./launcher-layout";
|
|
||||||
import { createInProcessWindow } from "../../ui/shell/in-process-window";
|
import { createInProcessWindow } from "../../ui/shell/in-process-window";
|
||||||
import {
|
import {
|
||||||
getFolderAssignments,
|
getFolderAssignments,
|
||||||
@@ -20,7 +16,6 @@ import {
|
|||||||
getFolderStateFingerprint,
|
getFolderStateFingerprint,
|
||||||
setAppFolder,
|
setAppFolder,
|
||||||
unusedNewFolderName,
|
unusedNewFolderName,
|
||||||
getExplicitFolderNames, createFolder, renameFolder, folderNameError, disbandFolder,
|
|
||||||
} from "./launcher-folders";
|
} from "./launcher-folders";
|
||||||
import { shell, type ShellWindow } from "../../ui/shell/shell";
|
import { shell, type ShellWindow } from "../../ui/shell/shell";
|
||||||
|
|
||||||
@@ -71,14 +66,6 @@ type LauncherGridEntry =
|
|||||||
* and is re-read every paint, so assistant folder tools take effect without
|
* and is re-read every paint, so assistant folder tools take effect without
|
||||||
* the layer holding any copy of the state.
|
* the layer holding any copy of the state.
|
||||||
*/
|
*/
|
||||||
const entryKey = (entry: LauncherGridEntry) => entry.kind === "app" ? `app:${entry.appId}` : `folder:${entry.name}`;
|
|
||||||
|
|
||||||
/** Reuse the phone text editor; dismiss it if the glasses leave this page. */
|
|
||||||
class FolderNameEditorLayer extends EditTextSettingLayer {
|
|
||||||
constructor(setting: ConfigSettingString, private readonly actions: LayerActions) { super(setting); }
|
|
||||||
onRemoved(): void { void this.actions.endTextSettingEdit(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
class LauncherGridLayer implements Layer {
|
class LauncherGridLayer implements Layer {
|
||||||
// Watch swipes are spatial: up/down move between rows, left/right between
|
// Watch swipes are spatial: up/down move between rows, left/right between
|
||||||
// columns. From the leftmost column, left keeps going out: it leaves the
|
// columns. From the leftmost column, left keeps going out: it leaves the
|
||||||
@@ -87,12 +74,6 @@ class LauncherGridLayer implements Layer {
|
|||||||
readonly acceptsDirectional = true;
|
readonly acceptsDirectional = true;
|
||||||
/** Folder whose contents the grid is showing, or null for the top grid. */
|
/** Folder whose contents the grid is showing, or null for the top grid. */
|
||||||
private currentFolder: string | null = null;
|
private currentFolder: string | null = null;
|
||||||
private editingFolder = false;
|
|
||||||
private moving: { key: string; label: string; folder: string | null } | null = null;
|
|
||||||
|
|
||||||
private sortEntries(entries: LauncherGridEntry[]): LauncherGridEntry[] {
|
|
||||||
return orderLauncherEntries(entries, entryKey, this.currentFolder, launcherLayoutSetting.get() === "custom");
|
|
||||||
}
|
|
||||||
private readonly grid = new IconGrid<LauncherGridEntry>({
|
private readonly grid = new IconGrid<LauncherGridEntry>({
|
||||||
items: () => this.entries(),
|
items: () => this.entries(),
|
||||||
describe: (entry) => ({
|
describe: (entry) => ({
|
||||||
@@ -123,23 +104,25 @@ class LauncherGridLayer implements Layer {
|
|||||||
const members = (getFolders().get(this.currentFolder) ?? [])
|
const members = (getFolders().get(this.currentFolder) ?? [])
|
||||||
.map((appId) => byAppId.get(appId))
|
.map((appId) => byAppId.get(appId))
|
||||||
.filter(Boolean) as LauncherAppEntry[];
|
.filter(Boolean) as LauncherAppEntry[];
|
||||||
if (members.length > 0 || getExplicitFolderNames().includes(this.currentFolder)) {
|
if (members.length > 0) {
|
||||||
return this.sortEntries(members.map((app): LauncherGridEntry => ({
|
return members
|
||||||
|
.map((app): LauncherGridEntry => ({
|
||||||
kind: "app",
|
kind: "app",
|
||||||
label: app.label,
|
label: app.label,
|
||||||
icon: app.icon,
|
icon: app.icon,
|
||||||
appId: app.appId,
|
appId: app.appId,
|
||||||
renderIcon: app.renderIcon,
|
renderIcon: app.renderIcon,
|
||||||
})));
|
}))
|
||||||
|
.sort((a, b) => a.label.localeCompare(b.label));
|
||||||
}
|
}
|
||||||
this.currentFolder = null;
|
this.currentFolder = null;
|
||||||
}
|
}
|
||||||
const assignments = getFolderAssignments();
|
const assignments = getFolderAssignments();
|
||||||
const entries: LauncherGridEntry[] = [];
|
const entries: LauncherGridEntry[] = [];
|
||||||
// Legacy folders need a known member; explicitly created folders may be empty.
|
// A folder cell appears only when it holds at least one known app; stale
|
||||||
const explicit = new Set(getExplicitFolderNames());
|
// assignments to removed apps are ignored.
|
||||||
for (const [name, members] of getFolders()) {
|
for (const [name, members] of getFolders()) {
|
||||||
if (explicit.has(name) || members.some((appId) => byAppId.has(appId))) {
|
if (members.some((appId) => byAppId.has(appId))) {
|
||||||
entries.push({ kind: "folder", label: name, name });
|
entries.push({ kind: "folder", label: name, name });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +137,7 @@ class LauncherGridLayer implements Layer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.sortEntries(entries);
|
return entries.sort((a, b) => a.label.localeCompare(b.label));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Leave the current folder, putting the selection back on its cell. */
|
/** Leave the current folder, putting the selection back on its cell. */
|
||||||
@@ -168,16 +151,6 @@ class LauncherGridLayer implements Layer {
|
|||||||
|
|
||||||
/** Enter a folder or launch an app; true when that left the grid (a launch). */
|
/** Enter a folder or launch an app; true when that left the grid (a launch). */
|
||||||
private async openEntry(entry: LauncherGridEntry): Promise<boolean> {
|
private async openEntry(entry: LauncherGridEntry): Promise<boolean> {
|
||||||
if (this.moving) {
|
|
||||||
const moving = this.moving;
|
|
||||||
this.moving = null;
|
|
||||||
if (launcherLayoutSetting.get() === "custom" && moving.folder === this.currentFolder) {
|
|
||||||
moveLauncherEntry(this.currentFolder, this.entries().map(entryKey), moving.key, entryKey(entry));
|
|
||||||
const index = this.entries().findIndex(item => entryKey(item) === moving.key);
|
|
||||||
if (index >= 0) this.grid.selectIndex(index);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (entry.kind === "folder") {
|
if (entry.kind === "folder") {
|
||||||
this.currentFolder = entry.name;
|
this.currentFolder = entry.name;
|
||||||
this.grid.resetSelection();
|
this.grid.resetSelection();
|
||||||
@@ -193,13 +166,6 @@ class LauncherGridLayer implements Layer {
|
|||||||
|
|
||||||
/** Leave the open folder, else yield to the sidebar; true when that left the grid. */
|
/** Leave the open folder, else yield to the sidebar; true when that left the grid. */
|
||||||
private back(): boolean {
|
private back(): boolean {
|
||||||
if (this.moving) {
|
|
||||||
const key = this.moving.key;
|
|
||||||
this.moving = null;
|
|
||||||
const index = this.entries().findIndex(entry => entryKey(entry) === key);
|
|
||||||
if (index >= 0) this.grid.selectIndex(index);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.currentFolder !== null) {
|
if (this.currentFolder !== null) {
|
||||||
this.exitFolder();
|
this.exitFolder();
|
||||||
return false;
|
return false;
|
||||||
@@ -209,54 +175,14 @@ class LauncherGridLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Layout and folder creation are always available. Per-icon actions need
|
* App-specific entries for the window's context menu. Only item mode
|
||||||
* item mode so row navigation never edits an ambiguous selection.
|
* pins the selection to a single cell, and only apps can move to folders,
|
||||||
|
* so anywhere else the menu falls back to just the defaults.
|
||||||
*/
|
*/
|
||||||
menuItems(): MenuItem[] {
|
menuItems(): MenuItem[] {
|
||||||
if (this.editingFolder) return [];
|
|
||||||
const entry = this.grid.selectedItem;
|
const entry = this.grid.selectedItem;
|
||||||
const items: MenuItem[] = [
|
if (!entry || entry.kind !== "app") return [];
|
||||||
enumSettingMenuItem(launcherLayoutSetting, { onChange: () => { this.moving = null; this.grid.resetSelection(); } }),
|
return [
|
||||||
{
|
|
||||||
label: "New folder",
|
|
||||||
onSelect: ctx => {
|
|
||||||
const name = unusedNewFolderName();
|
|
||||||
if (createFolder(name)) {
|
|
||||||
this.currentFolder = null;
|
|
||||||
this.moving = null;
|
|
||||||
this.grid.resetSelection();
|
|
||||||
this.grid.selectIndex(this.entries().findIndex(item => item.kind === "folder" && item.name === name));
|
|
||||||
}
|
|
||||||
ctx.stack.pop();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const folder = entry?.kind === "folder" ? entry.name : this.currentFolder;
|
|
||||||
if (folder !== null) {
|
|
||||||
items.push({ label: "Rename folder", onSelect: ctx => this.editFolderName(folder, ctx) }, {
|
|
||||||
label: "Delete folder",
|
|
||||||
onSelect: ctx => {
|
|
||||||
ctx.stack.pop();
|
|
||||||
ctx.stack.push(new MenuLayer("Delete folder? Apps stay installed.", [
|
|
||||||
{ label: "Delete folder", onSelect: confirm => {
|
|
||||||
disbandFolder(folder);
|
|
||||||
if (this.currentFolder === folder) this.currentFolder = null;
|
|
||||||
this.moving = null;
|
|
||||||
this.grid.resetSelection();
|
|
||||||
confirm.stack.pop();
|
|
||||||
} },
|
|
||||||
{ label: "Cancel", onSelect: confirm => confirm.stack.pop() },
|
|
||||||
], WINDOW_MENU_LAYOUT));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (this.moving) items.push({ label: "Cancel move", onSelect: ctx => { this.back(); ctx.stack.pop(); } });
|
|
||||||
else if (entry && launcherLayoutSetting.get() === "custom") items.push({
|
|
||||||
label: "Move icon",
|
|
||||||
onSelect: ctx => { this.moving = { key: entryKey(entry), label: entry.label, folder: this.currentFolder }; ctx.stack.pop(); },
|
|
||||||
});
|
|
||||||
if (!entry || entry.kind !== "app") return items;
|
|
||||||
return [...items,
|
|
||||||
{
|
{
|
||||||
label: "Move to folder",
|
label: "Move to folder",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
@@ -295,32 +221,6 @@ class LauncherGridLayer implements Layer {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private editFolderName(folder: string, ctx: LayerContext): void {
|
|
||||||
ctx.stack.pop();
|
|
||||||
const setting = new ConfigSettingString({
|
|
||||||
id: "launcher-folder-name", label: "Folder name", storageKey: "launcher.folderNameDraft",
|
|
||||||
defaultValue: folder, normalize: value => value ?? "",
|
|
||||||
validate: value => folderNameError(value, folder), reportInAnalytics: false,
|
|
||||||
});
|
|
||||||
setting.set(folder);
|
|
||||||
this.editingFolder = true;
|
|
||||||
const editor = new FolderNameEditorLayer(setting, ctx.actions);
|
|
||||||
ctx.stack.push(editor);
|
|
||||||
void ctx.actions.startTextSettingsEdit([setting], "Rename folder", () => {
|
|
||||||
this.editingFolder = false;
|
|
||||||
if (renameFolder(folder, setting.get())) {
|
|
||||||
if (this.currentFolder === folder) this.currentFolder = setting.get().trim();
|
|
||||||
this.moving = null;
|
|
||||||
}
|
|
||||||
ctx.stack.popIfTop(layer => layer === editor);
|
|
||||||
ctx.actions.requestRender();
|
|
||||||
}, undefined, () => {
|
|
||||||
this.editingFolder = false;
|
|
||||||
ctx.stack.popIfTop(layer => layer === editor);
|
|
||||||
ctx.actions.requestRender();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The folder-picker submenu: every existing folder except the app's own,
|
* The folder-picker submenu: every existing folder except the app's own,
|
||||||
* plus a generated-name "New folder" (ring input has no text entry) and,
|
* plus a generated-name "New folder" (ring input has no text entry) and,
|
||||||
@@ -342,9 +242,7 @@ class LauncherGridLayer implements Layer {
|
|||||||
items.push({
|
items.push({
|
||||||
label: "New folder",
|
label: "New folder",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
const name = unusedNewFolderName();
|
setAppFolder(appId, unusedNewFolderName());
|
||||||
createFolder(name);
|
|
||||||
setAppFolder(appId, name);
|
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -365,16 +263,8 @@ class LauncherGridLayer implements Layer {
|
|||||||
const { width, height } = ctx.stack.getBaseSize();
|
const { width, height } = ctx.stack.getBaseSize();
|
||||||
const image = new GrayImage(width, height, 0);
|
const image = new GrayImage(width, height, 0);
|
||||||
// The folder-name header band scales with the font.
|
// The folder-name header band scales with the font.
|
||||||
const entries = this.entries();
|
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : ROOT_GRID_TOP;
|
||||||
if (this.moving && (launcherLayoutSetting.get() !== "custom" || this.moving.folder !== this.currentFolder ||
|
if (this.currentFolder !== null) {
|
||||||
!entries.some(entry => entryKey(entry) === this.moving!.key))) this.moving = null;
|
|
||||||
const gridTop = this.moving ? GRID_TOP + 2 * (font.lineHeight + 2)
|
|
||||||
: this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : ROOT_GRID_TOP;
|
|
||||||
if (this.moving) {
|
|
||||||
image.drawText(font, 8, GRID_TOP - 2, truncateText(font, `Move ${this.moving.label}`, width - 16), 220);
|
|
||||||
image.drawText(font, 8, GRID_TOP + font.lineHeight, "Select position; double tap cancels", 160);
|
|
||||||
}
|
|
||||||
if (this.currentFolder !== null && !this.moving) {
|
|
||||||
image.drawText(font, 8, GRID_TOP - 2, truncateText(font, this.currentFolder, width - 16), 160);
|
image.drawText(font, 8, GRID_TOP - 2, truncateText(font, this.currentFolder, width - 16), 160);
|
||||||
}
|
}
|
||||||
// The grid runs to the window's bottom edge, so a row cut off there for
|
// The grid runs to the window's bottom edge, so a row cut off there for
|
||||||
@@ -384,7 +274,6 @@ class LauncherGridLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
if (this.moving && event.type === "double-click") { this.back(); return; }
|
|
||||||
await this.grid.handleInput(event, ctx);
|
await this.grid.handleInput(event, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,9 +311,9 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
|
|||||||
// keeps every unrelated setting change from repainting the launcher. The
|
// keeps every unrelated setting change from repainting the launcher. The
|
||||||
// launcher is pinned for the app's lifetime, so the subscription never needs
|
// launcher is pinned for the app's lifetime, so the subscription never needs
|
||||||
// tearing down.
|
// tearing down.
|
||||||
let lastState = `${getFolderStateFingerprint()}\n${getLauncherLayoutFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
let lastState = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||||
onAnySettingChanged(() => {
|
onAnySettingChanged(() => {
|
||||||
const state = `${getFolderStateFingerprint()}\n${getLauncherLayoutFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
const state = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||||
if (state === lastState) return;
|
if (state === lastState) return;
|
||||||
lastState = state;
|
lastState = state;
|
||||||
created.requestRender();
|
created.requestRender();
|
||||||
|
|||||||
@@ -1,50 +1,14 @@
|
|||||||
/** Launcher assignments keep their legacy format; explicitly created folders may be empty. */
|
/**
|
||||||
|
* Launcher folder state: which apps are grouped into which named folder.
|
||||||
|
* Stored as one JSON string (appId -> folder name) in the settings store, so
|
||||||
|
* it persists and its changes broadcast to every isolate. An unset value means
|
||||||
|
* the default grouping; any edit persists the whole map, so clearing out the
|
||||||
|
* defaults sticks. Folders exist only while at least one app is assigned to
|
||||||
|
* them — there is no separate create/delete step.
|
||||||
|
*/
|
||||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||||
|
|
||||||
import { renameLauncherFolderOrder, removeLauncherFolderOrder } from "./launcher-layout";
|
|
||||||
|
|
||||||
const STORAGE_KEY = "launcher.folders";
|
const STORAGE_KEY = "launcher.folders";
|
||||||
const NAMES_KEY = "launcher.folderNames";
|
|
||||||
|
|
||||||
/** Only user-created/renamed folders persist after their last member leaves. */
|
|
||||||
export function getExplicitFolderNames(): string[] {
|
|
||||||
try {
|
|
||||||
const value = JSON.parse(getStringSetting(NAMES_KEY, "[]"));
|
|
||||||
return Array.isArray(value) ? [...new Set(value.filter((name): name is string =>
|
|
||||||
typeof name === "string" && !!name.trim()).map(name => name.trim()))] : [];
|
|
||||||
} catch { return []; }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function folderNameError(input: string, previous?: string): string | null {
|
|
||||||
const name = input.trim();
|
|
||||||
if (!name) return "Enter a folder name.";
|
|
||||||
if (name.length > FOLDER_NAME_MAX_LENGTH) return `Use at most ${FOLDER_NAME_MAX_LENGTH} characters.`;
|
|
||||||
if (/[\u0000-\u001f\u007f]/.test(name)) return "Use a single-line folder name.";
|
|
||||||
if (previous !== undefined && !getFolders().has(previous)) return "This folder no longer exists.";
|
|
||||||
for (const existing of getFolders().keys()) {
|
|
||||||
if (existing !== previous && existing.toLowerCase() === name.toLowerCase()) return "A folder with this name already exists.";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createFolder(input: string): boolean {
|
|
||||||
if (folderNameError(input)) return false;
|
|
||||||
setStringSetting(NAMES_KEY, JSON.stringify([...getExplicitFolderNames(), input.trim()]));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function renameFolder(previous: string, input: string): boolean {
|
|
||||||
if (folderNameError(input, previous)) return false;
|
|
||||||
const name = input.trim();
|
|
||||||
if (name === previous) return true;
|
|
||||||
const assignments = getFolderAssignments();
|
|
||||||
for (const appId of Object.keys(assignments)) if (assignments[appId] === previous) assignments[appId] = name;
|
|
||||||
// Preserve position and per-folder order when the visible name changes.
|
|
||||||
renameLauncherFolderOrder(previous, name);
|
|
||||||
setStringSetting(NAMES_KEY, JSON.stringify([...getExplicitFolderNames().filter(n => n !== previous), name]));
|
|
||||||
setStringSetting(STORAGE_KEY, JSON.stringify(assignments));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The out-of-the-box grouping, applied only while the setting is unset. */
|
/** The out-of-the-box grouping, applied only while the setting is unset. */
|
||||||
const DEFAULT_ASSIGNMENTS: Record<string, string> = {
|
const DEFAULT_ASSIGNMENTS: Record<string, string> = {
|
||||||
@@ -68,7 +32,7 @@ export function getFolderAssignments(): Record<string, string> {
|
|||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(raw);
|
const parsed = JSON.parse(raw);
|
||||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
||||||
const assignments: Record<string, string> = Object.create(null);
|
const assignments: Record<string, string> = {};
|
||||||
for (const appId of Object.keys(parsed)) {
|
for (const appId of Object.keys(parsed)) {
|
||||||
const folder = parsed[appId];
|
const folder = parsed[appId];
|
||||||
if (typeof folder === "string" && folder.trim()) {
|
if (typeof folder === "string" && folder.trim()) {
|
||||||
@@ -94,7 +58,6 @@ export function getFolders(): Map<string, string[]> {
|
|||||||
unsorted.set(folder, [appId]);
|
unsorted.set(folder, [appId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const name of getExplicitFolderNames()) if (!unsorted.has(name)) unsorted.set(name, []);
|
|
||||||
const folders = new Map<string, string[]>();
|
const folders = new Map<string, string[]>();
|
||||||
for (const name of Array.from(unsorted.keys()).sort((a, b) => a.localeCompare(b))) {
|
for (const name of Array.from(unsorted.keys()).sort((a, b) => a.localeCompare(b))) {
|
||||||
folders.set(name, unsorted.get(name)!);
|
folders.set(name, unsorted.get(name)!);
|
||||||
@@ -123,8 +86,6 @@ export function disbandFolder(folder: string): number {
|
|||||||
moved++;
|
moved++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setStringSetting(NAMES_KEY, JSON.stringify(getExplicitFolderNames().filter(name => name !== folder)));
|
|
||||||
removeLauncherFolderOrder(folder);
|
|
||||||
if (moved > 0) {
|
if (moved > 0) {
|
||||||
setStringSetting(STORAGE_KEY, JSON.stringify(assignments));
|
setStringSetting(STORAGE_KEY, JSON.stringify(assignments));
|
||||||
}
|
}
|
||||||
@@ -134,7 +95,7 @@ export function disbandFolder(folder: string): number {
|
|||||||
/**
|
/**
|
||||||
* An unused name for a ring-created folder ("New folder", "New folder 2", …).
|
* An unused name for a ring-created folder ("New folder", "New folder 2", …).
|
||||||
* Ring input has no text entry, so new folders start with a generated name;
|
* Ring input has no text entry, so new folders start with a generated name;
|
||||||
* Rename folder uses the existing phone text editor for a custom name.
|
* the assistant's folder tools can regroup the apps under a better one.
|
||||||
*/
|
*/
|
||||||
export function unusedNewFolderName(): string {
|
export function unusedNewFolderName(): string {
|
||||||
const existing = new Set(Array.from(getFolders().keys()).map((name) => name.toLowerCase()));
|
const existing = new Set(Array.from(getFolders().keys()).map((name) => name.toLowerCase()));
|
||||||
@@ -158,6 +119,5 @@ export function resolveFolderName(input: string): string {
|
|||||||
|
|
||||||
/** Raw stored value, for cheap change detection by the launcher window. */
|
/** Raw stored value, for cheap change detection by the launcher window. */
|
||||||
export function getFolderStateFingerprint(): string {
|
export function getFolderStateFingerprint(): string {
|
||||||
return JSON.stringify([getStringSetting(STORAGE_KEY, ""), getStringSetting(NAMES_KEY, ""),
|
return getStringSetting(STORAGE_KEY, "");
|
||||||
getStringSetting("launcher.folderNameDraft", "")]);
|
|
||||||
}
|
}
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
|
||||||
|
|
||||||
const ORDER_KEY = "launcher.order";
|
|
||||||
const scopeKey = (folder: string | null) => folder === null ? "root" : `folder:${folder}`;
|
|
||||||
|
|
||||||
function readOrders(): Record<string, string[]> {
|
|
||||||
try {
|
|
||||||
const value = JSON.parse(getStringSetting(ORDER_KEY, "{}"));
|
|
||||||
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
||||||
return Object.fromEntries(Object.entries(value).filter(([, order]) => Array.isArray(order))
|
|
||||||
.map(([scope, order]) => [scope, [...new Set((order as unknown[]).filter((id): id is string => typeof id === "string"))]]));
|
|
||||||
} catch { return {}; }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setLauncherOrder(folder: string | null, ids: readonly string[]): void {
|
|
||||||
const orders = readOrders();
|
|
||||||
orders[scopeKey(folder)] = [...new Set(ids)];
|
|
||||||
setStringSetting(ORDER_KEY, JSON.stringify(orders));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Unseen apps append alphabetically; changing sort modes never destroys saved order. */
|
|
||||||
export function orderLauncherEntries<T extends { label: string }>(
|
|
||||||
entries: T[], key: (entry: T) => string, folder: string | null, custom: boolean,
|
|
||||||
): T[] {
|
|
||||||
const order = custom ? readOrders()[scopeKey(folder)] ?? [] : [];
|
|
||||||
const rank = new Map(order.map((id, index) => [id, index]));
|
|
||||||
return entries.sort((a, b) => (rank.get(key(a)) ?? Infinity) - (rank.get(key(b)) ?? Infinity) ||
|
|
||||||
a.label.localeCompare(b.label) || key(a).localeCompare(key(b)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Move into the target's position, without moving apps across folders. */
|
|
||||||
export function moveLauncherEntry(folder: string | null, ids: string[], source: string, target: string): boolean {
|
|
||||||
const from = ids.indexOf(source), to = ids.indexOf(target);
|
|
||||||
if (from < 0 || to < 0) return false;
|
|
||||||
const next = ids.slice();
|
|
||||||
next.splice(from, 1);
|
|
||||||
next.splice(to, 0, source);
|
|
||||||
setLauncherOrder(folder, next);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function renameLauncherFolderOrder(previous: string, next: string): void {
|
|
||||||
const orders = readOrders();
|
|
||||||
const oldScope = scopeKey(previous), newScope = scopeKey(next);
|
|
||||||
if (orders[oldScope]) orders[newScope] = orders[oldScope];
|
|
||||||
delete orders[oldScope];
|
|
||||||
if (orders.root) orders.root = orders.root.map(id => id === `folder:${previous}` ? `folder:${next}` : id);
|
|
||||||
setStringSetting(ORDER_KEY, JSON.stringify(orders));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function removeLauncherFolderOrder(folder: string): void {
|
|
||||||
const orders = readOrders();
|
|
||||||
delete orders[scopeKey(folder)];
|
|
||||||
if (orders.root) orders.root = orders.root.filter(id => id !== `folder:${folder}`);
|
|
||||||
setStringSetting(ORDER_KEY, JSON.stringify(orders));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getLauncherLayoutFingerprint(): string {
|
|
||||||
return JSON.stringify([getStringSetting("launcher.layout", "alphabetical"), getStringSetting(ORDER_KEY, "")]);
|
|
||||||
}
|
|
||||||
@@ -191,7 +191,7 @@ function registerTools(options: WindowToolsOptions, registry: ToolRegistry): voi
|
|||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
for (const [name, members] of getFolders()) {
|
for (const [name, members] of getFolders()) {
|
||||||
const known = members.filter((appId) => appIds.indexOf(appId) >= 0).sort();
|
const known = members.filter((appId) => appIds.indexOf(appId) >= 0).sort();
|
||||||
if (known.length || members.length === 0) lines.push(`${name}: ${known.length ? known.map(describeApp).join(", ") : "(empty)"}`);
|
if (known.length) lines.push(`${name}: ${known.map(describeApp).join(", ")}`);
|
||||||
}
|
}
|
||||||
const assignments = getFolderAssignments();
|
const assignments = getFolderAssignments();
|
||||||
const ungrouped = appIds.filter((appId) => !assignments[appId]);
|
const ungrouped = appIds.filter((appId) => !assignments[appId]);
|
||||||
@@ -237,7 +237,7 @@ function registerTools(options: WindowToolsOptions, registry: ToolRegistry): voi
|
|||||||
{
|
{
|
||||||
name: "apps.remove_from_folder",
|
name: "apps.remove_from_folder",
|
||||||
description:
|
description:
|
||||||
"Move an app out of its launcher folder back to the top-level grid. Default folders disappear when their last app is removed; user-created folders can stay empty.",
|
"Move an app out of its launcher folder back to the top-level grid. A folder disappears when its last app is removed.",
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
@@ -276,9 +276,8 @@ function registerTools(options: WindowToolsOptions, registry: ToolRegistry): voi
|
|||||||
(args) => {
|
(args) => {
|
||||||
const folder = resolveFolderName(String(args?.folder ?? ""));
|
const folder = resolveFolderName(String(args?.folder ?? ""));
|
||||||
if (!folder) return err("folder must be a non-empty name");
|
if (!folder) return err("folder must be a non-empty name");
|
||||||
const existed = getFolders().has(folder);
|
|
||||||
const moved = disbandFolder(folder);
|
const moved = disbandFolder(folder);
|
||||||
if (moved === 0 && !existed) {
|
if (moved === 0) {
|
||||||
const names = Array.from(getFolders().keys());
|
const names = Array.from(getFolders().keys());
|
||||||
return err(
|
return err(
|
||||||
names.length
|
names.length
|
||||||
|
|||||||
@@ -451,6 +451,8 @@ class DashboardController {
|
|||||||
openNotificationsWindow: () =>
|
openNotificationsWindow: () =>
|
||||||
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow),
|
this.openInProcessAppInBackground(NOTIFICATIONS_WINDOW_ID, NOTIFICATIONS_SURFACE_ID, createNotificationsAppWindow),
|
||||||
onSwitcherBarHeightChanged: () => this.applySwitcherBarHeight(),
|
onSwitcherBarHeightChanged: () => this.applySwitcherBarHeight(),
|
||||||
|
onWindowLayoutChanged: () => this.applySwitcherBarHeight(),
|
||||||
|
isLocked: () => this.glassesLocked,
|
||||||
onScreenStateChanged: (on) => {
|
onScreenStateChanged: (on) => {
|
||||||
// Any wake of the regular UI replaces a showing Glanceboard.
|
// Any wake of the regular UI replaces a showing Glanceboard.
|
||||||
if (on) this.glance.dismiss();
|
if (on) this.glance.dismiss();
|
||||||
|
|||||||
@@ -221,6 +221,12 @@ export class IosPreviewController {
|
|||||||
shell.foregroundWindow()?.requestRender()
|
shell.foregroundWindow()?.requestRender()
|
||||||
this.requestShellRender()
|
this.requestShellRender()
|
||||||
},
|
},
|
||||||
|
onWindowLayoutChanged: () => {
|
||||||
|
this.relayout()
|
||||||
|
shell.foregroundWindow()?.requestRender()
|
||||||
|
this.requestShellRender()
|
||||||
|
},
|
||||||
|
isLocked: () => this.glassesLocked,
|
||||||
onScreenStateChanged: on => {
|
onScreenStateChanged: on => {
|
||||||
if (on) this.glance.dismiss()
|
if (on) this.glance.dismiss()
|
||||||
// A wake unblanks only once the next shell render has staged an awake
|
// A wake unblanks only once the next shell render has staged an awake
|
||||||
|
|||||||
@@ -148,6 +148,39 @@ export class ConfigSettingBoolean<TId extends string = string> extends ConfigSet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const appFullscreenSettings = new Map<string, ConfigSettingBoolean>();
|
||||||
|
|
||||||
|
/** A user choice independent of an app's own temporary immersive mode. */
|
||||||
|
export function appFullscreenSetting(appId: string): ConfigSettingBoolean {
|
||||||
|
let setting = appFullscreenSettings.get(appId);
|
||||||
|
if (!setting) {
|
||||||
|
setting = new ConfigSettingBoolean({
|
||||||
|
id: `app-fullscreen-${appId}`, label: "Full screen",
|
||||||
|
storageKey: `display.fullscreen.${appId}`, defaultValue: false,
|
||||||
|
reportInAnalytics: false,
|
||||||
|
});
|
||||||
|
appFullscreenSettings.set(appId, setting);
|
||||||
|
}
|
||||||
|
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> & {
|
type ConfigSettingEnumOptions<TValue extends string, TId extends string> = ConfigSettingOptions<TValue, TId> & {
|
||||||
values: readonly TValue[];
|
values: readonly TValue[];
|
||||||
normalize?: (value: string | null | undefined) => TValue;
|
normalize?: (value: string | null | undefined) => TValue;
|
||||||
@@ -200,13 +233,6 @@ export class ConfigSettingEnum<TValue extends string, TId extends string = strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const launcherLayoutSetting = new ConfigSettingEnum({
|
|
||||||
id: "launcher-layout", label: "Layout", storageKey: "launcher.layout",
|
|
||||||
defaultValue: "alphabetical", values: ["alphabetical", "custom"] as const,
|
|
||||||
formatValue: value => value === "custom" ? "Custom" : "Alphabetical",
|
|
||||||
description: "Sort apps and folders alphabetically, or arrange icons yourself. Custom positions are remembered when switching layouts.",
|
|
||||||
});
|
|
||||||
|
|
||||||
type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<string, TId> & {
|
type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<string, TId> & {
|
||||||
editorTitle?: string;
|
editorTitle?: string;
|
||||||
glassesEditTitle?: string;
|
glassesEditTitle?: string;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
|
||||||
import {
|
import {
|
||||||
appSwitcherPositionSetting,
|
appSwitcherPositionSetting,
|
||||||
|
appFullscreenSetting,
|
||||||
type AppSwitcherPosition,
|
type AppSwitcherPosition,
|
||||||
displayLayoutSetting,
|
displayLayoutSetting,
|
||||||
type DisplayLayout,
|
type DisplayLayout,
|
||||||
@@ -118,7 +119,7 @@ export function setAppImmersive(appId: string, immersive: boolean): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isImmersive(appId?: string): boolean {
|
export function isImmersive(appId?: string): boolean {
|
||||||
return appId !== undefined && immersiveApps.has(appId);
|
return appId !== undefined && (immersiveApps.has(appId) || appFullscreenSetting(appId).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether an app's windows span the panel's whole width: Full Screen, or immersive. */
|
/** Whether an app's windows span the panel's whole width: Full Screen, or immersive. */
|
||||||
|
|||||||
+63
-58
@@ -31,6 +31,9 @@ import type { AssistantContext } from "../../assistant/types";
|
|||||||
import { SingleNotificationLayer } from "../notifications";
|
import { SingleNotificationLayer } from "../notifications";
|
||||||
import {
|
import {
|
||||||
anthropicApiKeySetting,
|
anthropicApiKeySetting,
|
||||||
|
appFullscreenSetting,
|
||||||
|
appKeepAwakeSetting,
|
||||||
|
toggleSettingMenuItem,
|
||||||
assistantHermesKeySetting,
|
assistantHermesKeySetting,
|
||||||
assistantHermesUrlSetting,
|
assistantHermesUrlSetting,
|
||||||
assistantBackendSetting,
|
assistantBackendSetting,
|
||||||
@@ -94,7 +97,8 @@ import type { AppSwitcherPosition } from "../dashboard-settings";
|
|||||||
* Input flow: every event enters via receiveInput. The shell consumes
|
* Input flow: every event enters via receiveInput. The shell consumes
|
||||||
* everything while the sidebar or a shell overlay has focus and forwards the
|
* everything while the sidebar or a shell overlay has focus and forwards the
|
||||||
* rest to the focused window. Long-press opens the shell-owned system menu
|
* rest to the focused window. Long-press opens the shell-owned system menu
|
||||||
* (Focus app switcher, Voice input, Brightness, Close window, Debug) without reaching the
|
* (Focus app switcher, Voice input, Brightness, Close current app, Close all apps,
|
||||||
|
* Debug) without reaching the
|
||||||
* app, so the shell keeps working when a window's handler hangs; a window
|
* app, so the shell keeps working when a window's handler hangs; a window
|
||||||
* that claims long-press for a move of its own gets it forwarded instead, and
|
* that claims long-press for a move of its own gets it forwarded instead, and
|
||||||
* holding the press past the escape threshold still opens the system menu.
|
* holding the press past the escape threshold still opens the system menu.
|
||||||
@@ -109,7 +113,7 @@ export type ShellWindow = {
|
|||||||
title: string;
|
title: string;
|
||||||
/** Compositor surface this window renders to; configured at connect / launch. */
|
/** Compositor surface this window renders to; configured at connect / launch. */
|
||||||
surfaceId: string;
|
surfaceId: string;
|
||||||
/** Whether the system menu offers Close window (the launcher is pinned). */
|
/** Whether the system menu can close this window (the launcher is pinned). */
|
||||||
closeable: boolean;
|
closeable: boolean;
|
||||||
/**
|
/**
|
||||||
* True when tap-then-hold currently opens the window's own context menu
|
* True when tap-then-hold currently opens the window's own context menu
|
||||||
@@ -222,6 +226,10 @@ export type ShellConfig = {
|
|||||||
* after the shell paint that found it.
|
* after the shell paint that found it.
|
||||||
*/
|
*/
|
||||||
onSwitcherBarHeightChanged?: () => void;
|
onSwitcherBarHeightChanged?: () => void;
|
||||||
|
/** A per-app full-screen choice changed the viewport and compositor geometry. */
|
||||||
|
onWindowLayoutChanged?: () => void;
|
||||||
|
/** 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
|
* The Notifications app's window, opened in the background (neither
|
||||||
* foregrounded nor focused) unless it is open already, for the switcher
|
* foregrounded nor focused) unless it is open already, for the switcher
|
||||||
@@ -326,7 +334,7 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
|||||||
*/
|
*/
|
||||||
keepWindowFocus = false;
|
keepWindowFocus = false;
|
||||||
|
|
||||||
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void, title = "System") {
|
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void) {
|
||||||
// Aligned to the min-height window band (like the sidebar), wherever the
|
// Aligned to the min-height window band (like the sidebar), wherever the
|
||||||
// vertical position setting currently puts it; centered over the
|
// vertical position setting currently puts it; centered over the
|
||||||
// application area, i.e. the part of the screen beside a side strip
|
// application area, i.e. the part of the screen beside a side strip
|
||||||
@@ -334,7 +342,7 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
|||||||
// the strip overlays).
|
// the strip overlays).
|
||||||
const width = 272;
|
const width = 272;
|
||||||
const area = appViewportRect("min");
|
const area = appViewportRect("min");
|
||||||
super(title, items, {
|
super("System", items, {
|
||||||
x: area.x + (((area.width - width) / 2) | 0),
|
x: area.x + (((area.width - width) / 2) | 0),
|
||||||
y: area.y + 8,
|
y: area.y + 8,
|
||||||
width,
|
width,
|
||||||
@@ -655,6 +663,12 @@ class Shell {
|
|||||||
if (window) this.closeWindow(window.windowId);
|
if (window) this.closeWindow(window.windowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Snapshot ids: close callbacks may remove themselves or other windows. */
|
||||||
|
closeAllWindows(): void {
|
||||||
|
const ids = this.windows.filter(window => window.closeable).map(window => window.windowId);
|
||||||
|
for (const id of ids) this.closeWindow(id);
|
||||||
|
}
|
||||||
|
|
||||||
getWindows(): readonly ShellWindow[] {
|
getWindows(): readonly ShellWindow[] {
|
||||||
return this.windows;
|
return this.windows;
|
||||||
}
|
}
|
||||||
@@ -866,7 +880,9 @@ class Shell {
|
|||||||
// A foreground window that is playing video holds it off the same way.
|
// A foreground window that is playing video holds it off the same way.
|
||||||
const foreground = this.foregroundWindow();
|
const foreground = this.foregroundWindow();
|
||||||
if (this.activeVoiceLayer || this.activeKeyboardLayer || this.assistantSession?.isTurnActive() ||
|
if (this.activeVoiceLayer || this.activeKeyboardLayer || this.assistantSession?.isTurnActive() ||
|
||||||
foreground?.isVoiceCapturing?.() || foreground?.keepsScreenOn?.()) {
|
foreground?.isVoiceCapturing?.() || foreground?.keepsScreenOn?.() ||
|
||||||
|
(foreground?.closeable && !this.config.isLocked?.() &&
|
||||||
|
appKeepAwakeSetting(foreground.appId).get())) {
|
||||||
this.lastInputAtMs = nowMs;
|
this.lastInputAtMs = nowMs;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1073,6 +1089,12 @@ class Shell {
|
|||||||
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
|
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
|
||||||
return { shell: true, window: false };
|
return { shell: true, window: false };
|
||||||
}
|
}
|
||||||
|
// The switcher owns its menu even when the selected app uses a hold
|
||||||
|
// for a game move or voice capture.
|
||||||
|
if (this.focus === "sidebar") {
|
||||||
|
this.openEscapeMenu();
|
||||||
|
return { shell: true, window: false };
|
||||||
|
}
|
||||||
const window = this.foregroundWindow();
|
const window = this.foregroundWindow();
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return { shell: true, window: false };
|
return { shell: true, window: false };
|
||||||
@@ -1082,10 +1104,6 @@ class Shell {
|
|||||||
return { shell: true, window: false };
|
return { shell: true, window: false };
|
||||||
}
|
}
|
||||||
if (!window.holdToTalk) this.startEscapeMenuTimer();
|
if (!window.holdToTalk) this.startEscapeMenuTimer();
|
||||||
if (this.focus === "sidebar") {
|
|
||||||
this.focus = "window";
|
|
||||||
window.onFocus?.(this.lastInput);
|
|
||||||
}
|
|
||||||
// The window owns frameId from here (render or explicit finish).
|
// The window owns frameId from here (render or explicit finish).
|
||||||
await window.handleInput(event, frameId);
|
await window.handleInput(event, frameId);
|
||||||
return { shell: true, window: true };
|
return { shell: true, window: true };
|
||||||
@@ -1096,6 +1114,10 @@ class Shell {
|
|||||||
// first), which answers with its own menu or asks for the system menu
|
// first), which answers with its own menu or asks for the system menu
|
||||||
// when it has none.
|
// when it has none.
|
||||||
if (event.type === "short-then-long-press") {
|
if (event.type === "short-then-long-press") {
|
||||||
|
if (this.focus === "sidebar" && !this.activeVoiceLayer && this.stack.isAtBase()) {
|
||||||
|
this.openEscapeMenu();
|
||||||
|
return { shell: true, window: false };
|
||||||
|
}
|
||||||
const window = this.foregroundWindow();
|
const window = this.foregroundWindow();
|
||||||
if (window?.holdToTalk) {
|
if (window?.holdToTalk) {
|
||||||
this.openEscapeMenu();
|
this.openEscapeMenu();
|
||||||
@@ -1304,43 +1326,6 @@ class Shell {
|
|||||||
return hidden ? this.windows.filter((window) => window !== hidden) : this.windows;
|
return hidden ? this.windows.filter((window) => window !== hidden) : this.windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reorder visible app windows while keeping pinned/temporary slots and foreground stable. */
|
|
||||||
private moveSwitcherWindow(windowId: string, targetId: string): boolean {
|
|
||||||
const movable = this.switcherWindows().filter(window => window.closeable);
|
|
||||||
const from = movable.findIndex(window => window.windowId === windowId);
|
|
||||||
const to = movable.findIndex(window => window.windowId === targetId);
|
|
||||||
if (from < 0 || to < 0 || from === to) return false;
|
|
||||||
const foreground = this.foregroundWindow();
|
|
||||||
const ids = new Set(movable.map(window => window.windowId));
|
|
||||||
const [moved] = movable.splice(from, 1);
|
|
||||||
movable.splice(to, 0, moved!);
|
|
||||||
let index = 0;
|
|
||||||
this.windows = this.windows.map(window => ids.has(window.windowId) ? movable[index++]! : window);
|
|
||||||
if (foreground) this.selectedIndex = this.windows.indexOf(foreground);
|
|
||||||
this.config.onWindowsChanged?.();
|
|
||||||
this.config.requestShellRender();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Capture window IDs: changing titles or closing windows cannot redirect a pending move. */
|
|
||||||
private openSwitcherMoveMenu(windowId: string): void {
|
|
||||||
if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return;
|
|
||||||
const movable = this.switcherWindows().filter(window => window.closeable);
|
|
||||||
const selected = movable.findIndex(window => window.windowId === windowId);
|
|
||||||
if (selected < 0 || movable.length < 2) return;
|
|
||||||
const items: MenuItem[] = movable.map((window, index) => ({
|
|
||||||
label: `${index + 1}. ${window.title}`,
|
|
||||||
onSelect: ctx => {
|
|
||||||
ctx.stack.pop();
|
|
||||||
this.moveSwitcherWindow(windowId, window.windowId);
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
const layer = new ShellOverlayMenuLayer(items, undefined, () => this.yieldFocusToSidebar(), "Move app to position");
|
|
||||||
layer.selectItem(selected);
|
|
||||||
this.stack.push(layer);
|
|
||||||
this.config.requestShellRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The status bar items the switcher's selection can move onto, in order:
|
* The status bar items the switcher's selection can move onto, in order:
|
||||||
* with a bottom switcher (the selection reaches them past the last
|
* with a bottom switcher (the selection reaches them past the last
|
||||||
@@ -1950,7 +1935,7 @@ class Shell {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The system/escape menu: the entries every window shares (Focus app
|
* The system/escape menu: the entries every window shares (Focus app
|
||||||
* switcher, Voice input, Brightness, Close window) plus Debug. Shell-owned and
|
* switcher, Voice input, Brightness, Close current app, Close all apps) plus Debug. Shell-owned and
|
||||||
* shell-drawn (never the app's), so an unresponsive app can always be
|
* shell-drawn (never the app's), so an unresponsive app can always be
|
||||||
* closed. It opens for long-press (over the app's own menu too), after an
|
* closed. It opens for long-press (over the app's own menu too), after an
|
||||||
* extended hold in a window that claims long-press, and on a window's
|
* extended hold in a window that claims long-press, and on a window's
|
||||||
@@ -1963,18 +1948,17 @@ class Shell {
|
|||||||
const items: MenuItem[] = [];
|
const items: MenuItem[] = [];
|
||||||
if (foreground.closeable) {
|
if (foreground.closeable) {
|
||||||
items.push({
|
items.push({
|
||||||
label: "Close window",
|
label: "Close current app",
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
// Pop the menu first (its onRemoved returns focus to the sidebar),
|
// Pop the menu first (its onRemoved returns focus to the sidebar),
|
||||||
// then close the window the menu was opened over.
|
// then close the window the menu was opened over.
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
this.closeForegroundWindow();
|
this.closeWindow(foreground.windowId);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Close window sits first but the menu opens on Focus app switcher, so a
|
// Prefer closing the current app; pinned windows fall back to the switcher.
|
||||||
// reflexive tap never closes the window.
|
const initialSelection = 0;
|
||||||
const initialSelection = items.length;
|
|
||||||
items.push(
|
items.push(
|
||||||
{
|
{
|
||||||
// Defocus the app (hand focus to the sidebar) without closing it: the
|
// Defocus the app (hand focus to the sidebar) without closing it: the
|
||||||
@@ -1996,16 +1980,37 @@ class Shell {
|
|||||||
},
|
},
|
||||||
}]),
|
}]),
|
||||||
);
|
);
|
||||||
const movableWindows = this.switcherWindows().filter(window => window.closeable);
|
|
||||||
if (movableWindows.length > 1 && movableWindows.includes(foreground)) {
|
|
||||||
items.push({
|
items.push({
|
||||||
label: "Move in app switcher",
|
label: "Close all apps",
|
||||||
description: "Choose this open window's position in the app switcher.",
|
disabled: () => !this.windows.some(window => window.closeable),
|
||||||
onSelect: ctx => {
|
onSelect: (ctx) => {
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
this.openSwitcherMoveMenu(foreground.windowId);
|
this.closeAllWindows();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (foreground.closeable) {
|
||||||
|
const fullscreen = appFullscreenSetting(foreground.appId);
|
||||||
|
items.push({
|
||||||
|
label: fullscreen.get() ? "Exit full screen" : "Enter full screen",
|
||||||
|
description: "Use the whole display for this app.",
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
if (!this.windows.some(window => window.windowId === foreground.windowId)) return;
|
||||||
|
fullscreen.set(!fullscreen.get());
|
||||||
|
this.noteUserActivity();
|
||||||
|
this.config.onWindowLayoutChanged?.();
|
||||||
|
this.focusWindow(foreground.windowId);
|
||||||
|
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") {
|
if (brightnessSetting.get() !== "auto") {
|
||||||
items.push({
|
items.push({
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import type { WorkerAppReply } from "./shell/worker-window";
|
|||||||
* The window context menu, opened by tap-then-hold: an app's own menu,
|
* The window context menu, opened by tap-then-hold: an app's own menu,
|
||||||
* holding its app-specific actions. The shell's system menu (long-press)
|
* holding its app-specific actions. The shell's system menu (long-press)
|
||||||
* carries the entries every window shares — Focus app switcher, Voice input,
|
* carries the entries every window shares — Focus app switcher, Voice input,
|
||||||
* Close window — so an app with nothing of its own to offer has no menu of
|
* Close current app, Close all apps — so an app with nothing of its own to offer has no menu of
|
||||||
* its own: tap-then-hold then opens the system menu in its place, so both
|
* its own: tap-then-hold then opens the system menu in its place, so both
|
||||||
* gestures land on the same menu. The system menu is also the safety net:
|
* gestures land on the same menu. The system menu is also the safety net:
|
||||||
* shell-owned, so an unresponsive app can always be closed (a window that
|
* shell-owned, so an unresponsive app can always be closed (a window that
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# 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,
|
||||||
|
independently of global display layout and app-controlled immersive mode.
|
||||||
|
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.
|
||||||
|
|
||||||
|
Stock EvenHub apps retain their logical 576x288 canvas in every host display
|
||||||
|
mode, including full screen. Content is centered at native pixel scale and
|
||||||
|
clipped to that canvas; extra space does not change wrapping or layout.
|
||||||
|
Only an app's explicit Faceclaw extended-layout request enables a taller canvas.
|
||||||
|
Regression tests compare the complete stock raster against its centered
|
||||||
|
full-screen placement, including text crossing the logical canvas boundary.
|
||||||
|
|
||||||
|
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, 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,
|
||||||
|
and reconnection. These hardware checks remain pending. No firmware change.
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# App switcher close menu
|
||||||
|
|
||||||
|
Feature branch: `feat/app-controls`, based on `main` so it can be
|
||||||
|
reviewed independently. The combined build lives on `build/all-features`.
|
||||||
|
|
||||||
|
With the app switcher focused, long-press or tap-then-hold opens the existing
|
||||||
|
shell-owned System menu. “Close current app” closes the selected window when it
|
||||||
|
is closeable. It is absent for the pinned launcher (the large application grid).
|
||||||
|
“Close all apps” closes every closeable window, including background windows and
|
||||||
|
multiple windows belonging to one app. Pinned windows remain available.
|
||||||
|
|
||||||
|
Both actions reuse the shell's normal close/cleanup path. The menu closes before
|
||||||
|
the windows do, and focus returns to the switcher. It selects “Close current app” by default when available, otherwise “Focus app switcher”. With no closeable windows, “Close all apps” is disabled.
|
||||||
|
No new preferences or persistence format are introduced.
|
||||||
|
|
||||||
|
Software: `tests/app-switcher-menu.test.cjs` covers both gestures, apps claiming
|
||||||
|
holds/hold-to-talk, launcher exclusion, captured close targets, cancellation,
|
||||||
|
default selection, multiple windows, reentrant removal, callback errors and
|
||||||
|
screen-off behavior. Existing in-app gesture routing remains unchanged.
|
||||||
|
|
||||||
|
Manual validation on glasses remains pending:
|
||||||
|
|
||||||
|
1. Open several apps, focus the app switcher, and open the menu with both gestures.
|
||||||
|
2. Close the selected app; verify its surface disappears and other apps remain.
|
||||||
|
3. Select the large application grid; verify “Close current app” is absent.
|
||||||
|
4. Use “Close all apps”; verify the launcher remains usable and apps can reopen.
|
||||||
|
5. Repeat for left/right/bottom/popup switcher positions and with a running game,
|
||||||
|
a hold-to-talk app and an app exposing multiple windows.
|
||||||
|
6. Check cancel/back closes nothing; confirming the initial selection closes the current app when available. Check both
|
||||||
|
menu gestures still work normally when focus is inside an app.
|
||||||
|
|
||||||
|
Closing windows retains each app's existing lifecycle semantics; it does not
|
||||||
|
uninstall apps or reset their preferences. Existing app-specific shutdown behavior
|
||||||
|
(such as a remote terminal connection) is the same as closing its window normally.
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
# Launcher folders and layouts
|
|
||||||
|
|
||||||
Open the Apps window's app menu (tap then hold by default). Layout and New folder are available even without a single icon selected. New folder creates a persistent empty folder with an unused generated name. Select a folder, or enter it, to rename it through the existing phone text editor. Rename commits on Submit; Cancel leaves the folder unchanged. Names must be non-empty, single-line, at most 24 characters, and unique ignoring case. Delete folder requires confirmation and returns its apps to the root without uninstalling them.
|
|
||||||
|
|
||||||
Layout offers Alphabetical (the existing default) and Custom. In Custom, select an app or folder icon and choose Move icon, navigate to its destination and click to place it at that position. Double tap cancels; the watch's back from the left edge also cancels. The phone mirror can select the destination too. Moves stay within the root or current folder; Move to folder and Remove from folder remain available for changing membership. Renaming a folder preserves its root position and internal order. New apps append alphabetically after saved icons. Switching to Alphabetical retains saved custom positions for later use.
|
|
||||||
|
|
||||||
Persistence uses the existing shared settings store. The legacy launcher.folders assignment map stays compatible; new launcher.folderNames metadata preserves explicitly created/renamed empty folders. Untouched legacy folders keep disappearing when their last app is removed. launcher.layout stores the mode, and launcher.order stores root and per-folder order. Assistant folder tools remain consistent with empty folders. Existing installations retain their grouping and alphabetical layout.
|
|
||||||
|
|
||||||
Software checks cover defaults, restart, existing assignments, empty folder creation/deletion, duplicate and invalid names, rename commit/cancel, independent root/folder positions, layout toggling, new/removed apps, malformed metadata, move cancellation and deletion confirmation. TypeScript and changed-source lint are checked separately.
|
|
||||||
|
|
||||||
Hardware validation remains pending: ring row/item selection, watch directional navigation and back, moving across scroll rows, phone-mirror placement, phone rename Submit/Cancel, reopening folders and app restart. No firmware was flashed.
|
|
||||||
|
|
||||||
Independent branch validation: 1073 JavaScript tests passed, 2 skipped, 0 failed; TypeScript and changed-source lint passed.
|
|
||||||
|
|
||||||
## Open app switcher order
|
|
||||||
|
|
||||||
The system menu adds Move in app switcher when the selected window can be moved and at least two app windows are open. Its numbered position picker shows the currently open app windows in switcher order, preselects the current position, and uses window IDs internally to distinguish windows with identical titles. Choose a destination to move there, or double tap to cancel.
|
|
||||||
|
|
||||||
This arranges existing open windows independently of the launcher's Alphabetical/Custom preference. Pinned windows keep their slots and temporary status-item windows do not participate. Reordering retains the same foreground window, attention state and most-recently-used history; closing a window still returns to the most recently viewed one. New windows append as before. Open-window order lasts for those windows' lifetime; reopening the app does not restore previously closed windows or write ephemeral window IDs to settings.
|
|
||||||
|
|
||||||
Software tests cover both directions, menu integration, duplicate titles, captured source IDs, cancellation, removed source/destination, temporary and pinned windows, appending/replacing windows, foreground identity and MRU close behavior. Hardware checks remain pending for ring/watch navigation in the position picker and left/right/bottom/popup switcher placements.
|
|
||||||
|
|
||||||
Independent branch after adding open-window ordering: 1080 JavaScript tests passed, 2 skipped; TypeScript and changed-source lint passed.
|
|
||||||
@@ -267,6 +267,9 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
|||||||
}
|
}
|
||||||
const voiceDialogs = [];
|
const voiceDialogs = [];
|
||||||
const settings = { wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' },
|
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 } };
|
assistantSkipConfirmationSetting: { get: () => skipConfirmation } };
|
||||||
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
|
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
|
||||||
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
|
'../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) },
|
||||||
@@ -370,6 +373,7 @@ test('ordinary apps retain long-press system menu and games retain the escape ti
|
|||||||
assert.deepEqual(env.input, []);
|
assert.deepEqual(env.input, []);
|
||||||
env.shell.stack.clearToBase();
|
env.shell.stack.clearToBase();
|
||||||
env.app.window.claimsLongPress = () => true;
|
env.app.window.claimsLongPress = () => true;
|
||||||
|
env.shell.focusWindow('ai-chat');
|
||||||
await env.shell.receiveInput(env.event('long-press'));
|
await env.shell.receiveInput(env.event('long-press'));
|
||||||
assert.notEqual(env.shell.escapeMenuTimer, null);
|
assert.notEqual(env.shell.escapeMenuTimer, null);
|
||||||
await env.shell.receiveInput(env.event('long-press-release'));
|
await env.shell.receiveInput(env.event('long-press-release'));
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ function geometry() {
|
|||||||
appSwitcherPositionSetting: 'left', uiDepthSetting: '0', statusBarPositionSetting: 'top',
|
appSwitcherPositionSetting: 'left', uiDepthSetting: '0', statusBarPositionSetting: 'top',
|
||||||
statusBarVisibilitySetting: 'always', windowBorderSetting: true,
|
statusBarVisibilitySetting: 'always', windowBorderSetting: true,
|
||||||
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
|
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
|
||||||
|
const fullscreen = new Map();
|
||||||
|
settings.appFullscreenSetting = id => ({ get: () => fullscreen.get(id) ?? false, set: value => fullscreen.set(id, value) });
|
||||||
const context = { exports: {}, require: (name) => {
|
const context = { exports: {}, require: (name) => {
|
||||||
if (name === '../../graphics/image') return { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480 };
|
if (name === '../../graphics/image') return { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480 };
|
||||||
assert.equal(name, '../dashboard-settings');
|
assert.equal(name, '../dashboard-settings');
|
||||||
@@ -27,6 +29,25 @@ function geometry() {
|
|||||||
|
|
||||||
const LAYOUTS = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
|
const LAYOUTS = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
|
||||||
|
|
||||||
|
test('user full screen spans the panel with any switcher and survives app immersive cleanup', () => {
|
||||||
|
const g = geometry();
|
||||||
|
const previous = g.rect('min', 'test');
|
||||||
|
for (const position of ['left', 'right', 'bottom', 'popup']) {
|
||||||
|
g.settings.appSwitcherPositionSetting.value = position;
|
||||||
|
g.settings.appFullscreenSetting('test').set(true);
|
||||||
|
assert.deepEqual(g.rect('min', 'test'), { x: 0, y: 0, width: 640, height: 480 });
|
||||||
|
assert.equal(g.sidebarStripVisible('window', 'test'), false);
|
||||||
|
assert.equal(g.sidebarStripVisible('sidebar', 'test'), true);
|
||||||
|
g.setAppImmersive('test', true);
|
||||||
|
g.setAppImmersive('test', false);
|
||||||
|
assert.equal(g.isImmersive('test'), true);
|
||||||
|
assert.equal(g.isImmersive('other'), false);
|
||||||
|
}
|
||||||
|
g.settings.appSwitcherPositionSetting.value = 'left';
|
||||||
|
g.settings.appFullscreenSetting('test').set(false);
|
||||||
|
assert.deepEqual(g.rect('min', 'test'), previous);
|
||||||
|
});
|
||||||
|
|
||||||
test('defaults preserve normal windows, EvenHub height and tall terminal sessions', () => {
|
test('defaults preserve normal windows, EvenHub height and tall terminal sessions', () => {
|
||||||
const g = geometry();
|
const g = geometry();
|
||||||
assert.deepEqual(g.rect('min', 'navigate'), { x: 64, y: 124, width: 576, height: 260 });
|
assert.deepEqual(g.rect('min', 'navigate'), { x: 64, y: 124, width: 576, height: 260 });
|
||||||
|
|||||||
@@ -0,0 +1,227 @@
|
|||||||
|
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');
|
||||||
|
|
||||||
|
function fixture(options = {}) {
|
||||||
|
const source = ts.createSourceFile('shell.ts', fs.readFileSync(path.join(__dirname, '../app/ui/shell/shell.ts'), 'utf8'), ts.ScriptTarget.Latest, true);
|
||||||
|
const shellClass = source.statements.find(node => ts.isClassDeclaration(node) && node.name.text === 'Shell');
|
||||||
|
const names = new Set(['routeInput', 'openEscapeMenu', 'closeAllWindows', 'closeWindow', 'removeWindow',
|
||||||
|
'foregroundWindow', 'noteWindowVisible', 'mostRecentWindowIndex', 'yieldFocusToSidebar', 'applyScreenTimeout']);
|
||||||
|
const methods = shellClass.members.filter(node => names.has(node.name?.getText(source)));
|
||||||
|
assert.equal(methods.length, names.size);
|
||||||
|
const overlay = source.statements.find(node => ts.isClassDeclaration(node) && node.name.text === 'ShellOverlayMenuLayer');
|
||||||
|
class MenuLayer {
|
||||||
|
constructor(title, items) { this.title = title; this.items = items; }
|
||||||
|
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,
|
||||||
|
brightnessSetting: { get: () => 'auto' }, gestureHints: () => 'App menu',
|
||||||
|
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) }),
|
||||||
|
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 },
|
||||||
|
}).outputText, context);
|
||||||
|
const s = new context.exports.Shell();
|
||||||
|
const closed = [], delivered = [], warnings = [], renders = [];
|
||||||
|
context.console.warn = message => warnings.push(message);
|
||||||
|
const window = (id, closeable = true, extra = {}) => ({
|
||||||
|
appId: id, windowId: id, closeable,
|
||||||
|
handleInput: async event => delivered.push([id, event.type]),
|
||||||
|
requestRender: () => renders.push(id),
|
||||||
|
close: () => closed.push(id),
|
||||||
|
...extra,
|
||||||
|
});
|
||||||
|
const launcher = window('launcher', false);
|
||||||
|
const app = window('current', true, options.app);
|
||||||
|
const background = window('background');
|
||||||
|
const layers = [];
|
||||||
|
s.stack = {
|
||||||
|
isAtBase: () => !layers.length,
|
||||||
|
push: layer => layers.push(layer),
|
||||||
|
pop: () => layers.pop()?.onRemoved?.(),
|
||||||
|
popIfTop: predicate => { if (!layers.length || !predicate(layers.at(-1))) return false; s.stack.pop(); return true; },
|
||||||
|
handleInput: async event => { if (event.type === 'double-click') s.stack.pop(); },
|
||||||
|
};
|
||||||
|
Object.assign(s, {
|
||||||
|
windows: [launcher, app, background], selectedIndex: 1, focus: 'sidebar', screenOn: true,
|
||||||
|
mruWindowIds: ['current', 'background', 'launcher'], attention: new Map(),
|
||||||
|
config: { voiceInputEnabled: false, requestShellRender() {}, onWindowsChanged() {} },
|
||||||
|
cancelEscapeMenuTimer() {}, startEscapeMenuTimer() { s.escapeStarted = true; },
|
||||||
|
lastInput: null,
|
||||||
|
lastInputAtMs: 0,
|
||||||
|
noteUserActivity() { this.lastInputAtMs = 100; },
|
||||||
|
focusWindow(id) { this.selectedIndex = this.windows.findIndex(w => w.windowId === id); this.focus = 'window'; },
|
||||||
|
sleep() { this.screenOn = false; },
|
||||||
|
});
|
||||||
|
const input = type => s.routeInput({ type, source: 'ring', timestampMs: 100 }, 1);
|
||||||
|
const menu = () => layers.at(-1);
|
||||||
|
const choose = label => {
|
||||||
|
const item = menu().items.find(item => item.label === label);
|
||||||
|
assert.ok(item, label);
|
||||||
|
item.onSelect({ stack: s.stack });
|
||||||
|
};
|
||||||
|
return { s, input, menu, choose, closed, delivered, warnings, renders, launcher, app, background, window, fullscreen, keepAwake };
|
||||||
|
}
|
||||||
|
|
||||||
|
test('full screen targets the captured app without inhibiting idle sleep', async () => {
|
||||||
|
const h = fixture();
|
||||||
|
h.s.config.getScreenTimeoutMs = () => 1000;
|
||||||
|
let relayouts = 0;
|
||||||
|
h.s.config.onWindowLayoutChanged = () => relayouts++;
|
||||||
|
await h.input('long-press');
|
||||||
|
h.s.selectedIndex = 2;
|
||||||
|
h.choose('Enter full screen');
|
||||||
|
assert.equal(h.fullscreen.get('current'), true);
|
||||||
|
assert.equal(h.s.foregroundWindow().windowId, 'current');
|
||||||
|
assert.equal(h.s.focus, 'window');
|
||||||
|
assert.equal(relayouts, 1);
|
||||||
|
assert.equal(h.s.applyScreenTimeout(5000), true);
|
||||||
|
h.s.screenOn = true;
|
||||||
|
h.s.focusWindow('current');
|
||||||
|
await h.input('long-press');
|
||||||
|
h.choose('Exit full screen');
|
||||||
|
assert.equal(h.fullscreen.get('current'), false);
|
||||||
|
assert.equal(relayouts, 2);
|
||||||
|
assert.equal(h.s.applyScreenTimeout(7000), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
h.s.screenOn = true;
|
||||||
|
h.s.config.isLocked = () => false;
|
||||||
|
h.s.sleep();
|
||||||
|
assert.equal(h.s.screenOn, false);
|
||||||
|
h.s.screenOn = true;
|
||||||
|
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 () => {
|
||||||
|
for (const type of ['long-press', 'short-then-long-press']) {
|
||||||
|
for (const app of [{}, { claimsLongPress: () => true }, { holdToTalk: true }]) {
|
||||||
|
const h = fixture({ app });
|
||||||
|
await h.input(type);
|
||||||
|
assert.ok(h.menu());
|
||||||
|
assert.ok(h.menu().items.some(item => item.label === 'Close current app'));
|
||||||
|
assert.ok(h.menu().items.some(item => item.label === 'Close all apps'));
|
||||||
|
assert.equal(h.menu().items[h.menu().selectedIndex].label, 'Close current app');
|
||||||
|
assert.deepEqual(h.delivered, [['current', 'system-menu-opened']]);
|
||||||
|
assert.equal(h.s.escapeStarted, undefined);
|
||||||
|
assert.equal(h.s.focus, 'sidebar');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('close current app closes the captured window and preserves the launcher and background windows', async () => {
|
||||||
|
const h = fixture();
|
||||||
|
await h.input('long-press');
|
||||||
|
h.s.selectedIndex = 2; // An asynchronous focus change must not redirect the close action.
|
||||||
|
h.menu().items[h.menu().selectedIndex].onSelect({ stack: h.s.stack });
|
||||||
|
assert.deepEqual(h.closed, ['current']);
|
||||||
|
assert.deepEqual(h.s.windows.map(w => w.windowId), ['launcher', 'background']);
|
||||||
|
assert.equal(h.s.focus, 'sidebar');
|
||||||
|
assert.equal(h.menu(), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('launcher offers close all but never close current; close all leaves only the launcher', async () => {
|
||||||
|
const h = fixture();
|
||||||
|
h.s.selectedIndex = 0;
|
||||||
|
await h.input('short-then-long-press');
|
||||||
|
assert.ok(!h.menu().items.some(item => item.label === 'Close current app'));
|
||||||
|
assert.equal(h.menu().items[h.menu().selectedIndex].label, 'Focus app switcher');
|
||||||
|
h.choose('Close all apps');
|
||||||
|
assert.deepEqual(h.closed, ['current', 'background']);
|
||||||
|
assert.deepEqual(h.s.windows.map(w => w.windowId), ['launcher']);
|
||||||
|
assert.equal(h.s.selectedIndex, 0);
|
||||||
|
assert.equal(h.s.focus, 'sidebar');
|
||||||
|
await h.input('long-press');
|
||||||
|
assert.equal(h.menu().items.find(item => item.label === 'Close all apps').disabled(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('close all uses normal cleanup despite reentrant removal, multiple windows per app and throwing callbacks', () => {
|
||||||
|
const h = fixture();
|
||||||
|
h.s.windows.push(h.window('another', true, { appId: 'current' }), h.window('pinned', false));
|
||||||
|
h.app.close = () => { h.closed.push('current'); h.s.removeWindow('current'); };
|
||||||
|
h.background.close = () => { h.closed.push('background'); throw new Error('failed cleanup'); };
|
||||||
|
h.s.closeAllWindows();
|
||||||
|
assert.deepEqual(h.closed, ['current', 'background', 'another']);
|
||||||
|
assert.deepEqual(h.s.windows.map(w => w.windowId), ['launcher', 'pinned']);
|
||||||
|
assert.equal(h.warnings.length, 1);
|
||||||
|
assert.equal(h.s.foregroundWindow().windowId, 'launcher');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('focusing switcher and cancelling do not close apps; an open overlay never receives a second menu', async () => {
|
||||||
|
const h = fixture();
|
||||||
|
await h.input('long-press');
|
||||||
|
h.choose('Focus app switcher');
|
||||||
|
assert.deepEqual(h.closed, []);
|
||||||
|
await h.input('long-press');
|
||||||
|
const menu = h.menu();
|
||||||
|
await h.input('long-press');
|
||||||
|
assert.equal(h.menu(), menu);
|
||||||
|
await h.input('double-click');
|
||||||
|
assert.equal(h.menu(), undefined);
|
||||||
|
assert.deepEqual(h.closed, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('in-app hold actions and app menus keep their existing routing; asleep switcher stays asleep', async () => {
|
||||||
|
for (const [app, type] of [[{ claimsLongPress: () => true }, 'long-press'], [{ holdToTalk: true }, 'long-press'], [{}, 'short-then-long-press']]) {
|
||||||
|
const h = fixture({ app });
|
||||||
|
h.s.focus = 'window';
|
||||||
|
await h.input(type);
|
||||||
|
assert.deepEqual(h.delivered, [['current', type]]);
|
||||||
|
assert.equal(h.menu(), undefined);
|
||||||
|
}
|
||||||
|
const h = fixture();
|
||||||
|
h.s.screenOn = false;
|
||||||
|
await h.input('long-press');
|
||||||
|
assert.equal(h.menu(), undefined);
|
||||||
|
assert.deepEqual(h.closed, []);
|
||||||
|
});
|
||||||
@@ -39,6 +39,9 @@ const menu = load('app/ui/menu.ts', {
|
|||||||
function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) {
|
function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) {
|
||||||
let value = initial, writes = 0, closed = 0;
|
let value = initial, writes = 0, closed = 0;
|
||||||
const settings = {
|
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++; } },
|
brightnessSetting: { get: () => value, set: (next) => { value = next; writes++; } },
|
||||||
brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value),
|
brightnessSettingToLevel: (value) => value === 'auto' ? null : Number(value),
|
||||||
};
|
};
|
||||||
@@ -120,13 +123,16 @@ test('system menu hides brightness in Auto and opens its picker between Voice in
|
|||||||
shell.openSystemMenu('test');
|
shell.openSystemMenu('test');
|
||||||
let opened = shell.stack.layers.at(-1);
|
let opened = shell.stack.layers.at(-1);
|
||||||
assert.deepEqual(Array.from(opened.items, (item) => item.label),
|
assert.deepEqual(Array.from(opened.items, (item) => item.label),
|
||||||
['Close window', 'Focus app switcher', 'Voice input', 'Debug']);
|
['Close current app', 'Focus app switcher', 'Voice input', 'Close all apps', 'Enter full screen', 'Keep screen awake', 'Debug']);
|
||||||
shell.stack.clearToBase();
|
shell.stack.clearToBase();
|
||||||
f.settings.brightnessSetting.set('40');
|
f.settings.brightnessSetting.set('40');
|
||||||
shell.openSystemMenu('test');
|
shell.openSystemMenu('test');
|
||||||
opened = shell.stack.layers.at(-1);
|
opened = shell.stack.layers.at(-1);
|
||||||
assert.deepEqual(Array.from(opened.items, (item) => item.label),
|
assert.deepEqual(Array.from(opened.items, (item) => item.label),
|
||||||
['Close window', 'Focus app switcher', 'Voice input', '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' }));
|
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: 'click', source: 'ring' }));
|
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'click', source: 'ring' }));
|
||||||
|
|||||||
@@ -64,3 +64,32 @@ test('Full Screen is offered only with a bottom or popup app switcher', () => {
|
|||||||
assert.deepEqual(Array.from(api.DISPLAY_LAYOUT_VALUES, (value) => api.displayLayoutLabel(value)),
|
assert.deepEqual(Array.from(api.DISPLAY_LAYOUT_VALUES, (value) => api.displayLayoutLabel(value)),
|
||||||
['Band · Top', 'Band · High', 'Band · Middle', 'Band · Low', 'Band · Bottom', 'Tall', 'Full Screen']);
|
['Band · Top', 'Band · High', 'Band · Middle', 'Band · Low', 'Band · Bottom', 'Tall', 'Full Screen']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('per-app full screen defaults off, persists across restart and preserves display preferences', () => {
|
||||||
|
const store = new Map([['display.layout', 'band-low'], ['terminal.displayLayout', 'tall']]);
|
||||||
|
const prefs = settingsFixture(store);
|
||||||
|
assert.equal(prefs.appFullscreenSetting('terminal').get(), false);
|
||||||
|
prefs.appFullscreenSetting('terminal').set(true);
|
||||||
|
const restarted = settingsFixture(store);
|
||||||
|
assert.equal(restarted.appFullscreenSetting('terminal').get(), true);
|
||||||
|
assert.equal(restarted.appFullscreenSetting('other').get(), false);
|
||||||
|
restarted.appFullscreenSetting('terminal').set(false);
|
||||||
|
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);
|
||||||
|
});
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const { loader } = require('./helpers/load-typescript.cjs');
|
||||||
|
const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||||
|
|
||||||
|
function fixture() {
|
||||||
|
let options, hooks;
|
||||||
|
const paints = [], heights = [];
|
||||||
|
const session = {
|
||||||
|
manifest: { name: 'Test', packageId: 'test.app' },
|
||||||
|
renderWindowIcon() {}, contextMenuItems: () => [], keepsScreenOn: () => false,
|
||||||
|
attachWindow(value) { hooks = value; },
|
||||||
|
paint(size, focused) {
|
||||||
|
paints.push({ ...size, focused });
|
||||||
|
const image = new GrayImage(size.width, size.height);
|
||||||
|
image.setPixel(0, 0, 255);
|
||||||
|
image.setPixel(size.width - 1, size.height - 1, 120);
|
||||||
|
// Deliberately overflow a deferred text run: stock clips it at 576x288.
|
||||||
|
image.drawFwText({ bakeFwTextRun(target, run, dx, dy) {
|
||||||
|
target.fillRect(run.x + dx, run.y + dy, 20, 20, run.value);
|
||||||
|
} }, 570, 280, 200, [{}]);
|
||||||
|
return image;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const load = loader({}, {
|
||||||
|
'../../graphics/image': { GrayImage },
|
||||||
|
'./compositor': { EVENHUB_SCREEN_WIDTH: 576, EVENHUB_SCREEN_HEIGHT: 288 },
|
||||||
|
'../../ui/gestures': {}, '../../ui/shell/shell': { shell: {} }, './session': {},
|
||||||
|
'../../ui/shell/chrome-layer': { windowIcon: () => () => null, makeImageWindowIcon: () => () => null },
|
||||||
|
'./installed-apps': {},
|
||||||
|
'../../ui/shell/in-process-window': { createInProcessWindow(value) {
|
||||||
|
options = value;
|
||||||
|
return { window: {}, stack: {}, requestRender() {}, setHeightMode(mode) { heights.push(mode); } };
|
||||||
|
} },
|
||||||
|
});
|
||||||
|
load('app/apps/evenhub/evenhub-window.ts').createEvenHubWindow('test', 'test', session, {}, () => {}, () => {});
|
||||||
|
return { paints, heights, hooks: () => hooks,
|
||||||
|
paint(width, height, focused = true) {
|
||||||
|
return options.baseLayer.paint({ stack: { getBaseSize: () => ({ width, height }), isFocused: () => focused } });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test('stock EvenHub canvas remains 576x288 through full-screen entry, resize and exit', () => {
|
||||||
|
const f = fixture();
|
||||||
|
for (const [width, height] of [[576, 288], [640, 480], [576, 452], [640, 480], [576, 288]]) {
|
||||||
|
const image = f.paint(width, height);
|
||||||
|
assert.deepEqual(f.paints.at(-1), { width: 576, height: 288, focused: true });
|
||||||
|
assert.equal(image.width, width);
|
||||||
|
assert.equal(image.height, height);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('full screen centers stock pixels at native scale and clips overflowing text to the stock canvas', () => {
|
||||||
|
const f = fixture();
|
||||||
|
const stock = f.paint(576, 288).withDrawsBaked();
|
||||||
|
const full = f.paint(640, 480).withDrawsBaked();
|
||||||
|
for (let y = 0; y < 480; y++) {
|
||||||
|
for (let x = 0; x < 640; x++) {
|
||||||
|
const expected = x >= 32 && x < 608 && y >= 96 && y < 384 ? stock.getPixel(x - 32, y - 96) : 0;
|
||||||
|
assert.equal(full.getPixel(x, y), expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('only an explicit extended-layout request opts into the taller canvas', () => {
|
||||||
|
const f = fixture();
|
||||||
|
f.paint(640, 480, false);
|
||||||
|
assert.deepEqual(f.paints.at(-1), { width: 576, height: 288, focused: false });
|
||||||
|
f.hooks().setTallCanvas(true);
|
||||||
|
assert.deepEqual(f.heights, ['max']);
|
||||||
|
f.paint(576, 452);
|
||||||
|
assert.equal(f.paints.at(-1).height, 452);
|
||||||
|
f.paint(640, 480);
|
||||||
|
assert.equal(f.paints.at(-1).width, 576);
|
||||||
|
assert.equal(f.paints.at(-1).height, 480);
|
||||||
|
f.hooks().setTallCanvas(false);
|
||||||
|
f.paint(640, 480);
|
||||||
|
assert.deepEqual(f.heights, ['max', 'medium']);
|
||||||
|
assert.equal(f.paints.at(-1).height, 288);
|
||||||
|
});
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
const test = require('node:test');
|
|
||||||
const assert = require('node:assert/strict');
|
|
||||||
const fs = require('node:fs');
|
|
||||||
const vm = require('node:vm');
|
|
||||||
const ts = require('typescript');
|
|
||||||
|
|
||||||
function fixture(store = new Map()) {
|
|
||||||
const storage = { getStringSetting: (key, fallback) => store.get(key) ?? fallback,
|
|
||||||
setStringSetting: (key, value) => store.set(key, value), onSettingsStoreChanged() {},
|
|
||||||
getBooleanSetting: (_key, fallback) => fallback, setBooleanSetting() {} };
|
|
||||||
function load(file, deps, suffix = '') {
|
|
||||||
const context = { exports: {}, global: { isIOS: false }, console,
|
|
||||||
require: id => deps(id) };
|
|
||||||
vm.runInNewContext(ts.transpileModule(fs.readFileSync(file, 'utf8') + suffix, {
|
|
||||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
||||||
}).outputText, context);
|
|
||||||
return context.exports;
|
|
||||||
}
|
|
||||||
const layout = load('app/apps/launcher/launcher-layout.ts', () => storage);
|
|
||||||
const folders = load('app/apps/launcher/launcher-folders.ts', id => id === './launcher-layout' ? layout : storage);
|
|
||||||
const settings = load('app/ui/dashboard-settings.ts', id => {
|
|
||||||
if (id.includes('settings-store')) return storage;
|
|
||||||
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: [] };
|
|
||||||
});
|
|
||||||
return { store, layout, folders, settings, load };
|
|
||||||
}
|
|
||||||
const plain = value => JSON.parse(JSON.stringify(value));
|
|
||||||
|
|
||||||
test('legacy assignments and alphabetical default survive creation, rename and restart', () => {
|
|
||||||
const f = fixture();
|
|
||||||
const original = plain(f.folders.getFolderAssignments());
|
|
||||||
assert.equal(f.settings.launcherLayoutSetting.get(), 'alphabetical');
|
|
||||||
assert.equal(f.folders.createFolder(' Français '), true);
|
|
||||||
assert.deepEqual(plain(f.folders.getFolders().get('Français')), []);
|
|
||||||
assert.deepEqual(plain(f.folders.getFolderAssignments()), original);
|
|
||||||
assert.equal(f.folders.renameFolder('Games', 'Jeux'), true);
|
|
||||||
const again = fixture(f.store);
|
|
||||||
assert.equal(again.folders.getFolderAssignments().blocks, 'Jeux');
|
|
||||||
assert.equal(again.folders.getFolderAssignments().calculator, 'Prototypes');
|
|
||||||
assert.equal(again.folders.getFolders().has('Français'), true);
|
|
||||||
assert.equal(again.folders.getFolders().has('Games'), false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('folder names reject blank, multiline, long and case-insensitive duplicate names', () => {
|
|
||||||
const f = fixture();
|
|
||||||
for (const name of ['', ' ', 'games', 'GAMES', 'x'.repeat(25), 'Two\nlines']) {
|
|
||||||
assert.equal(f.folders.createFolder(name), false, name);
|
|
||||||
assert.equal(f.folders.renameFolder('Prototypes', name), false, name);
|
|
||||||
}
|
|
||||||
assert.equal(f.folders.renameFolder('Games', 'games'), true);
|
|
||||||
assert.equal(f.folders.renameFolder('missing', 'New name'), false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('explicit empty folders persist, can be deleted and never reintroduce default assignments', () => {
|
|
||||||
const f = fixture(new Map([['launcher.folders', '{}']]));
|
|
||||||
assert.equal(f.folders.createFolder('Empty'), true);
|
|
||||||
f.folders.setAppFolder('test', 'Empty');
|
|
||||||
f.folders.setAppFolder('test', null);
|
|
||||||
assert.equal(fixture(f.store).folders.getFolders().has('Empty'), true);
|
|
||||||
assert.equal(f.folders.disbandFolder('Empty'), 0);
|
|
||||||
assert.equal(f.folders.getFolders().size, 0);
|
|
||||||
assert.equal(f.folders.unusedNewFolderName(), 'New folder');
|
|
||||||
f.folders.createFolder('New folder');
|
|
||||||
assert.equal(f.folders.unusedNewFolderName(), 'New folder 2');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('deleting a non-empty folder ungroups all members without losing other assignments', () => {
|
|
||||||
const f = fixture();
|
|
||||||
assert.equal(f.folders.disbandFolder('Games'), 5);
|
|
||||||
assert.equal(f.folders.getFolderAssignments().blocks, undefined);
|
|
||||||
assert.equal(f.folders.getFolderAssignments().calculator, 'Prototypes');
|
|
||||||
assert.equal(fixture(f.store).folders.getFolders().has('Games'), false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('custom root and folder orders persist independently, survive renames and append new apps', () => {
|
|
||||||
const f = fixture();
|
|
||||||
const entries = [{ label: 'Alpha', id: 'app:a' }, { label: 'Beta', id: 'app:b' }, { label: 'Games', id: 'folder:Games' }];
|
|
||||||
const sort = (scope, custom = true) => plain(f.layout.orderLauncherEntries(entries.slice(), e => e.id, scope, custom)).map(e => e.id);
|
|
||||||
f.settings.launcherLayoutSetting.set('custom');
|
|
||||||
f.layout.moveLauncherEntry(null, entries.map(e => e.id), 'folder:Games', 'app:a');
|
|
||||||
f.layout.setLauncherOrder('Games', ['app:b', 'app:a']);
|
|
||||||
assert.deepEqual(sort(null), ['folder:Games', 'app:a', 'app:b']);
|
|
||||||
assert.deepEqual(sort('Games'), ['app:b', 'app:a', 'folder:Games']);
|
|
||||||
assert.deepEqual(sort(null, false), ['app:a', 'app:b', 'folder:Games']);
|
|
||||||
f.settings.launcherLayoutSetting.set('alphabetical');
|
|
||||||
f.settings.launcherLayoutSetting.set('custom');
|
|
||||||
assert.deepEqual(sort(null), ['folder:Games', 'app:a', 'app:b']);
|
|
||||||
f.folders.renameFolder('Games', 'Jeux');
|
|
||||||
const again = fixture(f.store);
|
|
||||||
assert.equal(again.settings.launcherLayoutSetting.get(), 'custom');
|
|
||||||
entries[2] = { label: 'Jeux', id: 'folder:Jeux' };
|
|
||||||
assert.deepEqual(sort(null), ['folder:Jeux', 'app:a', 'app:b']);
|
|
||||||
assert.deepEqual(sort('Jeux'), ['app:b', 'app:a', 'folder:Jeux']);
|
|
||||||
entries.push({ label: 'A newly installed app', id: 'app:new' });
|
|
||||||
assert.deepEqual(sort(null), ['folder:Jeux', 'app:a', 'app:b', 'app:new']);
|
|
||||||
f.folders.disbandFolder('Jeux');
|
|
||||||
f.folders.createFolder('Jeux');
|
|
||||||
assert.deepEqual(sort('Jeux'), ['app:new', 'app:a', 'app:b', 'folder:Jeux']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('malformed metadata is safe; moves tolerate removed apps and stale IDs', () => {
|
|
||||||
const f = fixture(new Map([['launcher.folderNames', '{bad'], ['launcher.order', '{bad']]));
|
|
||||||
assert.equal(f.folders.getExplicitFolderNames().length, 0);
|
|
||||||
assert.equal(f.layout.moveLauncherEntry(null, ['a', 'b'], 'missing', 'a'), false);
|
|
||||||
assert.equal(f.layout.moveLauncherEntry(null, ['a', 'b'], 'a', 'missing'), false);
|
|
||||||
assert.equal(f.layout.moveLauncherEntry(null, ['a', 'b'], 'a', 'b'), true);
|
|
||||||
assert.deepEqual(JSON.parse(f.store.get('launcher.order')).root, ['b', 'a']);
|
|
||||||
});
|
|
||||||
|
|
||||||
function launcherFixture() {
|
|
||||||
const f = fixture(new Map([['launcher.folders', '{}']]));
|
|
||||||
const layers = [], launches = [], deleted = [];
|
|
||||||
class IconGrid {
|
|
||||||
constructor(options) { this.options = options; this.index = null; }
|
|
||||||
get selectedItem() { return this.index === null ? null : this.options.items()[this.index] ?? null; }
|
|
||||||
resetSelection() { this.index = null; }
|
|
||||||
selectIndex(index) { this.index = index; }
|
|
||||||
enterRowMode() { this.index = null; }
|
|
||||||
async handleInput(event, ctx) {
|
|
||||||
if (event.type === 'click') await this.options.onActivate(this.selectedItem, ctx);
|
|
||||||
if (event.type === 'double-click' || event.type === 'swipe-left') this.options.onBack(ctx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class MenuLayer { constructor(title, items) { this.title = title; this.items = items; } }
|
|
||||||
class EditTextSettingLayer { constructor(setting) { this.setting = setting; } }
|
|
||||||
let edit;
|
|
||||||
const ctx = { stack: {
|
|
||||||
push: layer => layers.push(layer), pop() { const layer = layers.pop(); layer?.onRemoved?.(); },
|
|
||||||
popIfTop(test) { if (layers.length && test(layers.at(-1))) { this.pop(); return true; } return false; },
|
|
||||||
}, actions: { requestRender() {}, endTextSettingEdit() {}, startTextSettingsEdit(settings, title, submit, toggle, cancel) {
|
|
||||||
edit = { setting: settings[0], submit, cancel };
|
|
||||||
} } };
|
|
||||||
const api = f.load('app/apps/launcher/launcher-app.ts', id => {
|
|
||||||
if (id === './launcher-folders') return f.folders;
|
|
||||||
if (id === './launcher-layout') return f.layout;
|
|
||||||
if (id.endsWith('/dashboard-settings')) return { ...f.settings, EditTextSettingLayer,
|
|
||||||
enumSettingMenuItem: setting => ({ label: setting.label }) };
|
|
||||||
if (id.endsWith('/icon-grid')) return { IconGrid, ICON_GRID_BAND_INSET_X: 0, ICON_GRID_HIGHLIGHT_INSET_Y: 0 };
|
|
||||||
if (id.endsWith('/menu')) return { MenuLayer };
|
|
||||||
if (id.endsWith('/shell/shell')) return { shell: { yieldFocusToSidebar() {} } };
|
|
||||||
return {};
|
|
||||||
}, '\nexport { LauncherGridLayer };');
|
|
||||||
const apps = [{ appId: 'a', label: 'Alpha', icon: 'a' }, { appId: 'b', label: 'Beta', icon: 'b' }, { appId: 'c', label: 'Gamma', icon: 'c' }];
|
|
||||||
const layer = new api.LauncherGridLayer({ apps: () => apps, launchApp: id => launches.push(id), uninstallApp: id => deleted.push(id) });
|
|
||||||
return { ...f, layer, ctx, layers, launches, deleted, apps, edit: () => edit,
|
|
||||||
choose(label) { const item = layer.menuItems().find(item => item.label === label); assert.ok(item, label); item.onSelect(ctx); } };
|
|
||||||
}
|
|
||||||
|
|
||||||
test('launcher menu is available in row mode and supports empty folder creation and entry', async () => {
|
|
||||||
const h = launcherFixture();
|
|
||||||
assert.deepEqual(plain(h.layer.menuItems().map(item => item.label)), ['Layout', 'New folder']);
|
|
||||||
h.choose('New folder');
|
|
||||||
const folder = h.layer.entries().find(entry => entry.kind === 'folder');
|
|
||||||
assert.equal(folder.name, 'New folder');
|
|
||||||
await h.layer.openEntry(folder);
|
|
||||||
assert.equal(h.layer.currentFolder, 'New folder');
|
|
||||||
assert.equal(h.layer.entries().length, 0);
|
|
||||||
assert.ok(h.layer.menuItems().some(item => item.label === 'Rename folder'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('folder rename uses the existing editor, commits on submit only, and preserves open folder', async () => {
|
|
||||||
const h = launcherFixture(); h.choose('New folder');
|
|
||||||
await h.layer.openEntry(h.layer.entries().find(entry => entry.kind === 'folder'));
|
|
||||||
h.choose('Rename folder');
|
|
||||||
h.edit().setting.set('Renommé');
|
|
||||||
assert.equal(h.layer.menuItems().length, 0);
|
|
||||||
assert.equal(h.folders.getFolders().has('New folder'), true);
|
|
||||||
h.edit().cancel();
|
|
||||||
assert.equal(h.folders.getFolders().has('Renommé'), false);
|
|
||||||
h.choose('Rename folder');
|
|
||||||
h.edit().setting.set('Renommé');
|
|
||||||
h.edit().submit();
|
|
||||||
assert.equal(h.layer.currentFolder, 'Renommé');
|
|
||||||
assert.equal(h.folders.getFolders().has('New folder'), false);
|
|
||||||
assert.equal(h.layers.length, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('moving icons reorders without launching; cancellation and alphabetical mode preserve order', async () => {
|
|
||||||
const h = launcherFixture();
|
|
||||||
h.layer.grid.selectIndex(0);
|
|
||||||
assert.equal(h.layer.menuItems().some(item => item.label === 'Move icon'), false);
|
|
||||||
h.settings.launcherLayoutSetting.set('custom');
|
|
||||||
h.choose('Move icon');
|
|
||||||
h.layer.grid.selectIndex(2);
|
|
||||||
await h.layer.handleInput({ type: 'click' }, h.ctx);
|
|
||||||
assert.deepEqual(plain(h.layer.entries().map(entry => entry.appId)), ['b', 'c', 'a']);
|
|
||||||
assert.equal(h.launches.length, 0);
|
|
||||||
h.choose('Move icon');
|
|
||||||
h.layer.grid.selectIndex(0);
|
|
||||||
await h.layer.handleInput({ type: 'double-click' }, h.ctx);
|
|
||||||
assert.equal(h.layer.moving, null);
|
|
||||||
assert.deepEqual(plain(h.layer.entries().map(entry => entry.appId)), ['b', 'c', 'a']);
|
|
||||||
h.settings.launcherLayoutSetting.set('alphabetical');
|
|
||||||
assert.deepEqual(plain(h.layer.entries().map(entry => entry.appId)), ['a', 'b', 'c']);
|
|
||||||
h.settings.launcherLayoutSetting.set('custom');
|
|
||||||
assert.deepEqual(plain(h.layer.entries().map(entry => entry.appId)), ['b', 'c', 'a']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('folder moves stay inside their scope, folder deletion is confirmed and apps are not uninstalled', async () => {
|
|
||||||
const h = launcherFixture(); h.folders.createFolder('Dossier');
|
|
||||||
h.folders.setAppFolder('a', 'Dossier'); h.folders.setAppFolder('b', 'Dossier');
|
|
||||||
await h.layer.openEntry(h.layer.entries().find(entry => entry.kind === 'folder'));
|
|
||||||
h.settings.launcherLayoutSetting.set('custom'); h.layer.grid.selectIndex(0);
|
|
||||||
h.choose('Move icon'); await h.layer.openEntry(h.layer.entries()[1]);
|
|
||||||
assert.deepEqual(plain(h.layer.entries().map(entry => entry.appId)), ['b', 'a']);
|
|
||||||
h.choose('Delete folder');
|
|
||||||
assert.equal(h.folders.getFolders().has('Dossier'), true);
|
|
||||||
h.layers.at(-1).items[0].onSelect(h.ctx);
|
|
||||||
assert.equal(h.folders.getFolders().has('Dossier'), false);
|
|
||||||
assert.equal(h.layer.currentFolder, null);
|
|
||||||
assert.equal(h.layer.entries().length, 3);
|
|
||||||
assert.equal(h.deleted.length, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
test('legacy folders with removed apps disappear while explicit empty folders remain', async () => {
|
|
||||||
const h = launcherFixture();
|
|
||||||
h.folders.setAppFolder('a', 'Legacy');
|
|
||||||
await h.layer.openEntry(h.layer.entries().find(entry => entry.kind === 'folder'));
|
|
||||||
h.apps.splice(0, 1);
|
|
||||||
assert.deepEqual(plain(h.layer.entries().map(entry => entry.appId)), ['b', 'c']);
|
|
||||||
assert.equal(h.layer.currentFolder, null);
|
|
||||||
h.folders.createFolder('Empty');
|
|
||||||
await h.layer.openEntry(h.layer.entries().find(entry => entry.kind === 'folder'));
|
|
||||||
assert.equal(h.layer.entries().length, 0);
|
|
||||||
assert.equal(h.layer.currentFolder, 'Empty');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('removing the source during a move cancels without launching or corrupting order', async () => {
|
|
||||||
const h = launcherFixture(); h.settings.launcherLayoutSetting.set('custom');
|
|
||||||
h.layer.grid.selectIndex(0); h.choose('Move icon');
|
|
||||||
h.apps.splice(0, 1);
|
|
||||||
await h.layer.openEntry(h.layer.entries()[0]);
|
|
||||||
assert.equal(h.layer.moving, null);
|
|
||||||
assert.equal(h.launches.length, 0);
|
|
||||||
assert.deepEqual(plain(h.layer.entries().map(entry => entry.appId)), ['b', 'c']);
|
|
||||||
});
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
const test = require('node:test');
|
|
||||||
const assert = require('node:assert/strict');
|
|
||||||
const fs = require('node:fs');
|
|
||||||
const vm = require('node:vm');
|
|
||||||
const ts = require('typescript');
|
|
||||||
|
|
||||||
function fixture() {
|
|
||||||
const source = ts.createSourceFile('shell.ts', fs.readFileSync('app/ui/shell/shell.ts', 'utf8'), ts.ScriptTarget.Latest, true);
|
|
||||||
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'Shell');
|
|
||||||
const names = new Set(['moveSwitcherWindow', 'openSwitcherMoveMenu', 'switcherWindows', 'foregroundWindow',
|
|
||||||
'openEscapeMenu', 'registerWindow', 'removeWindow', 'noteWindowVisible', 'mostRecentWindowIndex']);
|
|
||||||
const methods = cls.members.filter(n => names.has(n.name?.getText(source)));
|
|
||||||
assert.equal(methods.length, names.size);
|
|
||||||
const overlay = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'ShellOverlayMenuLayer');
|
|
||||||
class MenuLayer {
|
|
||||||
constructor(title, items) { this.title = title; this.items = items; }
|
|
||||||
selectItem(index) { this.selectedIndex = index; }
|
|
||||||
}
|
|
||||||
const context = { exports: {}, MenuLayer, appViewportRect: () => ({ x: 0, y: 0, width: 576 }),
|
|
||||||
CONTEXT_MENU_DIM: 0.5, brightnessSetting: { get: () => 'auto' }, makeInputEvent: e => e,
|
|
||||||
appFullscreenSetting: () => ({ get: () => false }), appKeepAwakeSetting: () => ({ label: 'Keep screen awake' }),
|
|
||||||
toggleSettingMenuItem: setting => ({ label: setting.label }),
|
|
||||||
swapMenuGesturesSetting: { get: () => false }, GESTURE_SHORT_THEN_LONG_PRESS: 'tap-hold',
|
|
||||||
};
|
|
||||||
vm.runInNewContext(ts.transpileModule(`${overlay.getText(source)}\nexport class Shell { ${methods.map(n => n.getText(source)).join('\n')} }`, {
|
|
||||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
||||||
}).outputText, context);
|
|
||||||
const s = new context.exports.Shell();
|
|
||||||
const foregroundCalls = [], closed = [], input = [];
|
|
||||||
const window = (windowId, appId = windowId, closeable = true, title = windowId) => ({
|
|
||||||
windowId, appId, closeable, title, requestRender() {},
|
|
||||||
setForeground: value => foregroundCalls.push([windowId, value]),
|
|
||||||
close: () => closed.push(windowId), handleInput: event => input.push([windowId, event.type]),
|
|
||||||
});
|
|
||||||
const launcher = window('launcher', 'launcher', false, 'Apps');
|
|
||||||
const first = window('terminal:one', 'terminal', true, 'Terminal');
|
|
||||||
const second = window('terminal:two', 'terminal', true, 'Terminal');
|
|
||||||
const third = window('calendar', 'calendar', true, 'Calendar');
|
|
||||||
const layers = [];
|
|
||||||
let changed = 0, renders = 0;
|
|
||||||
Object.assign(s, {
|
|
||||||
windows: [launcher, first, second, third], selectedIndex: 1, focus: 'sidebar', screenOn: true,
|
|
||||||
attention: new Map(), mruWindowIds: ['terminal:one', 'calendar', 'terminal:two', 'launcher'],
|
|
||||||
config: { voiceInputEnabled: false, onWindowsChanged: () => changed++, requestShellRender: () => renders++ },
|
|
||||||
yieldFocusToSidebar() { this.focus = 'sidebar'; },
|
|
||||||
stack: { isAtBase: () => !layers.length, push: layer => layers.push(layer),
|
|
||||||
pop: () => layers.pop()?.onRemoved?.() },
|
|
||||||
});
|
|
||||||
return { s, launcher, first, second, third, window, foregroundCalls, closed, input,
|
|
||||||
ids: () => Array.from(s.windows, w => w.windowId), changed: () => changed, renders: () => renders,
|
|
||||||
menu: () => layers.at(-1), choose(label) {
|
|
||||||
const item = layers.at(-1).items.find(item => item.label === label);
|
|
||||||
assert.ok(item, label); item.onSelect({ stack: s.stack });
|
|
||||||
} };
|
|
||||||
}
|
|
||||||
|
|
||||||
test('moving open windows in either direction keeps foreground, MRU and pinned launcher stable', () => {
|
|
||||||
const h = fixture(); h.s.focus = 'window';
|
|
||||||
const mru = Array.from(h.s.mruWindowIds);
|
|
||||||
assert.equal(h.s.moveSwitcherWindow(h.first.windowId, h.third.windowId), true);
|
|
||||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:two', 'calendar', 'terminal:one']);
|
|
||||||
assert.equal(h.s.foregroundWindow(), h.first);
|
|
||||||
assert.equal(h.s.selectedIndex, 3);
|
|
||||||
assert.equal(h.s.focus, 'window');
|
|
||||||
assert.deepEqual(Array.from(h.s.mruWindowIds), mru);
|
|
||||||
assert.deepEqual(h.foregroundCalls, []);
|
|
||||||
assert.deepEqual(h.closed, []);
|
|
||||||
assert.equal(h.changed(), 1); assert.equal(h.renders(), 1);
|
|
||||||
assert.equal(h.s.moveSwitcherWindow(h.first.windowId, h.second.windowId), true);
|
|
||||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:one', 'terminal:two', 'calendar']);
|
|
||||||
assert.equal(h.s.foregroundWindow(), h.first);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('system menu opens a numbered position picker and moves the captured window, even with duplicate titles', () => {
|
|
||||||
const h = fixture();
|
|
||||||
h.s.openEscapeMenu(); h.choose('Move in app switcher');
|
|
||||||
assert.equal(h.menu().title, 'Move app to position');
|
|
||||||
assert.deepEqual(Array.from(h.menu().items, item => item.label), ['1. Terminal', '2. Terminal', '3. Calendar']);
|
|
||||||
assert.equal(h.menu().selectedIndex, 0);
|
|
||||||
// A delayed focus change must not move a different app than the menu captured.
|
|
||||||
h.s.selectedIndex = 2;
|
|
||||||
h.choose('3. Calendar');
|
|
||||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:two', 'calendar', 'terminal:one']);
|
|
||||||
assert.equal(h.s.foregroundWindow(), h.second);
|
|
||||||
assert.equal(h.menu(), undefined);
|
|
||||||
assert.equal(h.s.focus, 'sidebar');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cancelling the picker and choosing the current slot leave ordering unchanged', () => {
|
|
||||||
const h = fixture(); const before = h.ids();
|
|
||||||
h.s.openSwitcherMoveMenu(h.first.windowId); h.s.stack.pop();
|
|
||||||
assert.deepEqual(h.ids(), before);
|
|
||||||
h.s.openSwitcherMoveMenu(h.first.windowId); h.choose('1. Terminal');
|
|
||||||
assert.deepEqual(h.ids(), before);
|
|
||||||
assert.equal(h.changed(), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('closing the pending source or destination prevents a stale move from affecting another window', () => {
|
|
||||||
for (const removed of ['terminal:one', 'calendar']) {
|
|
||||||
const h = fixture(); h.s.openSwitcherMoveMenu(h.first.windowId);
|
|
||||||
h.s.removeWindow(removed);
|
|
||||||
const afterClose = h.ids();
|
|
||||||
h.choose('3. Calendar');
|
|
||||||
assert.deepEqual(h.ids(), afterClose);
|
|
||||||
assert.equal(h.menu(), undefined);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('temporary status windows and pinned slots stay fixed, including selected status foreground', () => {
|
|
||||||
const h = fixture();
|
|
||||||
const hidden = h.window('notifications:temporary');
|
|
||||||
const pinned = h.window('another-pinned', 'pinned', false);
|
|
||||||
h.s.windows.splice(2, 0, hidden, pinned);
|
|
||||||
h.s.selectedIndex = 2;
|
|
||||||
h.s.selectedStatus = { transient: true, host: hidden, item: { key: 'notification' } };
|
|
||||||
assert.equal(h.s.moveSwitcherWindow(hidden.windowId, h.first.windowId), false);
|
|
||||||
h.s.moveSwitcherWindow(h.first.windowId, h.third.windowId);
|
|
||||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:two', 'notifications:temporary', 'another-pinned', 'calendar', 'terminal:one']);
|
|
||||||
assert.equal(h.s.foregroundWindow(), hidden);
|
|
||||||
assert.equal(h.s.selectedStatus.host, hidden);
|
|
||||||
h.s.openEscapeMenu();
|
|
||||||
assert.ok(!h.menu().items.some(item => item.label === 'Move in app switcher'));
|
|
||||||
h.s.stack.pop();
|
|
||||||
h.s.openSwitcherMoveMenu(h.first.windowId);
|
|
||||||
assert.deepEqual(Array.from(h.menu().items, item => item.label), ['1. Terminal', '2. Calendar', '3. Terminal']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('new windows append, replacements keep their slot, and closing uses unchanged recency after a move', () => {
|
|
||||||
const h = fixture(); h.s.moveSwitcherWindow(h.first.windowId, h.third.windowId);
|
|
||||||
h.s.registerWindow(h.window('new'));
|
|
||||||
assert.equal(h.ids().at(-1), 'new');
|
|
||||||
const replacement = h.window(h.second.windowId, 'terminal', true, 'Renamed session');
|
|
||||||
h.s.registerWindow(replacement);
|
|
||||||
assert.equal(h.s.windows[1], replacement);
|
|
||||||
assert.equal(h.s.foregroundWindow(), h.first);
|
|
||||||
h.s.removeWindow(h.first.windowId);
|
|
||||||
assert.equal(h.s.foregroundWindow(), h.third);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('pinned, missing, single-window, screen-off and overlay cases cannot start a reorder', () => {
|
|
||||||
const h = fixture(); const before = h.ids();
|
|
||||||
for (const [from, to] of [['launcher', 'calendar'], ['calendar', 'launcher'], ['missing', 'calendar']]) {
|
|
||||||
assert.equal(h.s.moveSwitcherWindow(from, to), false);
|
|
||||||
}
|
|
||||||
h.s.openSwitcherMoveMenu('missing'); assert.equal(h.menu(), undefined);
|
|
||||||
h.s.screenOn = false; h.s.openSwitcherMoveMenu(h.first.windowId); assert.equal(h.menu(), undefined);
|
|
||||||
h.s.screenOn = true; h.s.stack.push({});
|
|
||||||
h.s.openSwitcherMoveMenu(h.first.windowId); assert.equal(h.menu().title, undefined); h.s.stack.pop();
|
|
||||||
assert.deepEqual(h.ids(), before);
|
|
||||||
h.s.selectedIndex = 0; h.s.openEscapeMenu();
|
|
||||||
assert.ok(!h.menu().items.some(item => item.label === 'Move in app switcher')); h.s.stack.pop();
|
|
||||||
h.s.windows = [h.launcher, h.first]; h.s.selectedIndex = 1; h.s.openEscapeMenu();
|
|
||||||
assert.ok(!h.menu().items.some(item => item.label === 'Move in app switcher'));
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user