forked from Blendman974/faceclaw
Refactor font handling; add image-compression estimation debug option
This commit is contained in:
1 parent
5a92637537
commit
964cd11785
15 files changed
+389
-130
No files matched your search
@@ -10,13 +10,15 @@ import { onAndroidNotificationPosted } from "../native/notification-icons";
|
|||||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||||
import { grayImageToPreviewSource, grayImageToPreviewSourceWithBitmapFactory } from "../native/gray-image-preview";
|
import { grayImageToPreviewSource, grayImageToPreviewSourceWithBitmapFactory } from "../native/gray-image-preview";
|
||||||
import { voiceControlBridge } from "../native/voice-control";
|
import { voiceControlBridge } from "../native/voice-control";
|
||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
import { estimateTileCompression } from "../graphics/compression-estimator";
|
||||||
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, type ImageTile } from "../graphics/image";
|
||||||
import {
|
import {
|
||||||
applyDashboardScreenTimeout,
|
applyDashboardScreenTimeout,
|
||||||
consumeDashboardTiledWakePaint,
|
consumeDashboardTiledWakePaint,
|
||||||
drawDashboard,
|
drawDashboard,
|
||||||
getDashboardNightscoutSettings,
|
getDashboardNightscoutSettings,
|
||||||
getDashboardSystemCardName,
|
getDashboardSystemCardName,
|
||||||
|
isDashboardCompressionRatioEstimationEnabled,
|
||||||
isDashboardVoiceControlEnabled,
|
isDashboardVoiceControlEnabled,
|
||||||
noteDashboardPhoneTextInput,
|
noteDashboardPhoneTextInput,
|
||||||
openAndroidNotificationFromSleep,
|
openAndroidNotificationFromSleep,
|
||||||
@@ -636,7 +638,11 @@ class DashboardController {
|
|||||||
const paintMs = Date.now() - paintStartedAtMs;
|
const paintMs = Date.now() - paintStartedAtMs;
|
||||||
const forceTiledCommit = consumeDashboardTiledWakePaint();
|
const forceTiledCommit = consumeDashboardTiledWakePaint();
|
||||||
const fingerprint = image.fingerprint();
|
const fingerprint = image.fingerprint();
|
||||||
const tiles = image.toEvenHubTiles().map((tile) => tile.bmp);
|
const imageTiles = image.toEvenHubTiles();
|
||||||
|
if (isDashboardCompressionRatioEstimationEnabled()) {
|
||||||
|
this.logCompressionEstimate(imageTiles);
|
||||||
|
}
|
||||||
|
const tiles = imageTiles.map((tile) => tile.bmp);
|
||||||
const updatePreviewAfterTransmit = this.phase === "connected";
|
const updatePreviewAfterTransmit = this.phase === "connected";
|
||||||
if (!updatePreviewAfterTransmit) {
|
if (!updatePreviewAfterTransmit) {
|
||||||
this.updateDisplayPreviewFromImage(image);
|
this.updateDisplayPreviewFromImage(image);
|
||||||
@@ -823,6 +829,18 @@ class DashboardController {
|
|||||||
return `paint=${Math.round(metrics.paintMs)}ms, transmit=${Math.round(metrics.transmitMs)}ms, tiles=${Math.round(metrics.tileCount)}`;
|
return `paint=${Math.round(metrics.paintMs)}ms, transmit=${Math.round(metrics.transmitMs)}ms, tiles=${Math.round(metrics.tileCount)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private logCompressionEstimate(tiles: readonly ImageTile[]): void {
|
||||||
|
try {
|
||||||
|
const report = estimateTileCompression(tiles);
|
||||||
|
for (const line of report.tileLines) {
|
||||||
|
this.appendLog(line);
|
||||||
|
}
|
||||||
|
this.appendLog(report.totalLine);
|
||||||
|
} catch (error) {
|
||||||
|
this.appendLog(`compression estimate failed: ${this.formatError(error)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private appendLog(line: string): void {
|
private appendLog(line: string): void {
|
||||||
const stamped = `[${formatTimestamp(new Date())}] ${line}`;
|
const stamped = `[${formatTimestamp(new Date())}] ${line}`;
|
||||||
//this.log = this.log ? `${this.log}\n${stamped}` : stamped;
|
//this.log = this.log ? `${this.log}\n${stamped}` : stamped;
|
||||||
|
|||||||
+22
-16
@@ -130,22 +130,6 @@ export class BdfFont {
|
|||||||
|
|
||||||
const cachedEmbeddedFonts = new Map<string, BdfFont>();
|
const cachedEmbeddedFonts = new Map<string, BdfFont>();
|
||||||
|
|
||||||
export function loadEmbeddedTerminus12(): BdfFont {
|
|
||||||
return loadEmbeddedFont("fonts/terminus/ter-u12n.bdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function loadEmbeddedTerminus16(): BdfFont {
|
|
||||||
return loadEmbeddedFont("fonts/terminus/ter-u16n.bdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function loadEmbeddedTerminus24(): BdfFont {
|
|
||||||
return loadEmbeddedFont("fonts/terminus/ter-u24n.bdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function loadEmbeddedTerminus32(): BdfFont {
|
|
||||||
return loadEmbeddedFont("fonts/terminus/ter-u32n.bdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadEmbeddedFont(path: string): BdfFont {
|
function loadEmbeddedFont(path: string): BdfFont {
|
||||||
const cached = cachedEmbeddedFonts.get(path);
|
const cached = cachedEmbeddedFonts.get(path);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
@@ -157,3 +141,25 @@ function loadEmbeddedFont(path: string): BdfFont {
|
|||||||
cachedEmbeddedFonts.set(path, font);
|
cachedEmbeddedFonts.set(path, font);
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const embeddedFonts = {
|
||||||
|
"terminus12": "fonts/terminus/ter-u12n.bdf",
|
||||||
|
"terminus16": "fonts/terminus/ter-u16n.bdf",
|
||||||
|
"terminus24": "fonts/terminus/ter-u24n.bdf",
|
||||||
|
"terminus32": "fonts/terminus/ter-u32n.bdf",
|
||||||
|
}
|
||||||
|
type EmbeddedFontName = keyof typeof embeddedFonts;
|
||||||
|
|
||||||
|
export function getFont(font: EmbeddedFontName): BdfFont {
|
||||||
|
return loadEmbeddedFont(embeddedFonts[font]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefaultSmallFont(): BdfFont {
|
||||||
|
return getFont("terminus12");
|
||||||
|
}
|
||||||
|
export function getDefaultMediumFont(): BdfFont {
|
||||||
|
return getFont("terminus16");
|
||||||
|
}
|
||||||
|
export function getDefaultLargeFont(): BdfFont {
|
||||||
|
return getFont("terminus24");
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
import { type ImageTile } from "./image";
|
||||||
|
|
||||||
|
const lz4 = require("lz4js");
|
||||||
|
const pako = require("pako");
|
||||||
|
|
||||||
|
type CompressionTotals = {
|
||||||
|
uncompressed: number;
|
||||||
|
lz4: number;
|
||||||
|
png: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CompressionEstimateReport = {
|
||||||
|
tileLines: string[];
|
||||||
|
totalLine: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const cumulativeTotals: CompressionTotals = {
|
||||||
|
uncompressed: 0,
|
||||||
|
lz4: 0,
|
||||||
|
png: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let reportSequence = 0;
|
||||||
|
|
||||||
|
export function estimateTileCompression(tiles: readonly ImageTile[]): CompressionEstimateReport {
|
||||||
|
const frameTotals: CompressionTotals = {
|
||||||
|
uncompressed: 0,
|
||||||
|
lz4: 0,
|
||||||
|
png: 0,
|
||||||
|
};
|
||||||
|
const frameId = ++reportSequence;
|
||||||
|
const tileLines: string[] = [];
|
||||||
|
|
||||||
|
for (let index = 0; index < tiles.length; index++) {
|
||||||
|
const tile = tiles[index]!;
|
||||||
|
const uncompressedSize = tile.bmp.byteLength;
|
||||||
|
const lz4Size = byteLength(lz4.compress(tile.bmp));
|
||||||
|
const pngSize = encodePng4BitGrayscaleFromBmpTile(tile).byteLength;
|
||||||
|
|
||||||
|
frameTotals.uncompressed += uncompressedSize;
|
||||||
|
frameTotals.lz4 += lz4Size;
|
||||||
|
frameTotals.png += pngSize;
|
||||||
|
|
||||||
|
tileLines.push(
|
||||||
|
`compression estimate #${frameId} tile ${index + 1}/${tiles.length} ` +
|
||||||
|
`${tile.x},${tile.y} ${tile.width}x${tile.height}: ` +
|
||||||
|
`uncompressed=${uncompressedSize}, lz4=${formatSizeWithRatio(lz4Size, uncompressedSize)}, ` +
|
||||||
|
`png4=${formatSizeWithRatio(pngSize, uncompressedSize)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
cumulativeTotals.uncompressed += frameTotals.uncompressed;
|
||||||
|
cumulativeTotals.lz4 += frameTotals.lz4;
|
||||||
|
cumulativeTotals.png += frameTotals.png;
|
||||||
|
|
||||||
|
return {
|
||||||
|
tileLines,
|
||||||
|
totalLine:
|
||||||
|
`compression estimate #${frameId} totals: ` +
|
||||||
|
`frame uncompressed=${frameTotals.uncompressed}, ` +
|
||||||
|
`lz4=${formatSizeWithRatio(frameTotals.lz4, frameTotals.uncompressed)}, ` +
|
||||||
|
`png4=${formatSizeWithRatio(frameTotals.png, frameTotals.uncompressed)}; ` +
|
||||||
|
`running uncompressed=${cumulativeTotals.uncompressed}, ` +
|
||||||
|
`lz4=${formatSizeWithRatio(cumulativeTotals.lz4, cumulativeTotals.uncompressed)}, ` +
|
||||||
|
`png4=${formatSizeWithRatio(cumulativeTotals.png, cumulativeTotals.uncompressed)}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodePng4BitGrayscaleFromBmpTile(tile: ImageTile): Uint8Array {
|
||||||
|
const pixelOffset = readUint32Le(tile.bmp, 10);
|
||||||
|
const sourceStride = (((tile.width + 1) >> 1) + 3) & ~3;
|
||||||
|
const pngRowBytes = (tile.width + 1) >> 1;
|
||||||
|
const scanlineStride = 1 + pngRowBytes;
|
||||||
|
const scanlines = new Uint8Array(scanlineStride * tile.height);
|
||||||
|
|
||||||
|
for (let y = 0; y < tile.height; y++) {
|
||||||
|
const sourceY = tile.height - 1 - y;
|
||||||
|
const sourceOffset = pixelOffset + sourceY * sourceStride;
|
||||||
|
const targetOffset = y * scanlineStride;
|
||||||
|
scanlines[targetOffset] = 0; // PNG filter type 0 keeps the 4-bit samples unchanged.
|
||||||
|
scanlines.set(tile.bmp.subarray(sourceOffset, sourceOffset + pngRowBytes), targetOffset + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const compressed = toUint8Array(pako.deflate(scanlines));
|
||||||
|
const ihdr = new Uint8Array(13);
|
||||||
|
const ihdrView = new DataView(ihdr.buffer);
|
||||||
|
ihdrView.setUint32(0, tile.width, false);
|
||||||
|
ihdrView.setUint32(4, tile.height, false);
|
||||||
|
ihdr[8] = 4; // bit depth: 4-bit grayscale
|
||||||
|
ihdr[9] = 0; // color type: grayscale
|
||||||
|
ihdr[10] = 0; // compression method
|
||||||
|
ihdr[11] = 0; // filter method
|
||||||
|
ihdr[12] = 0; // no interlace
|
||||||
|
|
||||||
|
return concatBytes(
|
||||||
|
PNG_SIGNATURE,
|
||||||
|
pngChunk("IHDR", ihdr),
|
||||||
|
pngChunk("IDAT", compressed),
|
||||||
|
pngChunk("IEND", new Uint8Array(0)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pngChunk(type: string, data: Uint8Array): Uint8Array {
|
||||||
|
const typeBytes = asciiBytes(type);
|
||||||
|
const chunk = new Uint8Array(12 + data.byteLength);
|
||||||
|
const view = new DataView(chunk.buffer);
|
||||||
|
view.setUint32(0, data.byteLength, false);
|
||||||
|
chunk.set(typeBytes, 4);
|
||||||
|
chunk.set(data, 8);
|
||||||
|
view.setUint32(8 + data.byteLength, crc32(typeBytes, data), false);
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PNG_SIGNATURE = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
||||||
|
const CRC_TABLE = buildCrcTable();
|
||||||
|
|
||||||
|
function crc32(typeBytes: Uint8Array, data: Uint8Array): number {
|
||||||
|
let crc = 0xffffffff;
|
||||||
|
crc = updateCrc32(crc, typeBytes);
|
||||||
|
crc = updateCrc32(crc, data);
|
||||||
|
return (crc ^ 0xffffffff) >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCrc32(crc: number, data: Uint8Array): number {
|
||||||
|
for (let i = 0; i < data.byteLength; i++) {
|
||||||
|
crc = CRC_TABLE[(crc ^ data[i]!) & 0xff]! ^ (crc >>> 8);
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildCrcTable(): Uint32Array {
|
||||||
|
const table = new Uint32Array(256);
|
||||||
|
for (let n = 0; n < table.length; n++) {
|
||||||
|
let c = n;
|
||||||
|
for (let k = 0; k < 8; k++) {
|
||||||
|
c = (c & 1) !== 0 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
||||||
|
}
|
||||||
|
table[n] = c >>> 0;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
function asciiBytes(value: string): Uint8Array {
|
||||||
|
const out = new Uint8Array(value.length);
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
out[i] = value.charCodeAt(i) & 0x7f;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function concatBytes(...parts: Uint8Array[]): Uint8Array {
|
||||||
|
const totalLength = parts.reduce((sum, part) => sum + part.byteLength, 0);
|
||||||
|
const out = new Uint8Array(totalLength);
|
||||||
|
let offset = 0;
|
||||||
|
for (const part of parts) {
|
||||||
|
out.set(part, offset);
|
||||||
|
offset += part.byteLength;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readUint32Le(bytes: Uint8Array, offset: number): number {
|
||||||
|
return (
|
||||||
|
(bytes[offset] ?? 0) |
|
||||||
|
((bytes[offset + 1] ?? 0) << 8) |
|
||||||
|
((bytes[offset + 2] ?? 0) << 16) |
|
||||||
|
((bytes[offset + 3] ?? 0) << 24)
|
||||||
|
) >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function byteLength(value: ArrayLike<number> | Uint8Array): number {
|
||||||
|
return value instanceof Uint8Array ? value.byteLength : value.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toUint8Array(value: ArrayLike<number> | Uint8Array): Uint8Array {
|
||||||
|
return value instanceof Uint8Array ? value : Uint8Array.from(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSizeWithRatio(size: number, uncompressedSize: number): string {
|
||||||
|
if (uncompressedSize <= 0) return `${size}`;
|
||||||
|
return `${size} (${((size / uncompressedSize) * 100).toFixed(1)}%)`;
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ const SWATCH_HEIGHT = 16;
|
|||||||
export class ScreenTestLayer implements Layer {
|
export class ScreenTestLayer implements Layer {
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
|
|
||||||
for (let value = 0; value < COLOR_VALUE_COUNT; value += COLOR_VALUE_STEP) {
|
for (let value = 0; value < COLOR_VALUE_COUNT; value += COLOR_VALUE_STEP) {
|
||||||
const slot = value / COLOR_VALUE_STEP;
|
const slot = value / COLOR_VALUE_STEP;
|
||||||
@@ -26,10 +28,10 @@ export class ScreenTestLayer implements Layer {
|
|||||||
const cellX = GRID_X + col * CELL_WIDTH;
|
const cellX = GRID_X + col * CELL_WIDTH;
|
||||||
const cellY = row * CELL_HEIGHT;
|
const cellY = row * CELL_HEIGHT;
|
||||||
const label = String(value);
|
const label = String(value);
|
||||||
const labelX = cellX + Math.max(0, Math.floor((CELL_WIDTH - ctx.font.measureText(label)) / 2));
|
const labelX = cellX + Math.max(0, Math.floor((CELL_WIDTH - font.measureText(label)) / 2));
|
||||||
const swatchX = cellX + Math.floor((CELL_WIDTH - SWATCH_WIDTH) / 2);
|
const swatchX = cellX + Math.floor((CELL_WIDTH - SWATCH_WIDTH) / 2);
|
||||||
|
|
||||||
image.drawText(ctx.font, labelX, cellY + LABEL_Y_OFFSET, label, 185);
|
image.drawText(font, labelX, cellY + LABEL_Y_OFFSET, label, 185);
|
||||||
fillSwatch(image, swatchX, cellY + SWATCH_Y_OFFSET, SWATCH_WIDTH, SWATCH_HEIGHT, value);
|
fillSwatch(image, swatchX, cellY + SWATCH_Y_OFFSET, SWATCH_WIDTH, SWATCH_HEIGHT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { loadEmbeddedTerminus32 } from "../../graphics/bdffont";
|
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
|
||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
||||||
|
|
||||||
const stopwatchFont = loadEmbeddedTerminus32();
|
const stopwatchFont = getFont("terminus32");
|
||||||
|
|
||||||
export class StopwatchLayer implements Layer {
|
export class StopwatchLayer implements Layer {
|
||||||
private readonly startedAtMs = Date.now();
|
private readonly startedAtMs = Date.now();
|
||||||
@@ -14,17 +14,18 @@ export class StopwatchLayer implements Layer {
|
|||||||
const elapsedMs = this.elapsedMs();
|
const elapsedMs = this.elapsedMs();
|
||||||
const timeLabel = formatStopwatchElapsed(elapsedMs);
|
const timeLabel = formatStopwatchElapsed(elapsedMs);
|
||||||
const stateLabel = this.pausedAtMs === null ? "Running" : "Paused";
|
const stateLabel = this.pausedAtMs === null ? "Running" : "Paused";
|
||||||
|
const smallFont = getDefaultSmallFont();
|
||||||
|
|
||||||
image.drawText(ctx.font, 24, 24, "Stopwatch", 180);
|
image.drawText(smallFont, 24, 24, "Stopwatch", 180);
|
||||||
|
|
||||||
const quadrantWidth = G2_LENS_WIDTH / 2;
|
const quadrantWidth = G2_LENS_WIDTH / 2;
|
||||||
const quadrantHeight = G2_LENS_HEIGHT / 2;
|
const quadrantHeight = G2_LENS_HEIGHT / 2;
|
||||||
const timeX = Math.max(0, Math.round((quadrantWidth - stopwatchFont.measureText(timeLabel)) / 2));
|
const timeX = Math.max(0, Math.round((quadrantWidth - stopwatchFont.measureText(timeLabel)) / 2));
|
||||||
const timeY = Math.max(0, Math.round((quadrantHeight - stopwatchFont.lineHeight) / 2));
|
const timeY = Math.max(0, Math.round((quadrantHeight - stopwatchFont.lineHeight) / 2));
|
||||||
image.drawText(stopwatchFont, timeX, timeY, timeLabel, 245);
|
image.drawText(stopwatchFont, timeX, timeY, timeLabel, 245);
|
||||||
image.drawText(ctx.font, 90, 142, stateLabel, 150);
|
image.drawText(smallFont, 90, 142, stateLabel, 150);
|
||||||
image.drawText(ctx.font, 90, 160, "Click: pause / resume", 150);
|
image.drawText(smallFont, 90, 160, "Click: pause / resume", 150);
|
||||||
image.drawText(ctx.font, 90, 178, "Double-click: back", 150);
|
image.drawText(smallFont, 90, 178, "Double-click: back", 150);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { wrapText } from "../../graphics/textwrap";
|
import { wrapText } from "../../graphics/textwrap";
|
||||||
import { type BdfFont } from "../../graphics/bdffont";
|
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
||||||
|
|
||||||
@@ -20,29 +20,30 @@ export class TelepromptLayer implements Layer {
|
|||||||
constructor(private readonly documentText: string | null) {}
|
constructor(private readonly documentText: string | null) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||||
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
|
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
|
||||||
image.drawText(ctx.font, MARGIN_X + 4, TITLE_Y, "Teleprompt", 220);
|
image.drawText(font, MARGIN_X + 4, TITLE_Y, "Teleprompt", 220);
|
||||||
|
|
||||||
if (this.documentText === null) {
|
if (this.documentText === null) {
|
||||||
const message = [
|
const message = [
|
||||||
"Open a plain text document on your phone and Share it to Faceclaw.",
|
"Open a plain text document on your phone and Share it to Faceclaw.",
|
||||||
];
|
];
|
||||||
for (let index = 0; index < message.length; index++) {
|
for (let index = 0; index < message.length; index++) {
|
||||||
image.drawText(ctx.font, BODY_X, BODY_Y + index * LINE_STEP, message[index]!, 200);
|
image.drawText(font, BODY_X, BODY_Y + index * LINE_STEP, message[index]!, 200);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lines = this.getLines(ctx.font);
|
const lines = this.getLines(font);
|
||||||
const visibleLines = lines.slice(this.firstLine, this.firstLine + BODY_LINE_COUNT);
|
const visibleLines = lines.slice(this.firstLine, this.firstLine + BODY_LINE_COUNT);
|
||||||
for (let index = 0; index < visibleLines.length; index++) {
|
for (let index = 0; index < visibleLines.length; index++) {
|
||||||
image.drawText(ctx.font, BODY_X, BODY_Y + index * LINE_STEP, visibleLines[index]!, 230);
|
image.drawText(font, BODY_X, BODY_Y + index * LINE_STEP, visibleLines[index]!, 230);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentPage = Math.floor(this.firstLine / PAGE_STEP) + 1;
|
const currentPage = Math.floor(this.firstLine / PAGE_STEP) + 1;
|
||||||
const totalPages = totalPageCount(lines.length);
|
const totalPages = totalPageCount(lines.length);
|
||||||
image.drawText(ctx.font, BODY_X, FOOTER_Y, `Page ${currentPage}/${totalPages}`, 110);
|
image.drawText(font, BODY_X, FOOTER_Y, `Page ${currentPage}/${totalPages}`, 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||||
import { type BdfFont } from "../../graphics/bdffont";
|
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||||
import { voiceControlBridge, type VoiceTranscriptEvent } from "../../native/voice-control";
|
import { voiceControlBridge, type VoiceTranscriptEvent } from "../../native/voice-control";
|
||||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
||||||
|
|
||||||
@@ -22,24 +22,25 @@ export class TranscribeLayer implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||||
const modeLabel = this.mode === "full" ? "Full" : this.mode === "wakeword" ? "Wakeword" : "Off";
|
const modeLabel = this.mode === "full" ? "Full" : this.mode === "wakeword" ? "Wakeword" : "Off";
|
||||||
const text = this.transcript || "Listening...";
|
const text = this.transcript || "Listening...";
|
||||||
const wrapped = wrapTranscribeText(ctx.font, text, G2_LENS_WIDTH - 64);
|
const wrapped = wrapTranscribeText(font, text, G2_LENS_WIDTH - 64);
|
||||||
|
|
||||||
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
|
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
|
||||||
image.drawText(ctx.font, 24, 24, "Transcribe", 200);
|
image.drawText(font, 24, 24, "Transcribe", 200);
|
||||||
image.drawText(ctx.font, G2_LENS_WIDTH - 108, 24, modeLabel, this.mode === "full" ? 220 : 130);
|
image.drawText(font, G2_LENS_WIDTH - 108, 24, modeLabel, this.mode === "full" ? 220 : 130);
|
||||||
//image.drawText(ctx.font, 24, 46, truncateTranscribeLine(this.status, 74), 110);
|
//image.drawText(font, 24, 46, truncateTranscribeLine(this.status, 74), 110);
|
||||||
image.drawText(ctx.font, 24, 46, this.status, 110);
|
image.drawText(font, 24, 46, this.status, 110);
|
||||||
|
|
||||||
const firstLine = Math.max(0, wrapped.length - 10);
|
const firstLine = Math.max(0, wrapped.length - 10);
|
||||||
for (let index = firstLine; index < wrapped.length; index++) {
|
for (let index = firstLine; index < wrapped.length; index++) {
|
||||||
const y = 72 + (index - firstLine) * 16;
|
const y = 72 + (index - firstLine) * 16;
|
||||||
image.drawText(ctx.font, 32, y, wrapped[index]!, 230);
|
image.drawText(font, 32, y, wrapped[index]!, 230);
|
||||||
}
|
}
|
||||||
|
|
||||||
image.drawText(ctx.font, 24, 252, "Click: mode / Double-click: back", 110);
|
image.drawText(font, 24, 252, "Click: mode / Double-click: back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+46
-41
@@ -1,6 +1,6 @@
|
|||||||
import takeRight from "lodash/takeRight";
|
import takeRight from "lodash/takeRight";
|
||||||
|
|
||||||
import { BdfFont, loadEmbeddedTerminus24 } from "../graphics/bdffont";
|
import { BdfFont, getDefaultLargeFont, getDefaultSmallFont } from "../graphics/bdffont";
|
||||||
import { GrayImage, imageFromAsciiArt } from "../graphics/image";
|
import { GrayImage, imageFromAsciiArt } from "../graphics/image";
|
||||||
import { wrapText } from "../graphics/textwrap";
|
import { wrapText } from "../graphics/textwrap";
|
||||||
import { mediaControllerBridge, type MediaControllerState } from "../native/media-controller";
|
import { mediaControllerBridge, type MediaControllerState } from "../native/media-controller";
|
||||||
@@ -26,7 +26,6 @@ export type DashboardPluginCardRenderArgs = {
|
|||||||
image: GrayImage;
|
image: GrayImage;
|
||||||
bounds: DashboardPluginCardBounds;
|
bounds: DashboardPluginCardBounds;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
font: BdfFont;
|
|
||||||
state: DashboardPluginState;
|
state: DashboardPluginState;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,7 +46,8 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
|
|||||||
{
|
{
|
||||||
id: "input-debug-log",
|
id: "input-debug-log",
|
||||||
label: "Input debug log",
|
label: "Input debug log",
|
||||||
renderCard: ({ image, bounds, font, state }) => {
|
renderCard: ({ image, bounds, state }) => {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
image.drawText(font, bounds.x + 10, bounds.y + 14, "Input log", 180);
|
image.drawText(font, bounds.x + 10, bounds.y + 14, "Input log", 180);
|
||||||
const lineHeight = 14;
|
const lineHeight = 14;
|
||||||
const visibleLineCount = Math.max(1, Math.floor((bounds.height - 28) / lineHeight));
|
const visibleLineCount = Math.max(1, Math.floor((bounds.height - 28) / lineHeight));
|
||||||
@@ -61,7 +61,8 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
|
|||||||
{
|
{
|
||||||
id: "music-controller",
|
id: "music-controller",
|
||||||
label: "Music controller",
|
label: "Music controller",
|
||||||
renderCard: ({ image, bounds, font, state }) => {
|
renderCard: ({ image, bounds, state }) => {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const media = state.media;
|
const media = state.media;
|
||||||
image.drawText(font, bounds.x + 10, bounds.y + 14, "Now playing", 180);
|
image.drawText(font, bounds.x + 10, bounds.y + 14, "Now playing", 180);
|
||||||
if (!media.accessEnabled) {
|
if (!media.accessEnabled) {
|
||||||
@@ -88,7 +89,8 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
|
|||||||
{
|
{
|
||||||
id: "nightscout",
|
id: "nightscout",
|
||||||
label: "Nightscout",
|
label: "Nightscout",
|
||||||
renderCard: ({ image, bounds, font, state }) => {
|
renderCard: ({ image, bounds, state }) => {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const nightscout = state.nightscout;
|
const nightscout = state.nightscout;
|
||||||
const nowMs = Date.now();
|
const nowMs = Date.now();
|
||||||
image.drawText(font, bounds.x + 10, bounds.y + 10, "Nightscout", 180);
|
image.drawText(font, bounds.x + 10, bounds.y + 10, "Nightscout", 180);
|
||||||
@@ -146,7 +148,7 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
|
|||||||
const PLUGIN_MAP = new Map<DashboardPluginId, DashboardPlugin>(
|
const PLUGIN_MAP = new Map<DashboardPluginId, DashboardPlugin>(
|
||||||
DASHBOARD_PLUGINS.map((plugin) => [plugin.id, plugin]),
|
DASHBOARD_PLUGINS.map((plugin) => [plugin.id, plugin]),
|
||||||
);
|
);
|
||||||
const nightscoutLargeFont = loadEmbeddedTerminus24();
|
const nightscoutLargeFont = getDefaultLargeFont();
|
||||||
const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
|
const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
|
||||||
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
|
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
|
||||||
const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
|
const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
|
||||||
@@ -489,9 +491,10 @@ class DebugLogLayer implements Layer {
|
|||||||
constructor(private readonly getState: () => DashboardPluginState) {}
|
constructor(private readonly getState: () => DashboardPluginState) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(576, 288, 0);
|
const image = new GrayImage(576, 288, 0);
|
||||||
image.drawRect(12, 12, 552, 264, 52);
|
image.drawRect(12, 12, 552, 264, 52);
|
||||||
image.drawText(ctx.font, 22, 16, "Input debug log", 220);
|
image.drawText(font, 22, 16, "Input debug log", 220);
|
||||||
|
|
||||||
const logs = this.getState().logLines;
|
const logs = this.getState().logLines;
|
||||||
const lineHeight = 14;
|
const lineHeight = 14;
|
||||||
@@ -501,9 +504,9 @@ class DebugLogLayer implements Layer {
|
|||||||
const start = Math.max(0, maxOffset - this.scrollOffset);
|
const start = Math.max(0, maxOffset - this.scrollOffset);
|
||||||
const visible = logs.slice(start, start + visibleCount);
|
const visible = logs.slice(start, start + visibleCount);
|
||||||
for (let index = 0; index < visible.length; index++) {
|
for (let index = 0; index < visible.length; index++) {
|
||||||
image.drawText(ctx.font, 22, 42 + index * lineHeight, visible[index]!, 180);
|
image.drawText(font, 22, 42 + index * lineHeight, visible[index]!, 180);
|
||||||
}
|
}
|
||||||
image.drawText(ctx.font, 22, 252, "Scroll: browse Double-click: back", 110);
|
image.drawText(font, 22, 252, "Scroll: browse Double-click: back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,40 +531,41 @@ class MusicControllerLayer implements Layer {
|
|||||||
constructor(private readonly getState: () => DashboardPluginState) {}
|
constructor(private readonly getState: () => DashboardPluginState) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(576, 288, 0);
|
const image = new GrayImage(576, 288, 0);
|
||||||
const media = this.getState().media;
|
const media = this.getState().media;
|
||||||
image.drawRect(12, 12, 552, 264, 52);
|
image.drawRect(12, 12, 552, 264, 52);
|
||||||
image.drawText(ctx.font, 22, 16, "Music controller", 220);
|
image.drawText(font, 22, 16, "Music controller", 220);
|
||||||
|
|
||||||
if (!media.accessEnabled) {
|
if (!media.accessEnabled) {
|
||||||
const lines = wrapText(
|
const lines = wrapText(
|
||||||
ctx.font,
|
font,
|
||||||
"Notification access is required before Android will expose active media sessions to Faceclaw. Click to open settings.",
|
"Notification access is required before Android will expose active media sessions to Faceclaw. Click to open settings.",
|
||||||
520,
|
520,
|
||||||
);
|
);
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
image.drawText(ctx.font, 22, 44 + i * 14, lines[i]!, 180);
|
image.drawText(font, 22, 44 + i * 14, lines[i]!, 180);
|
||||||
}
|
}
|
||||||
image.drawText(ctx.font, 22, 252, "Click: open settings Double-click: back", 110);
|
image.drawText(font, 22, 252, "Click: open settings Double-click: back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!media.available) {
|
if (!media.available) {
|
||||||
image.drawText(ctx.font, 22, 44, "No active media session.", 180);
|
image.drawText(font, 22, 44, "No active media session.", 180);
|
||||||
image.drawText(ctx.font, 22, 58, "Start playback in another app,", 180);
|
image.drawText(font, 22, 58, "Start playback in another app,", 180);
|
||||||
image.drawText(ctx.font, 22, 72, "then reopen this card.", 180);
|
image.drawText(font, 22, 72, "then reopen this card.", 180);
|
||||||
image.drawText(ctx.font, 22, 252, "Double-click: back", 110);
|
image.drawText(font, 22, 252, "Double-click: back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
image.drawText(ctx.font, 22, 44, media.title || "Unknown title", 220);
|
image.drawText(font, 22, 44, media.title || "Unknown title", 220);
|
||||||
image.drawText(ctx.font, 22, 60, media.artist || media.album || "Unknown artist", 180);
|
image.drawText(font, 22, 60, media.artist || media.album || "Unknown artist", 180);
|
||||||
image.drawText(ctx.font, 22, 76, media.packageName, 130);
|
image.drawText(font, 22, 76, media.packageName, 130);
|
||||||
image.drawText(ctx.font, 22, 104, `State: ${playbackLabel(media)}`, 180);
|
image.drawText(font, 22, 104, `State: ${playbackLabel(media)}`, 180);
|
||||||
image.drawText(ctx.font, 22, 132, "Click: play/pause", 180);
|
image.drawText(font, 22, 132, "Click: play/pause", 180);
|
||||||
image.drawText(ctx.font, 22, 146, "Scroll up: previous", 180);
|
image.drawText(font, 22, 146, "Scroll up: previous", 180);
|
||||||
image.drawText(ctx.font, 22, 160, "Scroll down: next", 180);
|
image.drawText(font, 22, 160, "Scroll down: next", 180);
|
||||||
image.drawText(ctx.font, 22, 252, "Double-click: back", 110);
|
image.drawText(font, 22, 252, "Double-click: back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,23 +602,24 @@ class NightscoutLayer implements Layer {
|
|||||||
constructor(private readonly getState: () => DashboardPluginState) {}
|
constructor(private readonly getState: () => DashboardPluginState) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(576, 288, 0);
|
const image = new GrayImage(576, 288, 0);
|
||||||
const nightscout = this.getState().nightscout;
|
const nightscout = this.getState().nightscout;
|
||||||
const nowMs = Date.now();
|
const nowMs = Date.now();
|
||||||
image.drawRect(12, 12, 552, 264, 52);
|
image.drawRect(12, 12, 552, 264, 52);
|
||||||
image.drawText(ctx.font, 22, 16, "Nightscout", 220);
|
image.drawText(font, 22, 16, "Nightscout", 220);
|
||||||
|
|
||||||
if (!this.getState().nightscoutConfigured || nightscout.configurationMissing) {
|
if (!this.getState().nightscoutConfigured || nightscout.configurationMissing) {
|
||||||
image.drawText(ctx.font, 22, 44, "Nightscout needs configuration.", 180);
|
image.drawText(font, 22, 44, "Nightscout needs configuration.", 180);
|
||||||
image.drawText(ctx.font, 22, 62, "Double-click and use Settings", 140);
|
image.drawText(font, 22, 62, "Double-click and use Settings", 140);
|
||||||
image.drawText(ctx.font, 22, 78, "Integrations > Nightscout.", 140);
|
image.drawText(font, 22, 78, "Integrations > Nightscout.", 140);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nightscout.available || !nightscout.latest) {
|
if (!nightscout.available || !nightscout.latest) {
|
||||||
image.drawText(ctx.font, 22, 44, "No Nightscout data available.", 180);
|
image.drawText(font, 22, 44, "No Nightscout data available.", 180);
|
||||||
image.drawText(ctx.font, 22, 58, truncateLine(nightscout.status, 60), 140);
|
image.drawText(font, 22, 58, truncateLine(nightscout.status, 60), 140);
|
||||||
image.drawText(ctx.font, 22, 252, "Click: refresh Double-click: back", 110);
|
image.drawText(font, 22, 252, "Click: refresh Double-click: back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,28 +631,28 @@ class NightscoutLayer implements Layer {
|
|||||||
if (isNightscoutPointStale(latest, nowMs)) {
|
if (isNightscoutPointStale(latest, nowMs)) {
|
||||||
drawNightscoutValueStrikeThrough(image, glucoseX, 40, glucoseWidth);
|
drawNightscoutValueStrikeThrough(image, glucoseX, 40, glucoseWidth);
|
||||||
}
|
}
|
||||||
image.drawText(ctx.font, glucoseX + glucoseWidth + 8, 36, nightscout.units, 140);
|
image.drawText(font, glucoseX + glucoseWidth + 8, 36, nightscout.units, 140);
|
||||||
const trendText = `Delta ${formatDelta(nightscout.delta)} Trend `;
|
const trendText = `Delta ${formatDelta(nightscout.delta)} Trend `;
|
||||||
image.drawText(ctx.font, 22, 62, trendText, 180);
|
image.drawText(font, 22, 62, trendText, 180);
|
||||||
drawDirectionIndicator(image, ctx.font, 22 + ctx.font.measureText(trendText), 62, nightscout.direction, 180);
|
drawDirectionIndicator(image, font, 22 + font.measureText(trendText), 62, nightscout.direction, 180);
|
||||||
image.drawText(
|
image.drawText(
|
||||||
ctx.font,
|
font,
|
||||||
22,
|
22,
|
||||||
78,
|
78,
|
||||||
`IOB ${nightscout.iob === null ? "--" : nightscout.iob.toFixed(2)} COB ${nightscout.cob === null ? "--" : formatWholeNumber(nightscout.cob)} Updated ${formatTimestamp(latest.timestampMs)}`,
|
`IOB ${nightscout.iob === null ? "--" : nightscout.iob.toFixed(2)} COB ${nightscout.cob === null ? "--" : formatWholeNumber(nightscout.cob)} Updated ${formatTimestamp(latest.timestampMs)}`,
|
||||||
160,
|
160,
|
||||||
);
|
);
|
||||||
image.drawText(
|
image.drawText(
|
||||||
ctx.font,
|
font,
|
||||||
22,
|
22,
|
||||||
94,
|
94,
|
||||||
`CAGE ${formatAgeShortFromTimestamp(nightscout.cageTimestampMs, nowMs)} Loop ${nightscout.openapsStatusShort}`,
|
`CAGE ${formatAgeShortFromTimestamp(nightscout.cageTimestampMs, nowMs)} Loop ${nightscout.openapsStatusShort}`,
|
||||||
160,
|
160,
|
||||||
);
|
);
|
||||||
image.drawText(ctx.font, 22, 110, `Pump ${truncateLine(nightscout.pumpStatus || "--", 56)}`, 150);
|
image.drawText(font, 22, 110, `Pump ${truncateLine(nightscout.pumpStatus || "--", 56)}`, 150);
|
||||||
drawNightscoutGraph(image, { x: 22, y: 128, width: 532, height: 96 }, nightscout, nowMs, ctx.font);
|
drawNightscoutGraph(image, { x: 22, y: 128, width: 532, height: 96 }, nightscout, nowMs, font);
|
||||||
image.drawText(ctx.font, 22, 234, "2-hour glucose history with basal / carbs / boluses", 130);
|
image.drawText(font, 22, 234, "2-hour glucose history with basal / carbs / boluses", 130);
|
||||||
image.drawText(ctx.font, 22, 252, "Click: refresh Double-click: back", 110);
|
image.drawText(font, 22, 252, "Click: refresh Double-click: back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ export const DEFAULT_SYSTEM_CARD_NAME = "Faceclaw";
|
|||||||
export const DEFAULT_SCREEN_TIMEOUT: ScreenTimeoutSetting = "30s";
|
export const DEFAULT_SCREEN_TIMEOUT: ScreenTimeoutSetting = "30s";
|
||||||
export const DEFAULT_WAKE_MODE: WakeModeSetting = "tiled";
|
export const DEFAULT_WAKE_MODE: WakeModeSetting = "tiled";
|
||||||
export const DEFAULT_VOICE_CONTROL_ENABLED = false;
|
export const DEFAULT_VOICE_CONTROL_ENABLED = false;
|
||||||
|
export const DEFAULT_ESTIMATE_COMPRESSION_RATIOS_ENABLED = false;
|
||||||
const SYSTEM_CARD_NAME_KEY = "dashboard.systemCardName";
|
const SYSTEM_CARD_NAME_KEY = "dashboard.systemCardName";
|
||||||
const SCREEN_TIMEOUT_KEY = "display.screenTimeout";
|
const SCREEN_TIMEOUT_KEY = "display.screenTimeout";
|
||||||
const WAKE_MODE_KEY = "display.wakeMode";
|
const WAKE_MODE_KEY = "display.wakeMode";
|
||||||
const VOICE_CONTROL_ENABLED_KEY = "voice.enabled";
|
const VOICE_CONTROL_ENABLED_KEY = "voice.enabled";
|
||||||
|
const ESTIMATE_COMPRESSION_RATIOS_ENABLED_KEY = "debug.estimateCompressionRatios";
|
||||||
const SYSTEM_CARD_SETTING_KEYS: Record<SystemCardSettingKey, string> = {
|
const SYSTEM_CARD_SETTING_KEYS: Record<SystemCardSettingKey, string> = {
|
||||||
showFaceclawLogo: "dashboard.systemCard.showFaceclawLogo",
|
showFaceclawLogo: "dashboard.systemCard.showFaceclawLogo",
|
||||||
showBatteryIndicators: "dashboard.systemCard.showBatteryIndicators",
|
showBatteryIndicators: "dashboard.systemCard.showBatteryIndicators",
|
||||||
@@ -149,6 +151,18 @@ export function saveVoiceControlEnabled(value: boolean): boolean {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function loadEstimateCompressionRatiosEnabled(): boolean {
|
||||||
|
return ApplicationSettings.getBoolean(
|
||||||
|
ESTIMATE_COMPRESSION_RATIOS_ENABLED_KEY,
|
||||||
|
DEFAULT_ESTIMATE_COMPRESSION_RATIOS_ENABLED,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveEstimateCompressionRatiosEnabled(value: boolean): boolean {
|
||||||
|
ApplicationSettings.setBoolean(ESTIMATE_COMPRESSION_RATIOS_ENABLED_KEY, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
export function nextScreenTimeoutSetting(value: ScreenTimeoutSetting): ScreenTimeoutSetting {
|
export function nextScreenTimeoutSetting(value: ScreenTimeoutSetting): ScreenTimeoutSetting {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case "15s":
|
case "15s":
|
||||||
|
|||||||
+33
-5
@@ -1,5 +1,5 @@
|
|||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||||
import { loadEmbeddedTerminus12, loadEmbeddedTerminus16, loadEmbeddedTerminus32 } from "../graphics/bdffont";
|
import { getDefaultMediumFont, getDefaultSmallFont } from "../graphics/bdffont";
|
||||||
import { BATTERY_ICON_WIDTH, drawBattery } from "../graphics/battery";
|
import { BATTERY_ICON_WIDTH, drawBattery } from "../graphics/battery";
|
||||||
import { loadPngAsGrayImage } from "../graphics/imagefile";
|
import { loadPngAsGrayImage } from "../graphics/imagefile";
|
||||||
import { type RawInputEvent } from "../native/faceclaw-communicator";
|
import { type RawInputEvent } from "../native/faceclaw-communicator";
|
||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
getDashboardSlotIds,
|
getDashboardSlotIds,
|
||||||
isNightscoutSettingsConfigured,
|
isNightscoutSettingsConfigured,
|
||||||
loadDashboardSlotConfig,
|
loadDashboardSlotConfig,
|
||||||
|
loadEstimateCompressionRatiosEnabled,
|
||||||
loadNightscoutSettings,
|
loadNightscoutSettings,
|
||||||
loadScreenTimeoutSetting,
|
loadScreenTimeoutSetting,
|
||||||
loadSystemCardSettings,
|
loadSystemCardSettings,
|
||||||
@@ -31,6 +32,7 @@ import {
|
|||||||
nextScreenTimeoutSetting,
|
nextScreenTimeoutSetting,
|
||||||
nextWakeModeSetting,
|
nextWakeModeSetting,
|
||||||
saveDashboardSlotPlugin,
|
saveDashboardSlotPlugin,
|
||||||
|
saveEstimateCompressionRatiosEnabled,
|
||||||
saveNightscoutApiToken,
|
saveNightscoutApiToken,
|
||||||
saveNightscoutSiteUrl,
|
saveNightscoutSiteUrl,
|
||||||
saveScreenTimeoutSetting,
|
saveScreenTimeoutSetting,
|
||||||
@@ -72,6 +74,7 @@ let dashboardState = {
|
|||||||
screenTimeout: loadScreenTimeoutSetting(),
|
screenTimeout: loadScreenTimeoutSetting(),
|
||||||
wakeMode: loadWakeModeSetting(),
|
wakeMode: loadWakeModeSetting(),
|
||||||
voiceControlEnabled: loadVoiceControlEnabled(),
|
voiceControlEnabled: loadVoiceControlEnabled(),
|
||||||
|
estimateCompressionRatiosEnabled: loadEstimateCompressionRatiosEnabled(),
|
||||||
tiledWakePaintPending: false,
|
tiledWakePaintPending: false,
|
||||||
telepromptDocumentText: null as string | null,
|
telepromptDocumentText: null as string | null,
|
||||||
nightscoutSettings: loadNightscoutSettings(),
|
nightscoutSettings: loadNightscoutSettings(),
|
||||||
@@ -96,8 +99,8 @@ const dashboardActions: LayerActions = {
|
|||||||
startDedicatedVoiceInput: () => {},
|
startDedicatedVoiceInput: () => {},
|
||||||
stopDedicatedVoiceInput: () => {},
|
stopDedicatedVoiceInput: () => {},
|
||||||
};
|
};
|
||||||
const dashboardFont = loadEmbeddedTerminus12();
|
const dashboardFont = getDefaultSmallFont();
|
||||||
const dashboardSystemFont = loadEmbeddedTerminus16();
|
const dashboardSystemFont = getDefaultMediumFont();
|
||||||
const NOTIFICATION_ICON_SIZE = 24;
|
const NOTIFICATION_ICON_SIZE = 24;
|
||||||
const SYSTEM_CARD_ITEM_HEIGHT = 38;
|
const SYSTEM_CARD_ITEM_HEIGHT = 38;
|
||||||
const SYSTEM_CARD_ITEM_GAP = 2;
|
const SYSTEM_CARD_ITEM_GAP = 2;
|
||||||
@@ -245,6 +248,10 @@ export function setDashboardVoiceControlEnabled(value: boolean): void {
|
|||||||
dashboardState.voiceControlEnabled = saveVoiceControlEnabled(value);
|
dashboardState.voiceControlEnabled = saveVoiceControlEnabled(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isDashboardCompressionRatioEstimationEnabled(): boolean {
|
||||||
|
return dashboardState.estimateCompressionRatiosEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
export function applyDashboardScreenTimeout(nowMs = Date.now()): boolean {
|
export function applyDashboardScreenTimeout(nowMs = Date.now()): boolean {
|
||||||
const timeoutMs = screenTimeoutMs(dashboardState.screenTimeout);
|
const timeoutMs = screenTimeoutMs(dashboardState.screenTimeout);
|
||||||
if (timeoutMs === null || !dashboardState.screenOn) return false;
|
if (timeoutMs === null || !dashboardState.screenOn) return false;
|
||||||
@@ -439,7 +446,6 @@ class DashboardLayer implements Layer {
|
|||||||
image,
|
image,
|
||||||
bounds,
|
bounds,
|
||||||
selected: false,
|
selected: false,
|
||||||
font: dashboardFont,
|
|
||||||
state: pluginState,
|
state: pluginState,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -648,6 +654,24 @@ function createDisplaySettingsMenuLayer(): MenuLayer {
|
|||||||
drawRightValueMenuItem(image, dashboardFont, x, y, width, "Wake mode", wakeModeLabel(dashboardState.wakeMode));
|
drawRightValueMenuItem(image, dashboardFont, x, y, width, "Wake mode", wakeModeLabel(dashboardState.wakeMode));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Estimate compression ratios",
|
||||||
|
onSelect: () => {
|
||||||
|
setEstimateCompressionRatiosEnabled(!dashboardState.estimateCompressionRatiosEnabled);
|
||||||
|
},
|
||||||
|
render: ({ image, x, y, width, selected }) => {
|
||||||
|
drawToggleMenuItem(
|
||||||
|
image,
|
||||||
|
dashboardFont,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
"Estimate compression ratios",
|
||||||
|
dashboardState.estimateCompressionRatiosEnabled,
|
||||||
|
selected,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
TOP_LEFT_MENU_LAYOUT,
|
TOP_LEFT_MENU_LAYOUT,
|
||||||
);
|
);
|
||||||
@@ -662,6 +686,10 @@ function setWakeMode(value: WakeModeSetting): void {
|
|||||||
dashboardState.wakeMode = saveWakeModeSetting(value);
|
dashboardState.wakeMode = saveWakeModeSetting(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setEstimateCompressionRatiosEnabled(value: boolean): void {
|
||||||
|
dashboardState.estimateCompressionRatiosEnabled = saveEstimateCompressionRatiosEnabled(value);
|
||||||
|
}
|
||||||
|
|
||||||
function createVoiceSettingsMenuLayer(): MenuLayer {
|
function createVoiceSettingsMenuLayer(): MenuLayer {
|
||||||
return new MenuLayer(
|
return new MenuLayer(
|
||||||
"Settings > Voice",
|
"Settings > Voice",
|
||||||
@@ -935,6 +963,6 @@ function maskToken(token: string): string {
|
|||||||
return token.length <= 6 ? "******" : `${token.slice(0, 2)}...${token.slice(-4)}`;
|
return token.length <= 6 ? "******" : `${token.slice(0, 2)}...${token.slice(-4)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dashboardLayers = new LayerStack(new DashboardLayer(), dashboardFont, dashboardActions);
|
const dashboardLayers = new LayerStack(new DashboardLayer(), dashboardActions);
|
||||||
dashboardLayers.push(createRootMenuLayer());
|
dashboardLayers.push(createRootMenuLayer());
|
||||||
|
|
||||||
+1
-3
@@ -26,7 +26,6 @@ export type PaintBelow = () => GrayImage;
|
|||||||
|
|
||||||
export interface LayerContext {
|
export interface LayerContext {
|
||||||
readonly stack: LayerStack;
|
readonly stack: LayerStack;
|
||||||
readonly font: BdfFont;
|
|
||||||
readonly actions: LayerActions;
|
readonly actions: LayerActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,11 +39,10 @@ export class LayerStack {
|
|||||||
private readonly layers: Layer[];
|
private readonly layers: Layer[];
|
||||||
private readonly ctx: LayerContext;
|
private readonly ctx: LayerContext;
|
||||||
|
|
||||||
constructor(baseLayer: Layer, font: BdfFont, actions: LayerActions) {
|
constructor(baseLayer: Layer, actions: LayerActions) {
|
||||||
this.layers = [baseLayer];
|
this.layers = [baseLayer];
|
||||||
this.ctx = {
|
this.ctx = {
|
||||||
stack: this,
|
stack: this,
|
||||||
font,
|
|
||||||
actions,
|
actions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-7
@@ -1,6 +1,6 @@
|
|||||||
import { GrayImage } from "../graphics/image";
|
import { GrayImage } from "../graphics/image";
|
||||||
import { wrapText } from "../graphics/textwrap";
|
import { wrapText } from "../graphics/textwrap";
|
||||||
import { type BdfFont } from "../graphics/bdffont";
|
import { getDefaultSmallFont, type BdfFont } from "../graphics/bdffont";
|
||||||
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "./layers";
|
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "./layers";
|
||||||
|
|
||||||
const DEFAULT_MENU_X = 8;
|
const DEFAULT_MENU_X = 8;
|
||||||
@@ -92,12 +92,13 @@ export class MenuLayer implements Layer {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const { x, y, width, height } = this.layout;
|
const { x, y, width, height } = this.layout;
|
||||||
const image = paintBelow();
|
const image = paintBelow();
|
||||||
image.fillRoundedRect(x, y, width, height, 0);
|
image.fillRoundedRect(x, y, width, height, 0);
|
||||||
image.drawRoundedRect(x, y, width, height, 72);
|
image.drawRoundedRect(x, y, width, height, 72);
|
||||||
if (this.title) {
|
if (this.title) {
|
||||||
image.drawText(ctx.font, x + 12, y + 8, this.title, 220);
|
image.drawText(font, x + 12, y + 8, this.title, 220);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bodyY = y + (this.title ? MENU_TITLE_HEIGHT : 0) + 8;
|
const bodyY = y + (this.title ? MENU_TITLE_HEIGHT : 0) + 8;
|
||||||
@@ -121,7 +122,7 @@ export class MenuLayer implements Layer {
|
|||||||
ctx,
|
ctx,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
image.drawText(ctx.font, x + 22, y + 3, item.label, selected ? 255 : 200);
|
image.drawText(font, x + 22, y + 3, item.label, selected ? 255 : 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,15 +162,16 @@ export class TextPageLayer implements Layer {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(576, 288, 0);
|
const image = new GrayImage(576, 288, 0);
|
||||||
image.drawText(ctx.font, 18, 14, this.title, 220);
|
image.drawText(font, 18, 14, this.title, 220);
|
||||||
image.drawRect(12, 12, 552, 264, 52);
|
image.drawRect(12, 12, 552, 264, 52);
|
||||||
|
|
||||||
const wrapped = wrapText(ctx.font, this.body, 520);
|
const wrapped = wrapText(font, this.body, 520);
|
||||||
for (let index = 0; index < wrapped.length; index++) {
|
for (let index = 0; index < wrapped.length; index++) {
|
||||||
image.drawText(ctx.font, 24, 42 + index * 14, wrapped[index]!, 190);
|
image.drawText(font, 24, 42 + index * 14, wrapped[index]!, 190);
|
||||||
}
|
}
|
||||||
image.drawText(ctx.font, 24, 252, "Double-click to go back", 110);
|
image.drawText(font, 24, 252, "Double-click to go back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-17
@@ -1,4 +1,4 @@
|
|||||||
import { BdfFont } from "../graphics/bdffont";
|
import { BdfFont, getDefaultSmallFont } from "../graphics/bdffont";
|
||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||||
import { wrapText } from "../graphics/textwrap";
|
import { wrapText } from "../graphics/textwrap";
|
||||||
import {
|
import {
|
||||||
@@ -40,20 +40,21 @@ export class NotificationsListLayer implements Layer {
|
|||||||
constructor(private readonly exitToRootMenu?: (ctx: LayerContext) => void) {}
|
constructor(private readonly exitToRootMenu?: (ctx: LayerContext) => void) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||||
const notifications = readActiveNotifications(MAX_NOTIFICATIONS);
|
const notifications = readActiveNotifications(MAX_NOTIFICATIONS);
|
||||||
const selectedIndex = this.resolveSelectedIndex(notifications);
|
const selectedIndex = this.resolveSelectedIndex(notifications);
|
||||||
const layouts = notifications.map((notification, index) =>
|
const layouts = notifications.map((notification, index) =>
|
||||||
buildNotificationCardLayout(ctx.font, notification, index === selectedIndex),
|
buildNotificationCardLayout(font, notification, index === selectedIndex),
|
||||||
);
|
);
|
||||||
|
|
||||||
image.drawRect(PAGE_X, PAGE_Y, PAGE_WIDTH, PAGE_HEIGHT, 52);
|
image.drawRect(PAGE_X, PAGE_Y, PAGE_WIDTH, PAGE_HEIGHT, 52);
|
||||||
image.drawText(ctx.font, PAGE_X + 12, PAGE_Y + 9, "Notifications", 220);
|
image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Notifications", 220);
|
||||||
image.drawText(ctx.font, G2_LENS_WIDTH - 96, PAGE_Y + 9, `${notifications.length} active`, 150);
|
image.drawText(font, G2_LENS_WIDTH - 96, PAGE_Y + 9, `${notifications.length} active`, 150);
|
||||||
|
|
||||||
if (!notifications.length) {
|
if (!notifications.length) {
|
||||||
image.drawText(ctx.font, 24, 72, "No current Android notifications.", 190);
|
image.drawText(font, 24, 72, "No current Android notifications.", 190);
|
||||||
image.drawText(ctx.font, 24, 252, "Double-click to return to dashboard", 110);
|
image.drawText(font, 24, 252, "Double-click to return to dashboard", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +63,14 @@ export class NotificationsListLayer implements Layer {
|
|||||||
for (let index = 0; index < layouts.length; index++) {
|
for (let index = 0; index < layouts.length; index++) {
|
||||||
const layout = layouts[index]!;
|
const layout = layouts[index]!;
|
||||||
if (cursorY + layout.height >= LIST_TOP && cursorY <= LIST_BOTTOM) {
|
if (cursorY + layout.height >= LIST_TOP && cursorY <= LIST_BOTTOM) {
|
||||||
drawNotificationCard(image, ctx.font, layout, CARD_X, cursorY, CARD_WIDTH, index === selectedIndex);
|
drawNotificationCard(image, font, layout, CARD_X, cursorY, CARD_WIDTH, index === selectedIndex);
|
||||||
}
|
}
|
||||||
cursorY += layout.height + CARD_GAP;
|
cursorY += layout.height + CARD_GAP;
|
||||||
if (cursorY > LIST_BOTTOM + 80) break;
|
if (cursorY > LIST_BOTTOM + 80) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const footer = `${selectedIndex + 1}/${notifications.length} tap: open double: dashboard`;
|
const footer = `${selectedIndex + 1}/${notifications.length} tap: open double: dashboard`;
|
||||||
image.drawText(ctx.font, PAGE_X + 12, 258, footer, 110);
|
image.drawText(font, PAGE_X + 12, 258, footer, 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,21 +120,21 @@ export class SingleNotificationLayer implements Layer {
|
|||||||
constructor(private readonly notificationKey: string) {}
|
constructor(private readonly notificationKey: string) {}
|
||||||
|
|
||||||
paint(ctx: LayerContext, _paintBelow: PaintBelow): GrayImage {
|
paint(ctx: LayerContext, _paintBelow: PaintBelow): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||||
const notification = readActiveNotifications(MAX_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
const notification = readActiveNotifications(MAX_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
|
||||||
|
|
||||||
image.drawRect(PAGE_X, PAGE_Y, PAGE_WIDTH, PAGE_HEIGHT, 52);
|
|
||||||
if (!notification) {
|
if (!notification) {
|
||||||
image.drawText(ctx.font, PAGE_X + 12, PAGE_Y + 9, "Notification", 220);
|
image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Notification", 220);
|
||||||
image.drawText(ctx.font, 24, 72, "This notification is no longer active.", 190);
|
image.drawText(font, 24, 72, "This notification is no longer active.", 190);
|
||||||
image.drawText(ctx.font, 24, 252, "Double-click to go back", 110);
|
image.drawText(font, 24, 252, "Double-click to go back", 110);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
const menu = buildDetailMenu(notification);
|
const menu = buildDetailMenu(notification);
|
||||||
this.selectedMenuIndex = clamp(this.selectedMenuIndex, 0, Math.max(0, menu.length - 1));
|
this.selectedMenuIndex = clamp(this.selectedMenuIndex, 0, Math.max(0, menu.length - 1));
|
||||||
drawDetailContent(image, ctx.font, notification);
|
drawDetailContent(image, font, notification);
|
||||||
drawDetailMenu(image, ctx.font, menu, this.selectedMenuIndex);
|
drawDetailMenu(image, font, menu, this.selectedMenuIndex);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,9 +264,8 @@ function drawDetailContent(image: GrayImage, font: BdfFont, notification: Androi
|
|||||||
|
|
||||||
function drawDetailMenu(image: GrayImage, font: BdfFont, menu: DetailMenuItem[], selectedIndex: number): void {
|
function drawDetailMenu(image: GrayImage, font: BdfFont, menu: DetailMenuItem[], selectedIndex: number): void {
|
||||||
const menuX = 404;
|
const menuX = 404;
|
||||||
const menuY = 40;
|
const menuY = 24;
|
||||||
const menuWidth = 148;
|
const menuWidth = 148;
|
||||||
image.drawText(font, menuX, 24, "Menu", 170);
|
|
||||||
for (let index = 0; index < menu.length; index++) {
|
for (let index = 0; index < menu.length; index++) {
|
||||||
const y = menuY + index * 22;
|
const y = menuY + index * 22;
|
||||||
const selected = index === selectedIndex;
|
const selected = index === selectedIndex;
|
||||||
@@ -276,7 +276,6 @@ function drawDetailMenu(image: GrayImage, font: BdfFont, menu: DetailMenuItem[],
|
|||||||
const label = truncateToWidth(font, menu[index]!.label, menuWidth - 12);
|
const label = truncateToWidth(font, menu[index]!.label, menuWidth - 12);
|
||||||
image.drawText(font, menuX, y + 2, label, selected ? 255 : 185);
|
image.drawText(font, menuX, y + 2, label, selected ? 255 : 185);
|
||||||
}
|
}
|
||||||
image.drawText(font, 404, 258, "tap: select", 110);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildDetailMenu(notification: AndroidNotification): DetailMenuItem[] {
|
function buildDetailMenu(notification: AndroidNotification): DetailMenuItem[] {
|
||||||
|
|||||||
Generated
+17
-17
@@ -11,6 +11,8 @@
|
|||||||
"@nativescript/core": "~9.0.0",
|
"@nativescript/core": "~9.0.0",
|
||||||
"@nativescript/theme": "^3.1.0",
|
"@nativescript/theme": "^3.1.0",
|
||||||
"lodash": "^4.18.1",
|
"lodash": "^4.18.1",
|
||||||
|
"lz4js": "^0.2.0",
|
||||||
|
"pako": "^2.1.0",
|
||||||
"upng-js": "^2.1.0"
|
"upng-js": "^2.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -51,7 +53,6 @@
|
|||||||
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.29.0",
|
"@babel/code-frame": "^7.29.0",
|
||||||
"@babel/generator": "^7.29.0",
|
"@babel/generator": "^7.29.0",
|
||||||
@@ -365,7 +366,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
},
|
},
|
||||||
@@ -388,7 +388,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -1308,7 +1307,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz",
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz",
|
||||||
"integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
|
"integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"acorn": "bin/acorn"
|
"acorn": "bin/acorn"
|
||||||
},
|
},
|
||||||
@@ -1427,7 +1425,6 @@
|
|||||||
"integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==",
|
"integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"fast-uri": "^3.0.1",
|
"fast-uri": "^3.0.1",
|
||||||
@@ -1640,7 +1637,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"baseline-browser-mapping": "^2.10.12",
|
"baseline-browser-mapping": "^2.10.12",
|
||||||
"caniuse-lite": "^1.0.30001782",
|
"caniuse-lite": "^1.0.30001782",
|
||||||
@@ -2421,7 +2417,6 @@
|
|||||||
"integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==",
|
"integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.1",
|
"fast-deep-equal": "^3.1.1",
|
||||||
"fast-json-stable-stringify": "^2.0.0",
|
"fast-json-stable-stringify": "^2.0.0",
|
||||||
@@ -3000,6 +2995,12 @@
|
|||||||
"yallist": "^3.0.2"
|
"yallist": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/lz4js": {
|
||||||
|
"version": "0.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lz4js/-/lz4js-0.2.0.tgz",
|
||||||
|
"integrity": "sha512-gY2Ia9Lm7Ep8qMiuGRhvUq0Q7qUereeldZPP1PMEJxPtEWHJLqw9pgX68oHajBH0nzJK4MaZEA/YNV3jT8u8Bg==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/magic-string": {
|
"node_modules/magic-string": {
|
||||||
"version": "0.30.21",
|
"version": "0.30.21",
|
||||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
||||||
@@ -3223,9 +3224,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/pako": {
|
"node_modules/pako": {
|
||||||
"version": "1.0.11",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz",
|
||||||
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==",
|
"integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==",
|
||||||
"license": "(MIT AND Zlib)"
|
"license": "(MIT AND Zlib)"
|
||||||
},
|
},
|
||||||
"node_modules/parent-module": {
|
"node_modules/parent-module": {
|
||||||
@@ -3440,7 +3441,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^3.3.11",
|
"nanoid": "^3.3.11",
|
||||||
"picocolors": "^1.1.1",
|
"picocolors": "^1.1.1",
|
||||||
@@ -3658,7 +3658,6 @@
|
|||||||
"integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==",
|
"integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.1",
|
"fast-deep-equal": "^3.1.1",
|
||||||
"fast-json-stable-stringify": "^2.0.0",
|
"fast-json-stable-stringify": "^2.0.0",
|
||||||
@@ -3727,7 +3726,6 @@
|
|||||||
"integrity": "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw==",
|
"integrity": "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
@@ -3871,7 +3869,6 @@
|
|||||||
"integrity": "sha512-kgW13M54DUB7IsIRM5LvJkNlpH+WhMpooUcaWGFARkF1Tc82v9mIWkCbCYf+MBvpIUBSeSOTilpZjEPr2VYE6Q==",
|
"integrity": "sha512-kgW13M54DUB7IsIRM5LvJkNlpH+WhMpooUcaWGFARkF1Tc82v9mIWkCbCYf+MBvpIUBSeSOTilpZjEPr2VYE6Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chokidar": "^4.0.0",
|
"chokidar": "^4.0.0",
|
||||||
"immutable": "^5.1.5",
|
"immutable": "^5.1.5",
|
||||||
@@ -4289,7 +4286,6 @@
|
|||||||
"integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==",
|
"integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
@@ -4363,7 +4359,6 @@
|
|||||||
"integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==",
|
"integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
@@ -4429,6 +4424,12 @@
|
|||||||
"pako": "^1.0.5"
|
"pako": "^1.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/upng-js/node_modules/pako": {
|
||||||
|
"version": "1.0.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
|
||||||
|
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==",
|
||||||
|
"license": "(MIT AND Zlib)"
|
||||||
|
},
|
||||||
"node_modules/uri-js": {
|
"node_modules/uri-js": {
|
||||||
"version": "4.4.1",
|
"version": "4.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
|
||||||
@@ -4489,7 +4490,6 @@
|
|||||||
"integrity": "sha512-wGN3qcrBQIFmQ/c0AiOAQBvrZ5lmY8vbbMv4Mxfgzqd/B6+9pXtLo73WuS1dSGXM5QYY3hZnIbvx+K1xxe6FyA==",
|
"integrity": "sha512-wGN3qcrBQIFmQ/c0AiOAQBvrZ5lmY8vbbMv4Mxfgzqd/B6+9pXtLo73WuS1dSGXM5QYY3hZnIbvx+K1xxe6FyA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/eslint-scope": "^3.7.7",
|
"@types/eslint-scope": "^3.7.7",
|
||||||
"@types/estree": "^1.0.8",
|
"@types/estree": "^1.0.8",
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
"@nativescript/core": "~9.0.0",
|
"@nativescript/core": "~9.0.0",
|
||||||
"@nativescript/theme": "^3.1.0",
|
"@nativescript/theme": "^3.1.0",
|
||||||
"lodash": "^4.18.1",
|
"lodash": "^4.18.1",
|
||||||
|
"lz4js": "^0.2.0",
|
||||||
|
"pako": "^2.1.0",
|
||||||
"upng-js": "^2.1.0"
|
"upng-js": "^2.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
Reference in new issue
Block a user