forked from Blendman974/faceclaw
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8be15d890c
|
||
|
|
c22f2e5f13
|
||
|
|
dded80a850
|
No files matched your search
-12
@@ -504,18 +504,6 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun dismissAllNotifications(): Boolean {
|
||||
val service = activeService ?: return false
|
||||
return try {
|
||||
service.cancelAllNotifications()
|
||||
true
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "failed to dismiss all notifications", t)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun emitNotificationPosted(key: String?) {
|
||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) }
|
||||
}
|
||||
|
||||
@@ -8,7 +8,11 @@ import { IconGrid, ICON_GRID_BAND_INSET_X, ICON_GRID_HIGHLIGHT_INSET_Y, ICON_GRI
|
||||
import { Layer, LayerActions, LayerContext } from "../../ui/layers";
|
||||
import { MenuLayer, type MenuItem } from "../../ui/menu";
|
||||
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
|
||||
import { onAnySettingChanged } from "../../ui/dashboard-settings";
|
||||
import {
|
||||
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 {
|
||||
getFolderAssignments,
|
||||
@@ -16,6 +20,7 @@ import {
|
||||
getFolderStateFingerprint,
|
||||
setAppFolder,
|
||||
unusedNewFolderName,
|
||||
getExplicitFolderNames, createFolder, renameFolder, folderNameError, disbandFolder,
|
||||
} from "./launcher-folders";
|
||||
import { shell, type ShellWindow } from "../../ui/shell/shell";
|
||||
|
||||
@@ -66,6 +71,14 @@ type LauncherGridEntry =
|
||||
* and is re-read every paint, so assistant folder tools take effect without
|
||||
* 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 {
|
||||
// Watch swipes are spatial: up/down move between rows, left/right between
|
||||
// columns. From the leftmost column, left keeps going out: it leaves the
|
||||
@@ -74,6 +87,12 @@ class LauncherGridLayer implements Layer {
|
||||
readonly acceptsDirectional = true;
|
||||
/** Folder whose contents the grid is showing, or null for the top grid. */
|
||||
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>({
|
||||
items: () => this.entries(),
|
||||
describe: (entry) => ({
|
||||
@@ -104,25 +123,23 @@ class LauncherGridLayer implements Layer {
|
||||
const members = (getFolders().get(this.currentFolder) ?? [])
|
||||
.map((appId) => byAppId.get(appId))
|
||||
.filter(Boolean) as LauncherAppEntry[];
|
||||
if (members.length > 0) {
|
||||
return members
|
||||
.map((app): LauncherGridEntry => ({
|
||||
if (members.length > 0 || getExplicitFolderNames().includes(this.currentFolder)) {
|
||||
return this.sortEntries(members.map((app): LauncherGridEntry => ({
|
||||
kind: "app",
|
||||
label: app.label,
|
||||
icon: app.icon,
|
||||
appId: app.appId,
|
||||
renderIcon: app.renderIcon,
|
||||
}))
|
||||
.sort((a, b) => a.label.localeCompare(b.label));
|
||||
})));
|
||||
}
|
||||
this.currentFolder = null;
|
||||
}
|
||||
const assignments = getFolderAssignments();
|
||||
const entries: LauncherGridEntry[] = [];
|
||||
// A folder cell appears only when it holds at least one known app; stale
|
||||
// assignments to removed apps are ignored.
|
||||
// Legacy folders need a known member; explicitly created folders may be empty.
|
||||
const explicit = new Set(getExplicitFolderNames());
|
||||
for (const [name, members] of getFolders()) {
|
||||
if (members.some((appId) => byAppId.has(appId))) {
|
||||
if (explicit.has(name) || members.some((appId) => byAppId.has(appId))) {
|
||||
entries.push({ kind: "folder", label: name, name });
|
||||
}
|
||||
}
|
||||
@@ -137,7 +154,7 @@ class LauncherGridLayer implements Layer {
|
||||
});
|
||||
}
|
||||
}
|
||||
return entries.sort((a, b) => a.label.localeCompare(b.label));
|
||||
return this.sortEntries(entries);
|
||||
}
|
||||
|
||||
/** Leave the current folder, putting the selection back on its cell. */
|
||||
@@ -151,6 +168,16 @@ class LauncherGridLayer implements Layer {
|
||||
|
||||
/** Enter a folder or launch an app; true when that left the grid (a launch). */
|
||||
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") {
|
||||
this.currentFolder = entry.name;
|
||||
this.grid.resetSelection();
|
||||
@@ -166,6 +193,13 @@ class LauncherGridLayer implements Layer {
|
||||
|
||||
/** Leave the open folder, else yield to the sidebar; true when that left the grid. */
|
||||
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) {
|
||||
this.exitFolder();
|
||||
return false;
|
||||
@@ -175,14 +209,54 @@ class LauncherGridLayer implements Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* App-specific entries for the window's context menu. Only item mode
|
||||
* 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.
|
||||
* Layout and folder creation are always available. Per-icon actions need
|
||||
* item mode so row navigation never edits an ambiguous selection.
|
||||
*/
|
||||
menuItems(): MenuItem[] {
|
||||
if (this.editingFolder) return [];
|
||||
const entry = this.grid.selectedItem;
|
||||
if (!entry || entry.kind !== "app") return [];
|
||||
return [
|
||||
const items: MenuItem[] = [
|
||||
enumSettingMenuItem(launcherLayoutSetting, { onChange: () => { this.moving = null; this.grid.resetSelection(); } }),
|
||||
{
|
||||
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",
|
||||
onSelect: (ctx) => {
|
||||
@@ -221,6 +295,32 @@ 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,
|
||||
* plus a generated-name "New folder" (ring input has no text entry) and,
|
||||
@@ -242,7 +342,9 @@ class LauncherGridLayer implements Layer {
|
||||
items.push({
|
||||
label: "New folder",
|
||||
onSelect: (ctx) => {
|
||||
setAppFolder(appId, unusedNewFolderName());
|
||||
const name = unusedNewFolderName();
|
||||
createFolder(name);
|
||||
setAppFolder(appId, name);
|
||||
ctx.stack.pop();
|
||||
},
|
||||
});
|
||||
@@ -263,8 +365,16 @@ class LauncherGridLayer implements Layer {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
// The folder-name header band scales with the font.
|
||||
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : ROOT_GRID_TOP;
|
||||
if (this.currentFolder !== null) {
|
||||
const entries = this.entries();
|
||||
if (this.moving && (launcherLayoutSetting.get() !== "custom" || this.moving.folder !== this.currentFolder ||
|
||||
!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);
|
||||
}
|
||||
// The grid runs to the window's bottom edge, so a row cut off there for
|
||||
@@ -274,6 +384,7 @@ class LauncherGridLayer implements Layer {
|
||||
}
|
||||
|
||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
if (this.moving && event.type === "double-click") { this.back(); return; }
|
||||
await this.grid.handleInput(event, ctx);
|
||||
}
|
||||
|
||||
@@ -311,9 +422,9 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
|
||||
// keeps every unrelated setting change from repainting the launcher. The
|
||||
// launcher is pinned for the app's lifetime, so the subscription never needs
|
||||
// tearing down.
|
||||
let lastState = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||
let lastState = `${getFolderStateFingerprint()}\n${getLauncherLayoutFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||
onAnySettingChanged(() => {
|
||||
const state = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||
const state = `${getFolderStateFingerprint()}\n${getLauncherLayoutFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||
if (state === lastState) return;
|
||||
lastState = state;
|
||||
created.requestRender();
|
||||
|
||||
@@ -1,14 +1,50 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/** Launcher assignments keep their legacy format; explicitly created folders may be empty. */
|
||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||
|
||||
import { renameLauncherFolderOrder, removeLauncherFolderOrder } from "./launcher-layout";
|
||||
|
||||
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. */
|
||||
const DEFAULT_ASSIGNMENTS: Record<string, string> = {
|
||||
@@ -32,7 +68,7 @@ export function getFolderAssignments(): Record<string, string> {
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
||||
const assignments: Record<string, string> = {};
|
||||
const assignments: Record<string, string> = Object.create(null);
|
||||
for (const appId of Object.keys(parsed)) {
|
||||
const folder = parsed[appId];
|
||||
if (typeof folder === "string" && folder.trim()) {
|
||||
@@ -58,6 +94,7 @@ export function getFolders(): Map<string, string[]> {
|
||||
unsorted.set(folder, [appId]);
|
||||
}
|
||||
}
|
||||
for (const name of getExplicitFolderNames()) if (!unsorted.has(name)) unsorted.set(name, []);
|
||||
const folders = new Map<string, string[]>();
|
||||
for (const name of Array.from(unsorted.keys()).sort((a, b) => a.localeCompare(b))) {
|
||||
folders.set(name, unsorted.get(name)!);
|
||||
@@ -86,6 +123,8 @@ export function disbandFolder(folder: string): number {
|
||||
moved++;
|
||||
}
|
||||
}
|
||||
setStringSetting(NAMES_KEY, JSON.stringify(getExplicitFolderNames().filter(name => name !== folder)));
|
||||
removeLauncherFolderOrder(folder);
|
||||
if (moved > 0) {
|
||||
setStringSetting(STORAGE_KEY, JSON.stringify(assignments));
|
||||
}
|
||||
@@ -95,7 +134,7 @@ export function disbandFolder(folder: string): number {
|
||||
/**
|
||||
* 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;
|
||||
* the assistant's folder tools can regroup the apps under a better one.
|
||||
* Rename folder uses the existing phone text editor for a custom name.
|
||||
*/
|
||||
export function unusedNewFolderName(): string {
|
||||
const existing = new Set(Array.from(getFolders().keys()).map((name) => name.toLowerCase()));
|
||||
@@ -119,5 +158,6 @@ export function resolveFolderName(input: string): string {
|
||||
|
||||
/** Raw stored value, for cheap change detection by the launcher window. */
|
||||
export function getFolderStateFingerprint(): string {
|
||||
return getStringSetting(STORAGE_KEY, "");
|
||||
return JSON.stringify([getStringSetting(STORAGE_KEY, ""), getStringSetting(NAMES_KEY, ""),
|
||||
getStringSetting("launcher.folderNameDraft", "")]);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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, "")]);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NotificationsListLayer } from "../../ui/notifications";
|
||||
import { NotificationFilterLayer } from "../../ui/notification-filter";
|
||||
import { ALL_NOTIFICATIONS, dismissAllNotifications, onAndroidNotificationsChanged, readActiveNotifications } from "../../native/notification-icons";
|
||||
import { onAndroidNotificationsChanged } from "../../native/notification-icons";
|
||||
import {
|
||||
createInProcessWindow,
|
||||
YieldAtRootLayer,
|
||||
@@ -32,15 +32,6 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr
|
||||
ctx.stack.pop();
|
||||
ctx.stack.push(new NotificationFilterLayer());
|
||||
},
|
||||
}, {
|
||||
label: "Dismiss all notifications",
|
||||
description: "Dismiss notifications on the phone and glasses. System-protected notifications may remain.",
|
||||
disabled: () => readActiveNotifications(ALL_NOTIFICATIONS).length === 0,
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.pop();
|
||||
dismissAllNotifications();
|
||||
created.requestRender();
|
||||
},
|
||||
}],
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new NotificationsListLayer()),
|
||||
|
||||
@@ -191,7 +191,7 @@ function registerTools(options: WindowToolsOptions, registry: ToolRegistry): voi
|
||||
const lines: string[] = [];
|
||||
for (const [name, members] of getFolders()) {
|
||||
const known = members.filter((appId) => appIds.indexOf(appId) >= 0).sort();
|
||||
if (known.length) lines.push(`${name}: ${known.map(describeApp).join(", ")}`);
|
||||
if (known.length || members.length === 0) lines.push(`${name}: ${known.length ? known.map(describeApp).join(", ") : "(empty)"}`);
|
||||
}
|
||||
const assignments = getFolderAssignments();
|
||||
const ungrouped = appIds.filter((appId) => !assignments[appId]);
|
||||
@@ -237,7 +237,7 @@ function registerTools(options: WindowToolsOptions, registry: ToolRegistry): voi
|
||||
{
|
||||
name: "apps.remove_from_folder",
|
||||
description:
|
||||
"Move an app out of its launcher folder back to the top-level grid. A folder disappears when its last app is removed.",
|
||||
"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.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
@@ -276,8 +276,9 @@ function registerTools(options: WindowToolsOptions, registry: ToolRegistry): voi
|
||||
(args) => {
|
||||
const folder = resolveFolderName(String(args?.folder ?? ""));
|
||||
if (!folder) return err("folder must be a non-empty name");
|
||||
const existed = getFolders().has(folder);
|
||||
const moved = disbandFolder(folder);
|
||||
if (moved === 0) {
|
||||
if (moved === 0 && !existed) {
|
||||
const names = Array.from(getFolders().keys());
|
||||
return err(
|
||||
names.length
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { GrayImage } from '../graphics/image'
|
||||
import { pebbleIcon } from '../graphics/pebble-icons'
|
||||
import { AncsClient, ANCS_CONNECT_MESSAGE, type AncsState } from '../g2/ancs-client'
|
||||
import { notificationAppIcon, notificationCategoryIcon } from './notification-app-icons'
|
||||
import { rememberNotificationSources, shouldShowNotificationOnGlasses } from './notification-sources'
|
||||
import { rememberNotificationSources } from './notification-sources'
|
||||
import type { AndroidNotification } from './notification-types'
|
||||
export type { AndroidNotification, AndroidNotificationAction } from './notification-types'
|
||||
export type { NotificationIconsResult, NotificationIconResult, NotificationImageResult } from './notification-icons'
|
||||
@@ -24,23 +24,8 @@ export function onIosNotificationPopup(listener: (key: string) => void): () => v
|
||||
export function iosNotificationMessage(): string { return active?.statusMessage ?? ANCS_CONNECT_MESSAGE }
|
||||
export function iosNotificationState(): AncsState { return active?.state ?? 'disconnected' }
|
||||
export function readActiveNotifications(maxNotifications = 50) { return active?.read(maxNotifications) ?? [] }
|
||||
export function readVisibleNotifications(maxNotifications = 50) {
|
||||
return readActiveNotifications(ALL_NOTIFICATIONS)
|
||||
.filter(notification => shouldShowNotificationOnGlasses(notification.packageName))
|
||||
.slice(0, Math.max(0, maxNotifications))
|
||||
}
|
||||
export function invokeNotificationAction(key: string, index: number): boolean { return active?.action(key,index) ?? false }
|
||||
export function dismissNotification(key: string): boolean { return active?.dismiss(key) ?? false }
|
||||
export function dismissAllNotifications(): boolean {
|
||||
const client = active
|
||||
if (!client) return false
|
||||
// Snapshot: removals may arrive while dismissal requests are being sent.
|
||||
let accepted = true
|
||||
for (const notification of [...client.read(ALL_NOTIFICATIONS)]) {
|
||||
if (!client.dismiss(notification.key)) accepted = false
|
||||
}
|
||||
return accepted
|
||||
}
|
||||
export function onAndroidNotificationPosted(listener: (key: string) => void): () => void {
|
||||
listeners.add(listener); return () => { listeners.delete(listener) }
|
||||
}
|
||||
@@ -59,7 +44,7 @@ function notificationIcon(notification: AndroidNotification): GrayImage {
|
||||
export function readActiveNotificationIcons(maxIcons: number, _allowStale: boolean) {
|
||||
// One icon per source, standing for its first notification.
|
||||
const sources = new Map<string, AndroidNotification>()
|
||||
for (const n of readVisibleNotifications(ALL_NOTIFICATIONS)) if (!sources.has(n.packageName)) sources.set(n.packageName, n)
|
||||
for (const n of readActiveNotifications(ALL_NOTIFICATIONS)) if (!sources.has(n.packageName)) sources.set(n.packageName, n)
|
||||
const shown = Array.from(sources.values()).slice(0,Math.max(0,maxIcons))
|
||||
return {icons: shown.map(notificationIcon),keys: shown.map(n => n.key),stale:false}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { GrayImage } from "../graphics/image";
|
||||
import { logCurrent, spanCurrent } from "./frame-timings";
|
||||
import { toUint8Array } from "../util/array-util";
|
||||
import { rememberNotificationSources, shouldShowNotificationOnGlasses } from "./notification-sources";
|
||||
import { rememberNotificationSources } from "./notification-sources";
|
||||
import { PHOTO_TONE, grayImageFromPacket } from "./image-files";
|
||||
import { NOTIFICATION_ICON_SIZE } from "./notification-types";
|
||||
|
||||
@@ -21,7 +21,6 @@ const ICON_CACHE_MS = 60_000;
|
||||
|
||||
let cachedIcons: GrayImage[] = [];
|
||||
let cachedKeys: string[] = [];
|
||||
let cachedPackages = new Map<string, string>();
|
||||
let cachedAtMs = 0;
|
||||
const keyedIconCache = new Map<string, { icon: GrayImage | null; atMs: number }>();
|
||||
const KEYED_ICON_CACHE_MAX = 128;
|
||||
@@ -96,7 +95,6 @@ export function readActiveNotificationIcons(maxIcons: number, allowStale: boolea
|
||||
keys.push(index < keyList.size() ? String(keyList.get(index)) : "");
|
||||
}
|
||||
|
||||
cachedPackages = new Map(readActiveNotifications(ALL_NOTIFICATIONS).map(n => [n.key, n.packageName]));
|
||||
cachedIcons = icons;
|
||||
cachedKeys = keys;
|
||||
cachedAtMs = now;
|
||||
@@ -105,12 +103,7 @@ export function readActiveNotificationIcons(maxIcons: number, allowStale: boolea
|
||||
|
||||
/** Copies of the first maxIcons cached icons, with their keys. */
|
||||
function cachedIconsResult(maxIcons: number, stale: boolean): NotificationIconsResult {
|
||||
// Reapply preferences even to a warm/stale cache: toggles take effect immediately.
|
||||
const indices = cachedKeys.map((_, index) => index).filter(index => {
|
||||
const packageName = cachedPackages.get(cachedKeys[index]!);
|
||||
return packageName !== undefined && shouldShowNotificationOnGlasses(packageName);
|
||||
}).slice(0, maxIcons);
|
||||
return { icons: indices.map(index => cachedIcons[index]!.clone()), keys: indices.map(index => cachedKeys[index]!), stale };
|
||||
return { icons: cachedIcons.slice(0, maxIcons).map(icon => icon.clone()), keys: cachedKeys.slice(0, maxIcons), stale };
|
||||
}
|
||||
|
||||
export type NotificationIconResult = {
|
||||
@@ -325,13 +318,6 @@ export function readActiveNotifications(maxNotifications = 50): AndroidNotificat
|
||||
}
|
||||
}
|
||||
|
||||
/** Glasses display only; discover all sources and filter before the display limit. */
|
||||
export function readVisibleNotifications(maxNotifications = 50): AndroidNotification[] {
|
||||
return readActiveNotifications(ALL_NOTIFICATIONS)
|
||||
.filter(notification => shouldShowNotificationOnGlasses(notification.packageName))
|
||||
.slice(0, Math.max(0, maxNotifications));
|
||||
}
|
||||
|
||||
export function invokeNotificationAction(notificationKey: string, actionIndex: number): boolean {
|
||||
if (!global.isAndroid || !notificationKey) return false;
|
||||
invalidateIconCaches();
|
||||
@@ -351,13 +337,6 @@ export function dismissNotification(notificationKey: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
/** Explicit user action: dismiss on the phone as well as on the glasses. */
|
||||
export function dismissAllNotifications(): boolean {
|
||||
if (!global.isAndroid) return false;
|
||||
invalidateIconCaches();
|
||||
return Boolean(com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissAllNotifications());
|
||||
}
|
||||
|
||||
export function onAndroidNotificationPosted(listener: (notificationKey: string) => void): () => void {
|
||||
return addNotificationListener(notificationPostedListeners, listener);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
import { getStringSetting, setStringSetting } from "./settings-store";
|
||||
|
||||
const SOURCES_KEY = "notifications.sources";
|
||||
const DEFAULT_KEY = "notifications.newAppsEnabledByDefault";
|
||||
|
||||
/** Unset preserves the behavior of existing installations. */
|
||||
export function newNotificationAppsEnabledByDefault(): boolean {
|
||||
return getStringSetting(DEFAULT_KEY, "true") !== "false";
|
||||
}
|
||||
|
||||
export function setNewNotificationAppsEnabledByDefault(enabled: boolean): void {
|
||||
setStringSetting(DEFAULT_KEY, String(enabled));
|
||||
}
|
||||
|
||||
export type NotificationSource = {
|
||||
packageName: string;
|
||||
@@ -18,15 +8,8 @@ export type NotificationSource = {
|
||||
showOnGlasses: boolean;
|
||||
};
|
||||
|
||||
type SavedSource = Omit<NotificationSource, "showOnGlasses"> & { showOnGlasses?: boolean };
|
||||
|
||||
/** Sources outlive their active notifications so a muted app can always be re-enabled. */
|
||||
export function readNotificationSources(): NotificationSource[] {
|
||||
const enabled = newNotificationAppsEnabledByDefault();
|
||||
return readSavedSources().map((source) => ({ ...source, showOnGlasses: source.showOnGlasses ?? enabled }));
|
||||
}
|
||||
|
||||
function readSavedSources(): SavedSource[] {
|
||||
try {
|
||||
const parsed = JSON.parse(getStringSetting(SOURCES_KEY, "[]"));
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
@@ -34,7 +17,7 @@ function readSavedSources(): SavedSource[] {
|
||||
.map((source) => ({
|
||||
packageName: source.packageName,
|
||||
appName: typeof source.appName === "string" && source.appName ? source.appName : source.packageName,
|
||||
showOnGlasses: typeof source.showOnGlasses === "boolean" ? source.showOnGlasses : undefined,
|
||||
showOnGlasses: source.showOnGlasses !== false,
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
@@ -42,7 +25,7 @@ function readSavedSources(): SavedSource[] {
|
||||
}
|
||||
|
||||
export function rememberNotificationSources(notifications: { packageName: string; appName: string }[]): void {
|
||||
const sources = new Map(readSavedSources().map((source) => [source.packageName, source]));
|
||||
const sources = new Map(readNotificationSources().map((source) => [source.packageName, source]));
|
||||
let changed = false;
|
||||
for (const notification of notifications) {
|
||||
if (!notification.packageName) continue;
|
||||
@@ -52,7 +35,7 @@ export function rememberNotificationSources(notifications: { packageName: string
|
||||
sources.set(notification.packageName, {
|
||||
packageName: notification.packageName,
|
||||
appName,
|
||||
showOnGlasses: previous?.showOnGlasses,
|
||||
showOnGlasses: previous?.showOnGlasses ?? true,
|
||||
});
|
||||
changed = true;
|
||||
}
|
||||
@@ -61,13 +44,12 @@ export function rememberNotificationSources(notifications: { packageName: string
|
||||
}
|
||||
|
||||
export function shouldShowNotificationOnGlasses(packageName: string): boolean {
|
||||
return readNotificationSources().find((source) => source.packageName === packageName)?.showOnGlasses
|
||||
?? newNotificationAppsEnabledByDefault();
|
||||
return readNotificationSources().find((source) => source.packageName === packageName)?.showOnGlasses ?? true;
|
||||
}
|
||||
|
||||
export function setNotificationSourceEnabled(source: { packageName: string; appName: string }, enabled: boolean): void {
|
||||
if (!source.packageName) return;
|
||||
const sources = new Map(readSavedSources().map((item) => [item.packageName, item]));
|
||||
const sources = new Map(readNotificationSources().map((item) => [item.packageName, item]));
|
||||
sources.set(source.packageName, {
|
||||
packageName: source.packageName,
|
||||
appName: source.appName || source.packageName,
|
||||
@@ -75,10 +57,3 @@ export function setNotificationSourceEnabled(source: { packageName: string; appN
|
||||
});
|
||||
setStringSetting(SOURCES_KEY, JSON.stringify(Array.from(sources.values())));
|
||||
}
|
||||
|
||||
/** Set explicit choices only for sources already discovered; leave the future default alone. */
|
||||
export function setAllNotificationSourcesEnabled(enabled: boolean): void {
|
||||
setStringSetting(SOURCES_KEY, JSON.stringify(readSavedSources().map((source) => ({
|
||||
...source, showOnGlasses: enabled,
|
||||
}))));
|
||||
}
|
||||
@@ -200,6 +200,13 @@ 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> & {
|
||||
editorTitle?: string;
|
||||
glassesEditTitle?: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { getDefaultSmallFont } from "../graphics/ui-fonts";
|
||||
import { GrayImage } from "../graphics/image";
|
||||
import { truncateText } from "../graphics/textwrap";
|
||||
import { ALL_NOTIFICATIONS, readActiveNotifications } from "../native/notification-icons";
|
||||
import { newNotificationAppsEnabledByDefault, setNewNotificationAppsEnabledByDefault, setAllNotificationSourcesEnabled, readNotificationSources, setNotificationSourceEnabled, shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
||||
import { readNotificationSources, setNotificationSourceEnabled, shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
||||
import { type InputEvent } from "./gestures";
|
||||
import { type Layer, type LayerContext, type PaintBelow } from "./layers";
|
||||
import { drawToggleMenuItem, MenuLayer, type MenuItem } from "./menu";
|
||||
@@ -11,26 +11,14 @@ import { drawToggleMenuItem, MenuLayer, type MenuItem } from "./menu";
|
||||
export class NotificationFilterLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
private menuWidth = 0;
|
||||
/** Stable row keys, including controls, parallel to the menu's items. */
|
||||
/** The package behind each current row, parallel to the menu's items. */
|
||||
private packages: string[] = [];
|
||||
|
||||
private currentMenu(ctx: LayerContext): MenuLayer {
|
||||
readActiveNotifications(ALL_NOTIFICATIONS);
|
||||
const sources = readNotificationSources().sort((a, b) =>
|
||||
a.appName.localeCompare(b.appName) || a.packageName.localeCompare(b.packageName));
|
||||
const items: MenuItem[] = [{
|
||||
label: "New apps enabled by default",
|
||||
onSelect: () => setNewNotificationAppsEnabledByDefault(!newNotificationAppsEnabledByDefault()),
|
||||
render: ({ image, x, y, width, selected }) => {
|
||||
const font = getDefaultSmallFont();
|
||||
drawToggleMenuItem(image, font, x, y, width,
|
||||
truncateText(font, "New apps enabled by default", width - 48), newNotificationAppsEnabledByDefault(), selected);
|
||||
},
|
||||
}, {
|
||||
label: "Enable all", onSelect: () => setAllNotificationSourcesEnabled(true),
|
||||
}, {
|
||||
label: "Disable all", onSelect: () => setAllNotificationSourcesEnabled(false),
|
||||
}, ...sources.map<MenuItem>((source) => ({
|
||||
const items: MenuItem[] = sources.map((source) => ({
|
||||
label: source.appName,
|
||||
onSelect: () => setNotificationSourceEnabled(source, !shouldShowNotificationOnGlasses(source.packageName)),
|
||||
render: ({ image, x, y, width, selected }) => {
|
||||
@@ -38,11 +26,11 @@ export class NotificationFilterLayer implements Layer {
|
||||
drawToggleMenuItem(image, font, x, y, width, truncateText(font, source.appName, width - 48),
|
||||
shouldShowNotificationOnGlasses(source.packageName), selected);
|
||||
},
|
||||
}))];
|
||||
if (!sources.length) items.push({ label: "No notification sources discovered yet.", disabled: true, onSelect: () => {} });
|
||||
}));
|
||||
if (!items.length) items.push({ label: "No notification sources discovered yet.", disabled: true, onSelect: () => {} });
|
||||
const selectedPackage = this.menu?.selectedIndex != null ? this.packages[this.menu.selectedIndex] : undefined;
|
||||
this.packages = ["default", "enable-all", "disable-all", ...sources.map((source) => `source:${source.packageName}`)];
|
||||
const index = selectedPackage === undefined ? 0 : this.packages.indexOf(selectedPackage);
|
||||
const index = sources.findIndex((source) => source.packageName === selectedPackage);
|
||||
this.packages = sources.map((source) => source.packageName);
|
||||
|
||||
const width = ctx.stack.getBaseSize().width;
|
||||
if (!this.menu || width !== this.menuWidth) {
|
||||
@@ -50,7 +38,7 @@ export class NotificationFilterLayer implements Layer {
|
||||
this.menu = new MenuLayer("Notification filter", items, {
|
||||
x: 8, y: 8, width: width - 16,
|
||||
opaque: true, showBorder: false,
|
||||
footer: "On = show notifications on glasses",
|
||||
footer: "On = show popups on glasses",
|
||||
}).selectItem(Math.max(0, index));
|
||||
} else {
|
||||
this.menu.setItems(items, index >= 0 ? index : undefined);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ALL_NOTIFICATIONS,
|
||||
dismissNotification,
|
||||
invokeNotificationAction,
|
||||
readVisibleNotifications,
|
||||
readActiveNotifications,
|
||||
readNotificationCustomView,
|
||||
readNotificationIconByKey,
|
||||
readNotificationLargeIcon,
|
||||
@@ -141,7 +141,7 @@ export class NotificationsListLayer implements Layer {
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const cardWidth = width - 2 * CARD_X;
|
||||
const cardTextWidth = cardWidth - CARD_TEXT_X - 14;
|
||||
const notifications = readVisibleNotifications(MAX_NOTIFICATIONS);
|
||||
const notifications = readActiveNotifications(MAX_NOTIFICATIONS);
|
||||
const selectedIndex = this.resolveSelectedIndex(notifications);
|
||||
const layouts = notifications.map((notification, index) =>
|
||||
buildNotificationCardLayout(font, notification, index === selectedIndex, cardTextWidth),
|
||||
@@ -185,7 +185,7 @@ export class NotificationsListLayer implements Layer {
|
||||
}
|
||||
|
||||
handleInput(event: InputEvent, ctx: LayerContext): void {
|
||||
const notifications = readVisibleNotifications(MAX_NOTIFICATIONS);
|
||||
const notifications = readActiveNotifications(MAX_NOTIFICATIONS);
|
||||
const selectedIndex = this.resolveSelectedIndex(notifications);
|
||||
if (event.type === "double-click") {
|
||||
// At the app's root this is intercepted by the yield wrapper; reached
|
||||
@@ -252,7 +252,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const notification = readVisibleNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
|
||||
if (!notification) {
|
||||
return this.closeUnavailableNotification(ctx, paintBelow);
|
||||
@@ -273,7 +273,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
else await menu.handleInput(event);
|
||||
return;
|
||||
}
|
||||
const notification = readVisibleNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||
if (!notification) {
|
||||
this.closeUnavailableNotification(ctx);
|
||||
return;
|
||||
@@ -297,7 +297,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
this.close(ctx);
|
||||
} else if (item.kind === "action") {
|
||||
invokeNotificationAction(this.notificationKey, item.action.index);
|
||||
if (!readVisibleNotifications(ALL_NOTIFICATIONS).some((active) => active.key === this.notificationKey)) {
|
||||
if (!readActiveNotifications(ALL_NOTIFICATIONS).some((active) => active.key === this.notificationKey)) {
|
||||
this.closeUnavailableNotification(ctx);
|
||||
}
|
||||
} else if (item.kind === "dismiss") {
|
||||
@@ -310,7 +310,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
menu: new Menu<ConfirmationItem>({
|
||||
items: [
|
||||
{ label: "Cancel", run: (runCtx) => this.close(runCtx) },
|
||||
{ label: "Hide on glasses", run: (runCtx) => {
|
||||
{ label: "Turn off popups", run: (runCtx) => {
|
||||
setNotificationSourceEnabled(notification, false);
|
||||
this.close(runCtx);
|
||||
} },
|
||||
@@ -341,7 +341,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
};
|
||||
menu.paint(image, menuBox, ctx.stack.isFocused());
|
||||
const top = menuBox.y + menuBox.height + CONFIRM_PROMPT_GAP;
|
||||
const prompt = `Hide notifications on glasses from ${source.appName || source.packageName}? You can turn them back on in the Notifications app's Notification filter.`;
|
||||
const prompt = `Turn off notification popups from ${source.appName || source.packageName}? You can turn them back on in the Notifications app's Notification filter.`;
|
||||
const lines = wrapText(font, prompt, width - 2 * CONFIRM_X);
|
||||
const maxLines = Math.max(1, Math.floor((height - top - 12) / lineStep(font)));
|
||||
for (let index = 0; index < Math.min(lines.length, maxLines); index++) {
|
||||
|
||||
+50
-2
@@ -326,7 +326,7 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
||||
*/
|
||||
keepWindowFocus = false;
|
||||
|
||||
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void) {
|
||||
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void, title = "System") {
|
||||
// Aligned to the min-height window band (like the sidebar), wherever the
|
||||
// vertical position setting currently puts it; centered over the
|
||||
// application area, i.e. the part of the screen beside a side strip
|
||||
@@ -334,7 +334,7 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
||||
// the strip overlays).
|
||||
const width = 272;
|
||||
const area = appViewportRect("min");
|
||||
super("System", items, {
|
||||
super(title, items, {
|
||||
x: area.x + (((area.width - width) / 2) | 0),
|
||||
y: area.y + 8,
|
||||
width,
|
||||
@@ -1304,6 +1304,43 @@ class Shell {
|
||||
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:
|
||||
* with a bottom switcher (the selection reaches them past the last
|
||||
@@ -1959,6 +1996,17 @@ class Shell {
|
||||
},
|
||||
}]),
|
||||
);
|
||||
const movableWindows = this.switcherWindows().filter(window => window.closeable);
|
||||
if (movableWindows.length > 1 && movableWindows.includes(foreground)) {
|
||||
items.push({
|
||||
label: "Move in app switcher",
|
||||
description: "Choose this open window's position in the app switcher.",
|
||||
onSelect: ctx => {
|
||||
ctx.stack.pop();
|
||||
this.openSwitcherMoveMenu(foreground.windowId);
|
||||
},
|
||||
});
|
||||
}
|
||||
if (brightnessSetting.get() !== "auto") {
|
||||
items.push({
|
||||
label: "Brightness",
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# Dismiss all notifications
|
||||
|
||||
The Notifications app menu offers Dismiss all notifications, disabled when the
|
||||
list is empty. This explicit action dismisses notifications on the phone too;
|
||||
popup filtering and source/default preferences remain independent.
|
||||
|
||||
Android uses NotificationListenerService.cancelAllNotifications, so dismissal
|
||||
is not limited to the 50 items displayed by the list and Android controls which
|
||||
notifications are removable. The normal removal callbacks update the list and
|
||||
popups. Missing listener access returns false without changing preferences.
|
||||
iOS uses the existing ANCS dismissal operation on a snapshot of all known keys;
|
||||
notifications without a negative action may remain.
|
||||
|
||||
Software tests cover menu action/disabled state, more than 50 notifications,
|
||||
native bridge dispatch, disconnected access and ANCS bulk dismissal.
|
||||
On a device, verify the permission-granted/revoked cases, protected or ongoing
|
||||
notifications, notification groups, and consistency with the phone's tray.
|
||||
Hardware validation remains pending.
|
||||
|
||||
Reference: https://developer.android.com/reference/android/service/notification/NotificationListenerService#cancelAllNotifications()
|
||||
@@ -0,0 +1,23 @@
|
||||
# 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.
|
||||
@@ -1,35 +0,0 @@
|
||||
# Notification filter validation
|
||||
|
||||
Software: `npm test` and `bash lint.sh app/native/notification-sources.ts app/ui/notification-filter.ts`.
|
||||
The notification suite covers legacy preferences, reloads of the settings store,
|
||||
discovery, default changes without overwriting exceptions, both bulk actions,
|
||||
empty lists, stable menu selection and popup suppression before wake.
|
||||
|
||||
Hardware validation (pending; no glasses tested):
|
||||
|
||||
1. On an existing installation, check that enabled and muted applications retain
|
||||
their behavior before touching the new default.
|
||||
2. Turn “New apps enabled by default” off; restart the app. Send a notification
|
||||
from a previously unknown package: it must appear in the filter and on the
|
||||
phone, without waking the glasses or showing a glasses popup.
|
||||
3. Enable that package individually; send another notification and check its popup.
|
||||
4. Change the default in both directions; verify individual exceptions survive.
|
||||
5. Use “Disable all”, then discover another package: it follows the default.
|
||||
Repeat with “Enable all” while the default is off.
|
||||
6. Restart and repeat notifications from enabled and disabled sources. Check that
|
||||
bulk actions and filtering never dismiss notifications on the phone.
|
||||
|
||||
The same source preferences now filter glasses popups, the Notifications list,
|
||||
and the notification tray/status icons. Filtering happens before display limits;
|
||||
source discovery and the phone notification lifecycle remain unfiltered.
|
||||
Cached tray icons reapply the current preferences on each read, including stale
|
||||
reads, so a changed toggle cannot leave a muted icon visible.
|
||||
|
||||
Additional software coverage: Android list limits and warm/stale icon caches,
|
||||
Disable all / re-enable without a new post, and iOS list/tray filtering.
|
||||
|
||||
Additional hardware validation (pending): with mixed enabled/disabled sources,
|
||||
check the list and status bar together. Toggle a source while its notification
|
||||
is already active, then Disable all and Enable all. Verify immediate removal /
|
||||
restoration without a new notification, including after restart, and verify
|
||||
notifications remain available in the phone notification shade.
|
||||
@@ -1,69 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
test('Notifications menu dismisses all, including beyond the visible list, and leaves filters untouched', () => {
|
||||
let options, active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) }));
|
||||
let dismissals = 0, renders = 0, pops = 0;
|
||||
const load = loader({}, {
|
||||
'../../ui/notifications': { NotificationsListLayer: class {} },
|
||||
'../../ui/notification-filter': { NotificationFilterLayer: class {} },
|
||||
'../../native/notification-icons': {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications(max) { assert.equal(max, 0x7fffffff); return active; },
|
||||
dismissAllNotifications() { dismissals++; active = []; return true; },
|
||||
onAndroidNotificationsChanged: () => () => {},
|
||||
},
|
||||
'../../ui/shell/in-process-window': {
|
||||
YieldAtRootLayer: class {},
|
||||
createInProcessWindow(value) { options = value; return { requestRender() { renders++; } }; },
|
||||
},
|
||||
});
|
||||
load('app/apps/notifications/notifications-app.ts').createNotificationsAppWindow({});
|
||||
const items = options.menuItems();
|
||||
assert.equal(items[0].label, 'Notification filter');
|
||||
const action = items.find(x => x.label === 'Dismiss all notifications');
|
||||
assert.equal(action.disabled(), false);
|
||||
assert.equal(dismissals, 0);
|
||||
action.onSelect({ stack: { pop() { pops++; } } });
|
||||
assert.equal(dismissals, 1);
|
||||
assert.equal(pops, 1);
|
||||
assert.equal(renders, 1);
|
||||
assert.equal(action.disabled(), true);
|
||||
});
|
||||
|
||||
test('Android bulk action uses the native listener and propagates unavailable access', () => {
|
||||
let calls = 0, allowed = false;
|
||||
const load = loader({ global: { isAndroid: true }, com: { faceclaw: { app: {
|
||||
FaceclawMediaNotificationListenerService: { dismissAllNotifications() { calls++; return allowed; } },
|
||||
} } } }, {
|
||||
'../graphics/image': {}, './frame-timings': {}, '../util/array-util': {},
|
||||
'./notification-sources': {}, './image-files': { PHOTO_TONE: { gamma: 1 } }, './notification-types': { NOTIFICATION_ICON_SIZE: 24 },
|
||||
});
|
||||
const api = load('app/native/notification-icons.ts');
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
allowed = true;
|
||||
assert.equal(api.dismissAllNotifications(), true);
|
||||
assert.equal(calls, 2);
|
||||
});
|
||||
|
||||
test('iOS snapshots all ANCS keys and continues when a notification cannot be dismissed', () => {
|
||||
const load = loader({}, {
|
||||
'../graphics/pebble-icons': {}, '../g2/ancs-client': {}, './notification-app-icons': {}, './notification-sources': {},
|
||||
});
|
||||
const api = load('app/native/notification-icons.ios.ts');
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
const active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) })), attempted = [];
|
||||
api.bindIosNotifications({
|
||||
read(max) { assert.equal(max, api.ALL_NOTIFICATIONS); return active; },
|
||||
dismiss(key) {
|
||||
attempted.push(key);
|
||||
if (key === '1') return false;
|
||||
active.splice(active.findIndex(x => x.key === key), 1);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
assert.equal(attempted.length, 80);
|
||||
assert.deepEqual(active, [{ key: '1' }]);
|
||||
});
|
||||
@@ -9,7 +9,7 @@ const generator = require('../scripts/generate-pebble-icons.cjs');
|
||||
function setup(notifications) {
|
||||
const load = loader({}, {
|
||||
'../g2/ancs-client': { AncsClient: class {}, ANCS_CONNECT_MESSAGE: '' },
|
||||
'./notification-sources': { rememberNotificationSources() {}, shouldShowNotificationOnGlasses: packageName => packageName !== "muted" },
|
||||
'./notification-sources': { rememberNotificationSources() {} },
|
||||
});
|
||||
const icons = load('app/native/notification-icons.ios.ts');
|
||||
icons.bindIosNotifications({ read: () => notifications });
|
||||
@@ -106,11 +106,3 @@ test('the icon generator inverts Pebble art: black ink lights up, white fills hi
|
||||
const decoded = loader({}, { './pebble-icons-data': loader({}, {})(dataFile) })('app/graphics/pebble-icons.ts').pebbleIcon('probe');
|
||||
assert.deepEqual([...decoded.pixels], [...pixels]);
|
||||
});
|
||||
|
||||
test('muted sources are hidden before list and icon limits without removing phone notifications', () => {
|
||||
const notifications = [notification('hidden', 'muted', '0'), notification('shown', 'allowed', '0')];
|
||||
const { icons } = setup(notifications);
|
||||
assert.deepEqual([...icons.readVisibleNotifications(1)].map(n => n.key), ['shown']);
|
||||
assert.deepEqual([...icons.readActiveNotificationIcons(1, false).keys], ['shown']);
|
||||
assert.equal(icons.readActiveNotifications(10).length, 2);
|
||||
});
|
||||
@@ -0,0 +1,239 @@
|
||||
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']);
|
||||
});
|
||||
@@ -70,7 +70,6 @@ function ui(fontSize = 12) {
|
||||
const native = {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => { prefs.rememberNotificationSources(active); return active; },
|
||||
readVisibleNotifications: () => { prefs.rememberNotificationSources(active); return active.filter(n => prefs.shouldShowNotificationOnGlasses(n.packageName)); },
|
||||
dismissNotification: () => { dismissals++; active = []; return true; },
|
||||
readNotificationIconByKey: () => ({ icon: null, stale: false }),
|
||||
};
|
||||
@@ -166,7 +165,6 @@ test('cancel and back dismiss the popup without changing source preferences', as
|
||||
test('filter toggles persist after notifications disappear and discovers new sources while open', async () => {
|
||||
const app = ui();
|
||||
app.paint(app.filter);
|
||||
for (let i = 0; i < 3; i++) await app.input(app.filter, 'scroll-down');
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
app.active([{ packageName: 'com.alpha', appName: 'Alpha' }]);
|
||||
@@ -179,68 +177,6 @@ test('filter toggles persist after notifications disappear and discovers new sou
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses('com.alpha'), true);
|
||||
});
|
||||
|
||||
test('default persists without overwriting explicit choices, including legacy saved sources', () => {
|
||||
const settings = new Map([['notifications.sources', JSON.stringify([
|
||||
{ ...mail, showOnGlasses: true },
|
||||
{ packageName: 'muted', appName: 'Muted', showOnGlasses: false },
|
||||
])]]);
|
||||
let prefs = store(settings);
|
||||
prefs.rememberNotificationSources([{ packageName: 'discovered', appName: 'Discovered' }]);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(false);
|
||||
prefs = store(settings);
|
||||
assert.equal(prefs.newNotificationAppsEnabledByDefault(), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses(mail.packageName), true);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('muted'), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('discovered'), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), false);
|
||||
prefs.rememberNotificationSources([{ packageName: 'future', appName: 'Future' }]);
|
||||
prefs.setNotificationSourceEnabled({ packageName: 'future', appName: 'Future' }, true);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(true);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(false);
|
||||
assert.equal(store(settings).shouldShowNotificationOnGlasses('future'), true);
|
||||
});
|
||||
|
||||
test('bulk choices persist for known sources without changing the default for future sources', () => {
|
||||
const settings = new Map();
|
||||
let prefs = store(settings);
|
||||
prefs.rememberNotificationSources([mail]);
|
||||
prefs.setAllNotificationSourcesEnabled(false);
|
||||
prefs = store(settings);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), true);
|
||||
prefs.setNewNotificationAppsEnabledByDefault(false);
|
||||
prefs.setAllNotificationSourcesEnabled(true);
|
||||
prefs = store(settings);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses(mail.packageName), true);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), false);
|
||||
prefs.rememberNotificationSources([{ packageName: 'future', appName: 'Future' }]);
|
||||
assert.equal(prefs.shouldShowNotificationOnGlasses('future'), false);
|
||||
prefs.setAllNotificationSourcesEnabled(false);
|
||||
assert.ok(prefs.readNotificationSources().every(source => !source.showOnGlasses));
|
||||
});
|
||||
|
||||
test('filter controls work with an empty list and keep selection as sources arrive', async () => {
|
||||
const app = ui();
|
||||
app.active([]);
|
||||
const labels = app.paint(app.filter).texts.map(({ text }) => text);
|
||||
assert.ok(labels.includes('New apps enabled by default'));
|
||||
assert.ok(labels.includes('Enable all'));
|
||||
assert.ok(labels.includes('Disable all'));
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.newNotificationAppsEnabledByDefault(), false);
|
||||
app.active([mail]);
|
||||
app.paint(app.filter);
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
await app.input(app.filter, 'scroll-down');
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), true);
|
||||
assert.equal(app.prefs.newNotificationAppsEnabledByDefault(), false);
|
||||
await app.input(app.filter, 'scroll-down');
|
||||
await app.input(app.filter, 'click');
|
||||
assert.equal(app.prefs.shouldShowNotificationOnGlasses(mail.packageName), false);
|
||||
assert.equal(app.dismissals(), 0);
|
||||
});
|
||||
|
||||
test('popup action wraps fully and stays visible with small and large fonts', async () => {
|
||||
for (const size of [12, 20]) {
|
||||
const app = ui(size);
|
||||
@@ -318,33 +254,3 @@ test('controller filters before waking or opening a popup, and still refreshes t
|
||||
elapse();
|
||||
assert.equal(popups, 1);
|
||||
});
|
||||
|
||||
test('Android display filters before limits and reapplies preferences to cached tray icons', () => {
|
||||
const prefs = store();
|
||||
const active = [{ ...mail, key: 'hidden' }, { packageName: 'allowed', appName: 'Allowed', key: 'shown' }];
|
||||
const file = ts.createSourceFile('icons.ts', source('app/native/notification-icons.ts'), ts.ScriptTarget.Latest, true);
|
||||
const functions = file.statements.filter(node => ts.isFunctionDeclaration(node) &&
|
||||
['readVisibleNotifications', 'cachedIconsResult'].includes(node.name?.text)).map(node => node.getText(file));
|
||||
const { readVisibleNotifications, cachedIconsResult } = evaluate(functions.join('\n') + '\nexport { cachedIconsResult };', null, {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => { prefs.rememberNotificationSources(active); return active; },
|
||||
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
|
||||
cachedKeys: ['hidden', 'shown'],
|
||||
cachedPackages: new Map(active.map(n => [n.key, n.packageName])),
|
||||
cachedIcons: [{ clone: () => 'mail-icon' }, { clone: () => 'allowed-icon' }],
|
||||
});
|
||||
prefs.setNotificationSourceEnabled(mail, false);
|
||||
assert.deepEqual(Array.from(readVisibleNotifications(1), n => n.key), ['shown']);
|
||||
for (const stale of [false, true]) {
|
||||
const result = cachedIconsResult(1, stale);
|
||||
assert.deepEqual(Array.from(result.keys), ['shown']);
|
||||
assert.deepEqual(Array.from(result.icons), ['allowed-icon']);
|
||||
assert.equal(result.stale, stale);
|
||||
}
|
||||
prefs.setAllNotificationSourcesEnabled(false);
|
||||
assert.equal(cachedIconsResult(10, false).keys.length, 0);
|
||||
assert.equal(readVisibleNotifications(50).length, 0);
|
||||
prefs.setNotificationSourceEnabled(mail, true);
|
||||
assert.deepEqual(Array.from(cachedIconsResult(1, false).keys), ['hidden']);
|
||||
assert.equal(active.length, 2);
|
||||
});
|
||||
@@ -0,0 +1,154 @@
|
||||
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