forked from Blendman974/faceclaw
Merge branch 'calculator' of https://github.com/kalanihelekunihi/faceclaw into calculator
This commit is contained in:
commit
f3ad55ca3d
126 files changed
+22253
-58
No files matched your search
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Ambient cards: small, non-interactive popups the shell chrome paints at the
|
||||
* bottom-right of the screen, stacking upward — used for the "you know this
|
||||
* person" encounter popup when captions recognize a familiar voice. Unlike
|
||||
* the notification modal they never take input or focus: they appear, sit
|
||||
* quietly for a few seconds, and expire on their own.
|
||||
*
|
||||
* Pure store + change notification; painting lives in the chrome layer, and
|
||||
* the shell subscribes to changes to request repaints.
|
||||
*/
|
||||
|
||||
export type AmbientCard = {
|
||||
/** Stable identity: posting the same id replaces the existing card. */
|
||||
id: string;
|
||||
/** Bright first line (e.g. "Alice · 2d ago"). */
|
||||
title: string;
|
||||
/** Dimmer detail lines (fact, action items); painted in order, truncated to fit. */
|
||||
lines: string[];
|
||||
expiresAtMs: number;
|
||||
};
|
||||
|
||||
const cards: AmbientCard[] = [];
|
||||
const listeners = new Set<() => void>();
|
||||
let expiryTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
/** Cards still alive, oldest first (painted bottom-up, so oldest sits lowest). */
|
||||
export function activeAmbientCards(nowMs = Date.now()): AmbientCard[] {
|
||||
prune(nowMs);
|
||||
return cards;
|
||||
}
|
||||
|
||||
/** Post (or refresh) a card; repaints happen via the change listeners. */
|
||||
export function postAmbientCard(card: AmbientCard): void {
|
||||
const index = cards.findIndex((existing) => existing.id === card.id);
|
||||
if (index >= 0) {
|
||||
cards.splice(index, 1);
|
||||
}
|
||||
cards.push(card);
|
||||
scheduleExpiry();
|
||||
notify();
|
||||
}
|
||||
|
||||
export function dismissAmbientCard(id: string): void {
|
||||
const index = cards.findIndex((existing) => existing.id === id);
|
||||
if (index >= 0) {
|
||||
cards.splice(index, 1);
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
export function onAmbientCardsChanged(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
}
|
||||
|
||||
function prune(nowMs: number): void {
|
||||
const before = cards.length;
|
||||
for (let index = cards.length - 1; index >= 0; index--) {
|
||||
if (cards[index]!.expiresAtMs <= nowMs) {
|
||||
cards.splice(index, 1);
|
||||
}
|
||||
}
|
||||
if (cards.length !== before) {
|
||||
scheduleExpiry();
|
||||
}
|
||||
}
|
||||
|
||||
/** One timer for the next expiry, so a card's disappearance also repaints. */
|
||||
function scheduleExpiry(): void {
|
||||
if (expiryTimer !== null) {
|
||||
clearTimeout(expiryTimer);
|
||||
expiryTimer = null;
|
||||
}
|
||||
if (!cards.length) return;
|
||||
const next = Math.min(...cards.map((card) => card.expiresAtMs));
|
||||
expiryTimer = setTimeout(() => {
|
||||
expiryTimer = null;
|
||||
prune(Date.now());
|
||||
notify();
|
||||
}, Math.max(50, next - Date.now()));
|
||||
}
|
||||
|
||||
function notify(): void {
|
||||
listeners.forEach((listener) => {
|
||||
try {
|
||||
listener();
|
||||
} catch (error) {
|
||||
console.warn(`ambient card listener failed: ${error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { activeAmbientCards } from "./ambient-cards";
|
||||
import { BATTERY_ICON_WIDTH, drawBattery } from "../../graphics/battery";
|
||||
import { readActiveNotificationIcons } from "../../native/notification-icons";
|
||||
import { readPhoneBatteryState } from "../../native/phone-battery";
|
||||
@@ -8,6 +10,7 @@ import { renderIcon, renderIconWithGlyph, type IconName } from "../../graphics/i
|
||||
import { batteryDisplayModeSetting, timeFormatSetting } from "../dashboard-settings";
|
||||
import { Layer } from "../layers";
|
||||
import { scrollToKeepSelectionVisible } from "../menu";
|
||||
import { lineStep } from "../metrics";
|
||||
import {
|
||||
MIN_WINDOW_HEIGHT,
|
||||
minWindowTop,
|
||||
@@ -192,6 +195,7 @@ export class ShellChromeLayer implements Layer {
|
||||
this.drawSidebar(image, state);
|
||||
}
|
||||
this.drawTopBar(image, state);
|
||||
drawAmbientCards(image);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -382,6 +386,50 @@ export class ShellChromeLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
// Ambient cards (encounter popups): compact and deliberately unobtrusive,
|
||||
// anchored to the bottom-right of the window band and stacking upward, clear
|
||||
// of the caption area's left-aligned text. Never interactive.
|
||||
const AMBIENT_CARD_WIDTH = 230;
|
||||
const AMBIENT_CARD_MARGIN = 6;
|
||||
const AMBIENT_CARD_GAP = 4;
|
||||
const AMBIENT_CARD_PADDING_X = 8;
|
||||
const AMBIENT_CARD_PADDING_Y = 4;
|
||||
const AMBIENT_MAX_LINES_PER_CARD = 3;
|
||||
|
||||
/**
|
||||
* Paint the active ambient cards bottom-up: the oldest card sits at the very
|
||||
* bottom of the window band and newer ones stack above it. Cards that would
|
||||
* cross into the top bar are dropped rather than clipped.
|
||||
*/
|
||||
function drawAmbientCards(image: GrayImage): void {
|
||||
const cards = activeAmbientCards();
|
||||
if (!cards.length) return;
|
||||
const font = getDefaultSmallFont();
|
||||
const bandTop = minWindowTop();
|
||||
const bandBottom = bandTop + MIN_WINDOW_HEIGHT;
|
||||
const x = G2_LENS_WIDTH - AMBIENT_CARD_WIDTH - AMBIENT_CARD_MARGIN;
|
||||
const textWidth = AMBIENT_CARD_WIDTH - 2 * AMBIENT_CARD_PADDING_X;
|
||||
let bottom = bandBottom - AMBIENT_CARD_MARGIN;
|
||||
for (const card of cards) {
|
||||
const lines = [card.title, ...card.lines].slice(0, 1 + AMBIENT_MAX_LINES_PER_CARD);
|
||||
const height = 2 * AMBIENT_CARD_PADDING_Y + lines.length * lineStep(font);
|
||||
const y = bottom - height;
|
||||
if (y < bandTop + TOP_BAR_HEIGHT) break;
|
||||
image.fillRoundedRect(x, y, AMBIENT_CARD_WIDTH, height, SHELL_OPAQUE_BLACK, 6);
|
||||
image.drawRoundedRect(x, y, AMBIENT_CARD_WIDTH, height, 90, 6);
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
image.drawText(
|
||||
font,
|
||||
x + AMBIENT_CARD_PADDING_X,
|
||||
y + AMBIENT_CARD_PADDING_Y + index * lineStep(font),
|
||||
truncateText(font, lines[index]!, textWidth),
|
||||
index === 0 ? 220 : 160,
|
||||
);
|
||||
}
|
||||
bottom = y - AMBIENT_CARD_GAP;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw app tray icons right-to-left, ending just left of the battery block;
|
||||
* returns the left edge of the tray region.
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
timeFormatSetting,
|
||||
wakeWordActionSetting,
|
||||
} from "../dashboard-settings";
|
||||
import { onAmbientCardsChanged } from "./ambient-cards";
|
||||
import { ShellChromeLayer, sidebarContentLeft, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
|
||||
import { ShellModalLayer } from "./modal-layer";
|
||||
import { ToolDebugMenuLayer } from "./tool-debug-layer";
|
||||
@@ -270,6 +271,21 @@ class Shell {
|
||||
this.config = config;
|
||||
this.stack.setActions(config.actions);
|
||||
this.subscribeToTopBarSettings();
|
||||
this.subscribeToAmbientCards();
|
||||
}
|
||||
|
||||
// Ambient (encounter) cards live in the chrome paint; a posted or expired
|
||||
// card repaints the shell surface so it appears and disappears on time.
|
||||
private ambientCardsSubscribed = false;
|
||||
|
||||
private subscribeToAmbientCards(): void {
|
||||
if (this.ambientCardsSubscribed) return;
|
||||
this.ambientCardsSubscribed = true;
|
||||
onAmbientCardsChanged(() => {
|
||||
if (this.screenOn) {
|
||||
this.config.requestShellRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private subscribeToTopBarSettings(): void {
|
||||
|
||||
Reference in new issue
Block a user