From 8a86cf28e1d82d1f3cde80fe90971a6cfc88744b Mon Sep 17 00:00:00 2001 From: James Babcock Date: Sun, 30 Aug 2026 20:38:14 -0700 Subject: [PATCH] Fix issue where you could want up without the official Even font extracted, if you skipped onboarding --- CHANGELOG | 1 + app/g2/dashboard-controller.ts | 29 +++++++++++++++- app/g2/firmware-builder.ts | 5 +++ app/graphics/evenhub-font.ts | 61 +++++++++++++++++++++++++++++---- app/phone-ui/main-page.xml | 4 +++ app/phone-ui/main-view-model.ts | 42 ++++++++++++++++++++++- 6 files changed, 134 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7ed4df0e..65873b75 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ * Preview Only mode works * Voice input uses phone mic in preview mode * Ring input on phone screen is swipe-style rather than separate buttons +* Fix an issue where you could be missing the EvenHub font after skipping onboarding ## 0.6.1 - 2026-08-30 * Settings import/export scripts work on release builds diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index b2ec2257..ab8117b8 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -1,6 +1,6 @@ import { Application, ImageSource } from "@nativescript/core"; import { EvenAIStatus, EvenAIStatusName, EventSourceType, EventSourceTypeName, OsEventTypeList, OsEventTypeName, WatchGestureType, WatchGestureTypeName } from "./events"; -import { loadDeviceAddresses } from "./device-addresses"; +import { isValidMacAddress, loadDeviceAddresses } from "./device-addresses"; import { ensureBlePermissions, ensureVoicePermissions, @@ -16,6 +16,7 @@ import { onAndroidNotificationPosted } from "../native/notification-icons"; import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict"; import { grayImageToPreviewSource } from "../native/gray-image-preview"; import { firmwareIncompatibilityMessage } from "./firmware-compat"; +import { hasExtractedEvenHubFonts } from "./firmware-builder"; import { resumeAutoReconnect, suppressAutoReconnect } from "./reconnect-policy"; import { WearRemote, type WearRemoteInputKind } from "./wear-remote"; @@ -107,6 +108,7 @@ export type DashboardSnapshot = { firmwareWarningVisible: boolean; screenRecordingActive: boolean; batteryOptimizationWarningVisible: boolean; + fontsMissingWarningVisible: boolean; /** * True while the headless preview display is standing in for a glasses * connection (preview-only mode): the mirror is live and interactive, but @@ -207,6 +209,10 @@ class DashboardController { private evenAppConflictMessage = ""; private firmwareWarningMessage = ""; private batteryOptimizationWarningVisible = false; + private fontsMissingWarningVisible = false; + // Sticky positive: the extracted-font file doesn't vanish mid-session, so a + // successful check spares later refreshes the file read and JSON parse. + private extractedFontsConfirmed = false; private screenRecordingActive = false; private displayPreview: ImageSource | null = createInitialDisplayPreview(); private silentMode = false; @@ -905,6 +911,7 @@ class DashboardController { firmwareWarningVisible: this.firmwareWarningMessage.length > 0, screenRecordingActive: this.screenRecordingActive, batteryOptimizationWarningVisible: this.batteryOptimizationWarningVisible, + fontsMissingWarningVisible: this.fontsMissingWarningVisible, previewMode: this.isPreviewDisplayActive(), }; } @@ -977,8 +984,28 @@ class DashboardController { }, 5_000); } + /** + * Warn when glasses are paired but the phone-side G2 fonts were never + * extracted (the onboarding flash flow normally extracts them, but a dev + * install or an imported config can arrive paired without them). Preview-only + * users have no addresses configured and are never warned. + */ + refreshEvenHubFontStatus(): void { + const addresses = loadDeviceAddresses(); + const paired = isValidMacAddress(addresses.right) && isValidMacAddress(addresses.left); + if (paired && !this.extractedFontsConfirmed) { + this.extractedFontsConfirmed = hasExtractedEvenHubFonts(); + } + const warningVisible = paired && !this.extractedFontsConfirmed; + if (warningVisible !== this.fontsMissingWarningVisible) { + this.fontsMissingWarningVisible = warningVisible; + this.emit(); + } + } + refreshEvenAppStatus(): void { this.refreshBatteryOptimizationStatus(); + this.refreshEvenHubFontStatus(); const state = readEvenAppNotificationState(); const wasActive = this.evenNotificationActive; this.evenNotificationActive = state.evenNotificationActive; diff --git a/app/g2/firmware-builder.ts b/app/g2/firmware-builder.ts index 8465e59e..4d2c4f3a 100644 --- a/app/g2/firmware-builder.ts +++ b/app/g2/firmware-builder.ts @@ -20,6 +20,7 @@ import { } from "./firmware-fonts"; import { fetchWithUserAgent } from "../util/http"; import { bytesToHex, hexToBytes as hexToBytesLenient } from "../util/hex-util"; +import { EvenHubFont } from "../graphics/evenhub-font"; declare const com: any; @@ -180,6 +181,10 @@ function persistEvenHubFonts(base: ArrayBuffer): void { }, ); if (writeError) throw writeError; + // A degraded EvenHubFont (built before this extraction existed) is cached + // per JS context; drop it so the next render picks up the real fonts + // without an app restart. + EvenHubFont.invalidate(); } catch (error) { throw new FirmwareBuildError( `The firmware was verified, but its EvenHub fonts could not be extracted: ${(error as Error)?.message ?? error}`, diff --git a/app/graphics/evenhub-font.ts b/app/graphics/evenhub-font.ts index fe2736db..e1a8f55f 100644 --- a/app/graphics/evenhub-font.ts +++ b/app/graphics/evenhub-font.ts @@ -6,7 +6,9 @@ * firmware into app-private storage while Faceclaw prepares custom firmware. * They are not distributed with Faceclaw. * - The final fallback is the G2's serialized Source Han Sans SC Light font, - * which Faceclaw can bundle under the SIL Open Font License. + * which Faceclaw can bundle under the SIL Open Font License. It carries no + * ASCII (it starts at U+00A4), so while the extracted fonts are missing a + * bundled Roboto backstops Latin text (see TTF_FALLBACK_ASSET_PATH). * - Text SIZING / KERNING / WRAPPING: @evenrealities/pretext, whose advance * tables the bitmaps were validated against. Using pretext for measurement * means our line breaks match exactly where EvenHub apps (which measure @@ -22,11 +24,24 @@ import { getTextWidth } from "@evenrealities/pretext"; import { EVENHUB_RUNTIME_FONT_FILENAME, isEvenHubFontAsset } from "../g2/firmware-fonts"; import { toUint8Array } from "../util/array-util"; import { GrayImage, grayToNibble, type FwTextFont, type PlacedFwText, type PlacedFwTextGlyph } from "./image"; +import { TtfFont } from "./ttf-font"; declare const com: any; const CJK_ASSET_PATH = "fonts/source-han-sans/SourceHanSansSC-Light-20.lvgl.bin"; +/** + * Last-resort face used ONLY while the extracted firmware fonts are missing. + * The bundled CJK partition font starts at U+00A4 with no ASCII at all (on + * stock it sits behind the main firmware's Latin fonts), so without this an + * un-extracted install renders Latin text as nothing. Advances still come + * from pretext, so layout and wrapping are unchanged; only the ink is + * Roboto's. Once the real fonts are extracted this path is disabled and + * unknown codepoints go back to stock's silent skip. + */ +const TTF_FALLBACK_ASSET_PATH = "fonts/ttf/Roboto-Regular.ttf"; +const TTF_FALLBACK_SIZE_PX = 20; + /** [boxW, boxH, ofsX, ofsY, bitmapOffset, bitmapLen] */ type GlyphRecord = [number, number, number, number, number, number]; @@ -95,8 +110,12 @@ export class EvenHubFont implements FwTextFont { private readonly cjkPath: string; private readonly cjkBaseline: number; private readonly cjkGlyphs = new Map(); + /** Degraded mode: the extracted asset was missing, so Roboto backstops. */ + private readonly useTtfFallback: boolean; + private ttfFallback: TtfFont | null | undefined; - private constructor(asset: FontAsset) { + private constructor(asset: FontAsset, useTtfFallback = false) { + this.useTtfFallback = useTtfFallback; this.lineHeight = asset.lineHeight; this.baseline = asset.baseline; this.bitmap = base64Decode(asset.bitmapBase64); @@ -124,21 +143,32 @@ export class EvenHubFont implements FwTextFont { if (!isEvenHubFontAsset(parsed)) throw new Error("invalid font asset structure"); asset = parsed; } catch (error) { - console.warn(`Could not load the extracted G2 fonts; using Source Han Sans only: ${error}`); + console.warn(`Could not load the extracted G2 fonts; using fallback faces: ${error}`); } } else { console.warn( - "The G2 fonts have not been extracted yet; using Source Han Sans only. " + - "Reinstall Faceclaw's custom firmware to prepare the exact fallback chain.", + "The G2 fonts have not been extracted yet; using fallback faces. " + + "The home screen's warning flag offers to prepare them.", ); } EvenHubFont.cached = new EvenHubFont( asset ?? { lineHeight: 27, baseline: 22, glyphs: {}, bitmapBase64: "" }, + asset === null, ); } return EvenHubFont.cached; } + /** + * Drop the cached instance so the next get() re-reads the extracted asset. + * Called after a successful firmware-font extraction: without this, a + * degraded instance built before the extraction would keep rendering with + * the fallback faces until the app restarts. + */ + static invalidate(): void { + EvenHubFont.cached = null; + } + hasGlyph(codePoint: number): boolean { return this.glyphs.has(codePoint) || this.getCjkGlyph(codePoint) !== null; } @@ -262,7 +292,11 @@ export class EvenHubFont implements FwTextFont { } else { flushRun(); const cjk = this.getCjkGlyph(cp); - if (cjk) this.drawGlyph(image, cjk.record, cjk.bitmap, penX, y + this.cjkBaseline, value); + if (cjk) { + this.drawGlyph(image, cjk.record, cjk.bitmap, penX, y + this.cjkBaseline, value); + } else if (this.useTtfFallback) { + this.drawTtfFallbackGlyph(image, cp, penX, baselineY, value); + } } penX += this.advanceOf(cp, cps[i + 1] ?? 0); } @@ -336,6 +370,21 @@ export class EvenHubFont implements FwTextFont { return lines.length; } + /** Degraded-mode ink: the codepoint's Roboto glyph, aligned on our baseline. */ + private drawTtfFallbackGlyph(image: GrayImage, cp: number, penX: number, baselineY: number, value: number): void { + if (this.ttfFallback === undefined) { + this.ttfFallback = TtfFont.load( + knownFolders.currentApp().getFile(TTF_FALLBACK_ASSET_PATH).path, + TTF_FALLBACK_SIZE_PX, + ); + } + const font = this.ttfFallback; + const glyph = font?.getGlyph(cp); + if (!font || !glyph || !glyph.coverage || glyph.bbxWidth <= 0) return; + // drawGlyph's y is the TTF line top (baseline at y + ascent). + image.drawGlyph(font, glyph, penX, baselineY - font.ascent, value); + } + private getCjkGlyph(codePoint: number): CjkGlyph | null { const cached = this.cjkGlyphs.get(codePoint); if (cached !== undefined) return cached; diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index 2b31e0a9..7dc9a3d3 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -84,6 +84,10 @@