forked from Blendman974/faceclaw
[verified] merge upstream c162c8e6 into all-features
This commit is contained in:
commit
5790e98d27
176 files changed
+5311
-2307
No files matched your search
@@ -10,6 +10,7 @@ import { Menu } from "../../ui/menu-core";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
|
||||
import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import type { Viewport } from "../../ui/viewport";
|
||||
import { GlanceBoard } from "./board";
|
||||
import { glanceFont } from "./glance-font";
|
||||
import {
|
||||
@@ -33,17 +34,20 @@ import { findGlanceWidget, glanceWidgetSpans } from "./widgets";
|
||||
export const GLANCEBOARD_WINDOW_ID = "glanceboard";
|
||||
export const GLANCEBOARD_SURFACE_ID = "window:glanceboard";
|
||||
|
||||
const TITLE_X = 18;
|
||||
const TITLE_Y = 10;
|
||||
const PARAGRAPH_X = 24;
|
||||
/** The entry page splits at the middle: menu left, slot preview right. */
|
||||
/** The entry page's title: its drop below the top padding. It lines up with the menu rows' text. */
|
||||
const TITLE_OFFSET_Y = 2;
|
||||
/** Indent of the intro paragraph under the title, and how far short of the middle it wraps. */
|
||||
const PARAGRAPH_INDENT = 6;
|
||||
const PARAGRAPH_RIGHT_GAP = 12;
|
||||
/** The entry page splits at the middle: menu left, slot preview right, this far from the split. */
|
||||
const PREVIEW_MARGIN = 8;
|
||||
/** The preview's outline, drawn just outside the scaled board. */
|
||||
const PREVIEW_OUTLINE = 1;
|
||||
const PREVIEW_MIN_LINE_VALUE = 20;
|
||||
const PREVIEW_LINE_VALUE = 100;
|
||||
/** The entry menu's row boxes: left inset, gap below the paragraph, and inset from the page's bottom. */
|
||||
const HOME_MENU_X = 20;
|
||||
/** The entry menu's row boxes: gap below the paragraph, and how far short of the middle they end. */
|
||||
const HOME_MENU_TOP_GAP = 12;
|
||||
const HOME_MENU_BOTTOM_MARGIN = 8;
|
||||
const HOME_MENU_RIGHT_GAP = 20;
|
||||
/** Horizontal inset of row text (and custom row content) from its selection box. */
|
||||
const HOME_ROW_TEXT_X = 10;
|
||||
// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the
|
||||
@@ -56,9 +60,7 @@ const INTRO =
|
||||
"long-press-and-hold. It will close automatically.";
|
||||
|
||||
/** Full-page list layout shared by the sub-screens. */
|
||||
function pageMenuLayout(width: number) {
|
||||
return { x: 8, y: 8, width: width - 16, opaque: true, showBorder: false } as const;
|
||||
}
|
||||
const PAGE_MENU_LAYOUT = { page: true } as const;
|
||||
|
||||
/**
|
||||
* The Glanceboard app's entry page. Left half: title, a short description
|
||||
@@ -67,6 +69,10 @@ function pageMenuLayout(width: number) {
|
||||
* name of the widget in each. "Select Contents" moves focus into that
|
||||
* preview, where scroll picks a slot and a tap opens the picker for it;
|
||||
* a double-tap returns focus to the menu.
|
||||
*
|
||||
* The menu's row boxes and the preview's outline sit at the padding
|
||||
* suggested for the window's edges (viewport.ts). The menu scrolls, so it
|
||||
* runs to the bottom edge itself, with that edge's padding after its last row.
|
||||
*/
|
||||
class GlanceboardHomeLayer implements Layer {
|
||||
private readonly menu: Menu<MenuItem>;
|
||||
@@ -125,17 +131,23 @@ class GlanceboardHomeLayer implements Layer {
|
||||
});
|
||||
}
|
||||
|
||||
/** Where the scaled board sits: the right half, board aspect, vertically centred. */
|
||||
private previewRect(width: number, height: number): { x: number; y: number; width: number; height: number } {
|
||||
const half = (width / 2) | 0;
|
||||
const availableWidth = width - half - 2 * PREVIEW_MARGIN;
|
||||
/**
|
||||
* Where the scaled board sits: board aspect, centred in the right half's
|
||||
* room inside the window's padding, which its outline may reach.
|
||||
*/
|
||||
private previewRect(viewport: Viewport): { x: number; y: number; width: number; height: number } {
|
||||
const { width, height, padding } = viewport;
|
||||
const left = ((width / 2) | 0) + PREVIEW_MARGIN;
|
||||
const top = padding.top + PREVIEW_OUTLINE;
|
||||
const availableWidth = Math.max(0, width - padding.right - PREVIEW_OUTLINE - left);
|
||||
const availableHeight = Math.max(0, height - padding.bottom - PREVIEW_OUTLINE - top);
|
||||
const layout = glanceLayout();
|
||||
const scale = Math.min(availableWidth / layout.width, (height - 2 * PREVIEW_MARGIN) / layout.height);
|
||||
const scale = Math.min(availableWidth / layout.width, availableHeight / layout.height);
|
||||
const previewWidth = Math.round(layout.width * scale);
|
||||
const previewHeight = Math.round(layout.height * scale);
|
||||
return {
|
||||
x: half + PREVIEW_MARGIN + (((availableWidth - previewWidth) / 2) | 0),
|
||||
y: ((height - previewHeight) / 2) | 0,
|
||||
x: left + (((availableWidth - previewWidth) / 2) | 0),
|
||||
y: top + (((availableHeight - previewHeight) / 2) | 0),
|
||||
width: previewWidth,
|
||||
height: previewHeight,
|
||||
};
|
||||
@@ -143,32 +155,37 @@ class GlanceboardHomeLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const viewport = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = viewport;
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const half = (width / 2) | 0;
|
||||
image.drawText(font, TITLE_X, TITLE_Y, "Glanceboard", 220);
|
||||
const menuX = padding.left;
|
||||
const titleX = menuX + HOME_ROW_TEXT_X;
|
||||
const titleY = padding.top + TITLE_OFFSET_Y;
|
||||
image.drawText(font, titleX, titleY, "Glanceboard", 220);
|
||||
const step = lineStep(font);
|
||||
let y = TITLE_Y + step + 6;
|
||||
for (const line of wrapText(font, INTRO, half - PARAGRAPH_X - 12)) {
|
||||
image.drawText(font, PARAGRAPH_X, y, line, 160);
|
||||
const paragraphX = titleX + PARAGRAPH_INDENT;
|
||||
let y = titleY + step + 6;
|
||||
for (const line of wrapText(font, INTRO, half - PARAGRAPH_RIGHT_GAP - paragraphX)) {
|
||||
image.drawText(font, paragraphX, y, line, 160);
|
||||
y += step;
|
||||
}
|
||||
// The menu sits below the paragraph in the left half. While the preview
|
||||
// has focus the menu keeps its outline-only selection.
|
||||
const menuTop = y + HOME_MENU_TOP_GAP;
|
||||
const menuWidth = half - 2 * HOME_MENU_X;
|
||||
const menuHeight = Math.max(0, height - menuTop - HOME_MENU_BOTTOM_MARGIN);
|
||||
const menuWidth = Math.max(0, half - HOME_MENU_RIGHT_GAP - menuX);
|
||||
const menuHeight = Math.max(0, height - menuTop);
|
||||
this.paintCtx = ctx;
|
||||
try {
|
||||
this.menu.paint(image, { x: HOME_MENU_X, y: menuTop, width: menuWidth, height: menuHeight },
|
||||
this.menu.paint(image, { x: menuX, y: menuTop, width: menuWidth, height: menuHeight, padBottom: padding.bottom },
|
||||
ctx.stack.isFocused() && this.focus === "menu");
|
||||
} finally {
|
||||
this.paintCtx = null;
|
||||
}
|
||||
this.menu.drawScrollbar(image, HOME_MENU_X + menuWidth + 5, menuTop, menuHeight - 4);
|
||||
this.menu.drawScrollbar(image, menuX + menuWidth + 5, menuTop, Math.max(0, menuHeight - padding.bottom - 4));
|
||||
|
||||
this.selectedSlot = Math.min(this.selectedSlot, glanceLayout().slots.length - 1);
|
||||
const preview = this.previewRect(width, height);
|
||||
const preview = this.previewRect(viewport);
|
||||
drawSlotPreview(image, preview, {
|
||||
selectedSlot: this.selectedSlot,
|
||||
selectionFocused: ctx.stack.isFocused() && this.focus === "preview",
|
||||
@@ -238,7 +255,7 @@ function drawSlotPreview(
|
||||
height: Math.round(r.height * sy),
|
||||
});
|
||||
|
||||
image.drawRect(rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2, 72);
|
||||
image.drawRect(rect.x - PREVIEW_OUTLINE, rect.y - PREVIEW_OUTLINE, rect.width + 2 * PREVIEW_OUTLINE, rect.height + 2 * PREVIEW_OUTLINE, 72);
|
||||
const selected = scaled(layout.slots[options.selectedSlot]!.rect);
|
||||
drawSelectionHighlight(image, selected.x + 1, selected.y + 1, selected.width - 2, selected.height - 2, options.selectionFocused, 4);
|
||||
|
||||
@@ -321,7 +338,7 @@ function openGlanceSettings(ctx: LayerContext): void {
|
||||
enumSettingMenuItem(glanceDepthSetting),
|
||||
...widgetSettingsMenuItems(),
|
||||
];
|
||||
const layer = new MenuLayer("Glanceboard settings", items(), pageMenuLayout(ctx.stack.getBaseSize().width));
|
||||
const layer = new MenuLayer("Glanceboard settings", items(), PAGE_MENU_LAYOUT);
|
||||
ctx.stack.push(layer);
|
||||
}
|
||||
|
||||
@@ -341,7 +358,7 @@ function widgetSettingsMenuItems(): MenuItem[] {
|
||||
return { label: widget.label, description: `${widget.label} has no settings.`, disabled: true, onSelect: () => {} };
|
||||
}
|
||||
return submenuItem(widget.label, (ctx) => {
|
||||
ctx.stack.push(new MenuLayer(`${widget.label} settings`, settingsMenuItems(), pageMenuLayout(ctx.stack.getBaseSize().width)));
|
||||
ctx.stack.push(new MenuLayer(`${widget.label} settings`, settingsMenuItems(), PAGE_MENU_LAYOUT));
|
||||
}, { description: `Settings for the ${widget.label} widget.` });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { ensureLocationPermission, hasLocationPermission } from "../../../native
|
||||
import { onAndroidNotificationsChanged, readActiveNotificationIcons } from "../../../native/notification-icons";
|
||||
import { NOTIFICATION_ICON_SIZE } from "../../../native/notification-types";
|
||||
import { readPhoneBatteryState } from "../../../native/phone-battery";
|
||||
import { voiceControlBridge } from "../../../native/voice-control";
|
||||
import { weatherBridge } from "../../../native/weather";
|
||||
import { formatClockDate, formatClockTime } from "../../../ui/clock-format";
|
||||
import {
|
||||
@@ -26,6 +27,7 @@ import {
|
||||
watchBatteryVisibilitySetting,
|
||||
type BatteryIndicatorVisibility,
|
||||
} from "../../../ui/dashboard-settings";
|
||||
import { RECORDING_ICON } from "../../../ui/listening-header";
|
||||
import { type MenuItem } from "../../../ui/menu";
|
||||
import { shell } from "../../../ui/shell/shell";
|
||||
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../../util/render-freshness";
|
||||
@@ -149,13 +151,16 @@ function requestWeatherLocationAccess(): void {
|
||||
* off, and the layout mirrored either way, in the card's submenu of
|
||||
* Glanceboard > Settings. Battery style and per-device visibility follow
|
||||
* Settings > Customization > Battery indicators, so the card agrees with
|
||||
* the bar. Countdowns tick once a second only while one is running.
|
||||
* the bar. Countdowns tick once a second only while one is running. While
|
||||
* Transcribe or Translate is saving the mic's audio (their Save Recording),
|
||||
* the recording circle sits under the batteries and weather.
|
||||
*/
|
||||
export class SystemCardWidget implements GlanceWidget {
|
||||
private requestRender: (() => void) | null = null;
|
||||
private minuteTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private secondTimer: ReturnType<typeof setInterval> | null = null;
|
||||
private unsubscribeNotifications: (() => void) | null = null;
|
||||
private unsubscribeRecording: (() => void) | null = null;
|
||||
private unsubscribeSettings: (() => void) | null = null;
|
||||
private unsubscribeTimers: (() => void) | null = null;
|
||||
private unsubscribeWeather: (() => void) | null = null;
|
||||
@@ -164,6 +169,7 @@ export class SystemCardWidget implements GlanceWidget {
|
||||
this.requestRender = requestRender;
|
||||
this.scheduleMinuteTick();
|
||||
this.unsubscribeNotifications = onAndroidNotificationsChanged(() => this.requestRender?.());
|
||||
this.unsubscribeRecording = voiceControlBridge.onRecordingChange(() => this.requestRender?.());
|
||||
this.unsubscribeSettings = onAnySettingChanged(() => this.requestRender?.());
|
||||
this.unsubscribeTimers = timerEngine.onChange(() => {
|
||||
this.syncSecondTick();
|
||||
@@ -182,6 +188,8 @@ export class SystemCardWidget implements GlanceWidget {
|
||||
this.secondTimer = null;
|
||||
this.unsubscribeNotifications?.();
|
||||
this.unsubscribeNotifications = null;
|
||||
this.unsubscribeRecording?.();
|
||||
this.unsubscribeRecording = null;
|
||||
this.unsubscribeSettings?.();
|
||||
this.unsubscribeSettings = null;
|
||||
this.unsubscribeTimers?.();
|
||||
@@ -237,6 +245,8 @@ export class SystemCardWidget implements GlanceWidget {
|
||||
if (batteryItems.length) sideBlocks.push(batteryBlock(small, batteryItems));
|
||||
const weather = weatherShowOnSystemCardSetting.get() ? weatherBlock(medium, now.getTime()) : null;
|
||||
if (weather) sideBlocks.push(weather);
|
||||
// Last, so it comes and goes without moving the others.
|
||||
if (voiceControlBridge.recording) sideBlocks.push(RECORDING_BLOCK);
|
||||
const side: Rect[] = [];
|
||||
let sideOffset = PAD;
|
||||
for (const block of sideBlocks) {
|
||||
@@ -382,6 +392,13 @@ function batteryBlock(font: UiFont, items: readonly BatteryItem[]): SideBlock {
|
||||
};
|
||||
}
|
||||
|
||||
/** The recording circle: the mic's audio is being saved (see RECORDING_ICON). */
|
||||
const RECORDING_BLOCK: SideBlock = {
|
||||
width: RECORDING_ICON.width,
|
||||
height: RECORDING_ICON.height,
|
||||
draw: (image, left, top) => image.drawImage(RECORDING_ICON, left, top),
|
||||
};
|
||||
|
||||
/** The current weather's condition icon and temperature, or null without a fresh reading. */
|
||||
function weatherBlock(font: UiFont, nowMs: number): SideBlock | null {
|
||||
const reading = weatherReading(weatherBridge.snapshot(), nowMs);
|
||||
|
||||
Reference in new issue
Block a user