forked from Blendman974/faceclaw
Calendar app shows day-of-the-month in its icon on the launcher and sidebar
This commit is contained in:
1 parent
061b2eb215
commit
cd25ec60f1
4 files changed
+61
No files matched your search
@@ -4,6 +4,7 @@
|
|||||||
* Settings import/export scripts work on release builds
|
* Settings import/export scripts work on release builds
|
||||||
* Fixed an issue where the onboarding flow failed to detect the existing glasses firmware version
|
* Fixed an issue where the onboarding flow failed to detect the existing glasses firmware version
|
||||||
* Update launcher, files, and game UIs to work better with watch input
|
* Update launcher, files, and game UIs to work better with watch input
|
||||||
|
* Calendar app shows the day-of-the-month in its icon
|
||||||
|
|
||||||
## 0.6 - 2026-08-29
|
## 0.6 - 2026-08-29
|
||||||
- Start keeping a changelog and making signed binaries via GitHub Releases
|
- Start keeping a changelog and making signed binaries via GitHub Releases
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { ensureCalendarPermission, hasCalendarPermission } from "../../g2/android-permissions";
|
import { ensureCalendarPermission, hasCalendarPermission } from "../../g2/android-permissions";
|
||||||
import { invalidateCalendarCache } from "../../native/calendar";
|
import { invalidateCalendarCache } from "../../native/calendar";
|
||||||
|
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||||
import { CalendarLayer } from "./calendar";
|
import { CalendarLayer } from "./calendar";
|
||||||
|
import { renderCalendarDateIcon } from "./calendar-icon";
|
||||||
import {
|
import {
|
||||||
createInProcessWindow,
|
createInProcessWindow,
|
||||||
YieldAtRootLayer,
|
YieldAtRootLayer,
|
||||||
@@ -39,6 +41,7 @@ export function createCalendarAppWindow(options: InProcessAppOptions): InProcess
|
|||||||
title: "Calendar",
|
title: "Calendar",
|
||||||
iconLetter: "Ca",
|
iconLetter: "Ca",
|
||||||
icon: "calendar",
|
icon: "calendar",
|
||||||
|
drawIcon: makeImageWindowIcon(renderCalendarDateIcon, windowIcon("calendar", "Ca")),
|
||||||
closeable: true,
|
closeable: true,
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
|
baseLayer: new YieldAtRootLayer(new CalendarLayer(requestPermission)),
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { type GrayImage } from "../../graphics/image";
|
||||||
|
import { ICON_SVGS, renderSvgIcon } from "../../graphics/icons";
|
||||||
|
import { ensurePreinstalledFonts, installedFontPath } from "../../graphics/installed-fonts";
|
||||||
|
import { TtfFont } from "../../graphics/ttf-font";
|
||||||
|
|
||||||
|
// The calendar icon minus its divider line, freeing the whole box for the
|
||||||
|
// date digits. Derived from the shared SVG so the outline stays in sync.
|
||||||
|
const DIVIDER = '<path d="M3 10h18"/>';
|
||||||
|
const CALENDAR_BLANK_SVG = ICON_SVGS.calendar.replace(DIVIDER, "");
|
||||||
|
|
||||||
|
// One entry per requested size (launcher 44, sidebar 32/28); replaced when the
|
||||||
|
// day rolls over. A fresh image object per (size, day) keeps downstream
|
||||||
|
// per-object caches (texture cache, the sidebar's inverted-icon memo) correct.
|
||||||
|
const cache = new Map<number, { day: number; image: GrayImage }>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Digit font: bundled Roboto scaled to the icon (not the user-selected UI
|
||||||
|
* font, so the digits always fit the icon's box). Loaded once per icon size.
|
||||||
|
*/
|
||||||
|
const digitFonts = new Map<number, TtfFont | null>();
|
||||||
|
function loadDigitFont(size: number): TtfFont | null {
|
||||||
|
let font = digitFonts.get(size);
|
||||||
|
if (font === undefined) {
|
||||||
|
ensurePreinstalledFonts(); // the icon can render before any font picker use
|
||||||
|
font = TtfFont.load(installedFontPath("Roboto-Regular.ttf"), Math.round(size / 2));
|
||||||
|
digitFonts.set(size, font);
|
||||||
|
}
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The calendar icon with today's day-of-month drawn in its body, like a phone
|
||||||
|
* calendar app icon.
|
||||||
|
*/
|
||||||
|
export function renderCalendarDateIcon(size: number): GrayImage | null {
|
||||||
|
const day = new Date().getDate();
|
||||||
|
const cached = cache.get(size);
|
||||||
|
if (cached && cached.day === day) return cached.image;
|
||||||
|
const base = renderSvgIcon("calendar-blank", CALENDAR_BLANK_SVG, size);
|
||||||
|
if (!base) return null;
|
||||||
|
// Without the digits the divider-less icon reads as broken; a null return
|
||||||
|
// gets both call sites' stock-calendar fallback instead.
|
||||||
|
const font = loadDigitFont(size);
|
||||||
|
if (!font) return null;
|
||||||
|
const image = base.clone();
|
||||||
|
const text = String(day);
|
||||||
|
// Center in the box interior (viewBox y 5..21 of 24, inside the stroke),
|
||||||
|
// nudged down so the digits sit clear of the top-edge hanging tabs.
|
||||||
|
const x = Math.round((size - font.measureText(text)) / 2);
|
||||||
|
const y = Math.round((size * 13.5) / 24 - font.lineHeight / 2);
|
||||||
|
image.drawText(font, x, y, text, 255);
|
||||||
|
image.bakeDeferredDrawsInPlace();
|
||||||
|
cache.set(size, { day, image });
|
||||||
|
return image;
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { type AppDefinition } from "../app-definition";
|
import { type AppDefinition } from "../app-definition";
|
||||||
import { CALENDAR_SURFACE_ID, CALENDAR_WINDOW_ID, createCalendarAppWindow } from "./calendar-app";
|
import { CALENDAR_SURFACE_ID, CALENDAR_WINDOW_ID, createCalendarAppWindow } from "./calendar-app";
|
||||||
|
import { renderCalendarDateIcon } from "./calendar-icon";
|
||||||
|
|
||||||
const calendarApp: AppDefinition = {
|
const calendarApp: AppDefinition = {
|
||||||
appId: "calendar",
|
appId: "calendar",
|
||||||
title: "Calendar",
|
title: "Calendar",
|
||||||
icon: "calendar",
|
icon: "calendar",
|
||||||
|
renderIcon: renderCalendarDateIcon,
|
||||||
launch: (ctx) => ctx.launchInProcessApp(CALENDAR_WINDOW_ID, CALENDAR_SURFACE_ID, createCalendarAppWindow),
|
launch: (ctx) => ctx.launchInProcessApp(CALENDAR_WINDOW_ID, CALENDAR_SURFACE_ID, createCalendarAppWindow),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user