forked from Blendman974/faceclaw
Merge branch 'main' into switcher-on-bottom
This commit is contained in:
commit
eab839f811
10 files changed
+310
-40
No files matched your search
@@ -27,7 +27,7 @@ export type NightscoutSettings = {
|
||||
siteUrl: string;
|
||||
apiToken: string;
|
||||
};
|
||||
export type BatteryDisplayMode = "icon" | "percentage" | "stacked" | "stacked-percentage";
|
||||
export type BatteryDisplayMode = "icon" | "percentage" | "stacked" | "stacked-percentage" | "dense";
|
||||
/** When a top-bar battery indicator is shown: always, only below 50%, or never. */
|
||||
export type BatteryIndicatorVisibility = "always" | "low" | "never";
|
||||
export type TimeFormat = "24h" | "12h";
|
||||
@@ -235,9 +235,9 @@ export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMod
|
||||
label: "Style",
|
||||
storageKey: "dashboard.systemCard.batteryDisplayMode",
|
||||
defaultValue: "stacked",
|
||||
values: ["icon", "percentage", "stacked", "stacked-percentage"],
|
||||
values: ["icon", "percentage", "stacked", "stacked-percentage", "dense"],
|
||||
formatValue: batteryDisplayModeLabel,
|
||||
description: "How the top bar shows battery levels: a gauge icon or exact percentage beside the label, or a compact gauge or percentage with the label stacked above it.",
|
||||
description: "How the top bar shows battery levels: a gauge icon or exact percentage beside the label, a compact gauge or percentage with the label stacked above it, or (dense) a device icon beside each gauge with two indicators stacked per column.",
|
||||
});
|
||||
|
||||
/** Below this charge level a "Below 50%" indicator becomes visible. */
|
||||
@@ -1121,6 +1121,7 @@ export function batteryDisplayModeLabel(value: BatteryDisplayMode): string {
|
||||
if (value === "percentage") return "Percentage";
|
||||
if (value === "stacked") return "Stacked";
|
||||
if (value === "stacked-percentage") return "Stacked percentage";
|
||||
if (value === "dense") return "Dense";
|
||||
return "Icon";
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,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 { BATTERY_ICON_WIDTH, DENSE_BATTERY_BLOCK_HEIGHT, drawBattery, drawDenseBatteries, type BatteryDevice } from "../../graphics/battery";
|
||||
import { readActiveNotificationIcons } from "../../native/notification-icons";
|
||||
import { readPhoneBatteryState } from "../../native/phone-battery";
|
||||
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
|
||||
@@ -474,35 +474,40 @@ export class ShellChromeLayer implements Layer {
|
||||
* Labelled battery indicators for the phone, Wear OS watch, G2, and R1,
|
||||
* right-aligned in the top bar. The watch one exists only while a watch
|
||||
* running the Faceclaw watch app is reachable (no placeholder otherwise).
|
||||
* The Settings > Customization > Battery indicators submenu picks the style (label beside a gauge icon or percentage, or stacked above
|
||||
* either) and, per device, whether the indicator shows always, only below
|
||||
* 50%, or never. `barRight` is the bar's right edge (short of a right-hand
|
||||
* sidebar). Returns the left edge of the battery block.
|
||||
* The Settings > Customization > Battery indicators submenu picks the
|
||||
* style (label beside a gauge icon or percentage, stacked above either, or
|
||||
* dense: device icons beside gauges, two per column) and, per device,
|
||||
* whether the indicator shows always, only below 50%, or never. `barRight`
|
||||
* is the bar's right edge (short of a right-hand sidebar). Returns the left
|
||||
* edge of the battery block.
|
||||
*/
|
||||
private drawTopBarBatteries(image: GrayImage, state: ShellChromeState, barTop: number, barRight: number): number {
|
||||
const mode = batteryDisplayModeSetting.get();
|
||||
const items: BatteryItem[] = [];
|
||||
const phone = readPhoneBatteryState();
|
||||
if (phone.battery !== null && Number.isFinite(phone.battery)) {
|
||||
pushBatteryItem(items, phoneBatteryVisibilitySetting.get(), "Phone", phone.battery, Boolean(phone.charging));
|
||||
pushBatteryItem(items, phoneBatteryVisibilitySetting.get(), "Phone", "phone", phone.battery, Boolean(phone.charging));
|
||||
}
|
||||
if (state.battery.watch !== null && Number.isFinite(state.battery.watch)) {
|
||||
pushBatteryItem(items, watchBatteryVisibilitySetting.get(), "Watch", state.battery.watch,
|
||||
pushBatteryItem(items, watchBatteryVisibilitySetting.get(), "Watch", "watch", state.battery.watch,
|
||||
Boolean(state.battery.watchCharging));
|
||||
}
|
||||
if (state.battery.headset !== null && Number.isFinite(state.battery.headset)) {
|
||||
pushBatteryItem(items, glassesBatteryVisibilitySetting.get(), "G2", state.battery.headset,
|
||||
pushBatteryItem(items, glassesBatteryVisibilitySetting.get(), "G2", "glasses", state.battery.headset,
|
||||
Boolean(state.battery.headsetCharging));
|
||||
}
|
||||
if (state.battery.ring !== null && Number.isInteger(state.battery.ring)
|
||||
&& state.battery.ring >= 0 && state.battery.ring <= 100) {
|
||||
pushBatteryItem(items, ringBatteryVisibilitySetting.get(), "R1", state.battery.ring,
|
||||
pushBatteryItem(items, ringBatteryVisibilitySetting.get(), "R1", "ring", state.battery.ring,
|
||||
Boolean(state.battery.ringCharging));
|
||||
}
|
||||
if (!items.length) return barRight;
|
||||
if (mode === "stacked" || mode === "stacked-percentage") {
|
||||
return drawStackedBatteries(image, items, barTop, barRight, mode === "stacked-percentage");
|
||||
}
|
||||
if (mode === "dense") {
|
||||
return drawDenseBatteries(image, items, barRight - BATTERY_BLOCK_RIGHT_MARGIN, barTop + DENSE_TOP);
|
||||
}
|
||||
|
||||
const font = getDefaultSmallFont();
|
||||
const percentageMode = mode === "percentage";
|
||||
@@ -538,7 +543,7 @@ export class ShellChromeLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
type BatteryItem = { label: string; percent: number; charging: boolean };
|
||||
type BatteryItem = { label: string; device: BatteryDevice; percent: number; charging: boolean };
|
||||
|
||||
const BATTERY_BLOCK_RIGHT_MARGIN = 8;
|
||||
const BATTERY_LABEL_VALUE = 150;
|
||||
@@ -548,12 +553,13 @@ function pushBatteryItem(
|
||||
items: BatteryItem[],
|
||||
visibility: BatteryIndicatorVisibility,
|
||||
label: string,
|
||||
device: BatteryDevice,
|
||||
percent: number,
|
||||
charging: boolean,
|
||||
): void {
|
||||
const clamped = Math.max(0, Math.min(100, Math.round(percent)));
|
||||
if (!batteryIndicatorVisible(visibility, clamped)) return;
|
||||
items.push({ label, percent: clamped, charging });
|
||||
items.push({ label, device, percent: clamped, charging });
|
||||
}
|
||||
|
||||
// Stacked style geometry, in rows below the bar's top edge. The bar has 27
|
||||
@@ -570,6 +576,10 @@ const STACKED_ICON_TOP = 13;
|
||||
const STACKED_PERCENT_BASELINE = 21;
|
||||
const STACKED_ITEM_GAP = 10;
|
||||
|
||||
// Dense style: two 10px indicator rows with a 2px gap span rows 2..23, the
|
||||
// same vertical center as the stacked styles' ink.
|
||||
const DENSE_TOP = (((TOP_BAR_HEIGHT - 1 - DENSE_BATTERY_BLOCK_HEIGHT) / 2) | 0);
|
||||
|
||||
/**
|
||||
* Stacked styles: each label centered above its gauge icon (or percentage
|
||||
* text), right-aligned in the bar (ending at barRight). Returns the left edge
|
||||
|
||||
Reference in new issue
Block a user