forked from Blendman974/faceclaw
Refactor
This commit is contained in:
1 parent
5da3b48c7d
commit
958861c24b
5 files changed
+318
-321
No files matched your search
@@ -330,7 +330,7 @@ function maskToken(token: string): string {
|
||||
|
||||
type SettingsMenuOptions<T> = {
|
||||
style?: "cycle"|"submenu"
|
||||
onChange?: (newValue: T, oldValue: T) => void
|
||||
onChange?: (ctx: LayerContext, newValue: T, oldValue: T) => void
|
||||
}
|
||||
|
||||
export function enumSettingMenuItem<TValue extends string, TId extends string = string>(
|
||||
@@ -345,13 +345,13 @@ export function enumSettingMenuItem<TValue extends string, TId extends string =
|
||||
const oldValue = setting.get();
|
||||
const newValue = setting.next(oldValue);
|
||||
setting.set(newValue);
|
||||
opts?.onChange?.(newValue, oldValue);
|
||||
opts?.onChange?.(ctx, newValue, oldValue);
|
||||
} else {
|
||||
const submenu = new MenuLayer(setting.label, setting.values.map((value) => ({
|
||||
label: value,
|
||||
onSelect: () => {
|
||||
setting.set(value);
|
||||
opts?.onChange?.(value, setting.get());
|
||||
opts?.onChange?.(ctx, value, setting.get());
|
||||
ctx.stack.pop();
|
||||
},
|
||||
render: ({ image, x, y }) => {
|
||||
@@ -374,9 +374,9 @@ export function toggleSettingMenuItem<TId extends string = string>(
|
||||
): MenuItem {
|
||||
return {
|
||||
label: setting.label,
|
||||
onSelect: () => {
|
||||
onSelect: (ctx) => {
|
||||
setting.set(!setting.get());
|
||||
opts?.onChange?.(setting.get(), !setting.get());
|
||||
opts?.onChange?.(ctx, setting.get(), !setting.get());
|
||||
},
|
||||
render: ({ image, x, y, width, selected }) => {
|
||||
drawToggleMenuItem(image, getDefaultSmallFont(), x, y, width, setting.label, setting.get(), selected);
|
||||
|
||||
+7
-316
@@ -4,40 +4,13 @@ import { type RawInputEvent } from "../native/faceclaw-communicator";
|
||||
import { mediaControllerBridge } from "../native/media-controller";
|
||||
import { nightscoutBridge } from "../native/nightscout-bridge";
|
||||
import { EventSourceType, OsEventTypeList } from "../g2/events";
|
||||
import { getDashboardPlugin, isBlankDashboardPlugin, type DashboardPluginCardBounds, type DashboardPluginState } from "./dashboard-plugins";
|
||||
import {
|
||||
estimateCompressionRatiosSetting,
|
||||
isNightscoutSettingsConfigured,
|
||||
nightscoutApiTokenSetting,
|
||||
nightscoutSiteUrlSetting,
|
||||
screenTimeoutSettingToMs,
|
||||
screenTimeoutSetting,
|
||||
systemCardNameSetting,
|
||||
voiceControlEnabledSetting,
|
||||
wakeModeSetting,
|
||||
type DashboardSlotId,
|
||||
DashboardPluginId,
|
||||
bottomRightSlotSetting,
|
||||
bottomLeftSlotSetting,
|
||||
dashboardSlotSettings,
|
||||
dashboardSlotIds,
|
||||
enumSettingMenuItem,
|
||||
toggleSettingMenuItem,
|
||||
showFaceclawLogoSetting,
|
||||
showBatteryIndicatorsSetting,
|
||||
showAndroidNotificationsSetting,
|
||||
showSignalStrengthSetting,
|
||||
textSettingMenuItem,
|
||||
} from "./dashboard-settings";
|
||||
import { getDashboardPlugin, type DashboardPluginCardBounds, type DashboardPluginState } from "./dashboard-plugins";
|
||||
import { isNightscoutSettingsConfigured, screenTimeoutSettingToMs, screenTimeoutSetting, wakeModeSetting, type DashboardSlotId, DashboardPluginId, bottomRightSlotSetting, bottomLeftSlotSetting, dashboardSlotIds } from "./dashboard-settings";
|
||||
import { Layer, LayerActions, LayerStack, type DashboardInputEvent, type LayerContext } from "./layers";
|
||||
import { MenuLayer } from "./menu";
|
||||
import { StopwatchLayer } from "./apps/stopwatch";
|
||||
import { NotificationsListLayer, SingleNotificationLayer } from "./notifications";
|
||||
import { TranscribeLayer } from "./apps/transcribe";
|
||||
import { SingleNotificationLayer } from "./notifications";
|
||||
import { TelepromptLayer } from "./apps/teleprompt";
|
||||
import { ScreenTestLayer } from "./apps/screen-test";
|
||||
import { getDashboardLogo } from "~/graphics/logo";
|
||||
import { drawSystemCard } from "./dashboard/system-card";
|
||||
import { createRootMenuLayer } from "./dashboard/root-menu";
|
||||
|
||||
type DashboardCardId = "system" | DashboardSlotId;
|
||||
export type DashboardBatteryLevels = {
|
||||
@@ -79,7 +52,7 @@ const dashboardActions: LayerActions = {
|
||||
stopDedicatedVoiceInput: () => {},
|
||||
};
|
||||
const dashboardFont = getDefaultSmallFont();
|
||||
const TOP_LEFT_MENU_LAYOUT = { x: 8, y: 8, width: 272, height: 128 };
|
||||
export const TOP_LEFT_MENU_LAYOUT = { x: 8, y: 8, width: 272, height: 128 };
|
||||
|
||||
function rawInputEventToInputEvent(event: RawInputEvent): DashboardInputEvent {
|
||||
if (event.kind === "sys-event") {
|
||||
@@ -227,7 +200,7 @@ export function setDashboardBatteryLevels(levels: Partial<DashboardBatteryLevels
|
||||
};
|
||||
}
|
||||
|
||||
function getPluginIdForSlot(slot: DashboardSlotId): DashboardPluginId {
|
||||
export function getPluginIdForSlot(slot: DashboardSlotId): DashboardPluginId {
|
||||
switch (slot) {
|
||||
case "bottom-left":
|
||||
return bottomLeftSlotSetting.get();
|
||||
@@ -275,285 +248,7 @@ class DashboardLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
class RootMenuLayer extends MenuLayer {
|
||||
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
|
||||
if (event.type === "double-click") {
|
||||
dashboardState.screenOn = false;
|
||||
ctx.stack.clearToBase();
|
||||
void ctx.actions.endTextSettingEdit();
|
||||
return;
|
||||
}
|
||||
await super.handleInput(event, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
function createRootMenuLayer(): MenuLayer {
|
||||
return new RootMenuLayer(
|
||||
null,
|
||||
[
|
||||
{
|
||||
label: "Apps",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createAppsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Notifications",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new NotificationsListLayer((ctx) => {
|
||||
ctx.stack.clearToBase();
|
||||
ctx.stack.push(createRootMenuLayer());
|
||||
}));
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Settings",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
...dashboardSlotIds
|
||||
.filter((slot) => !isBlankDashboardPlugin(getPluginIdForSlot(slot)))
|
||||
.map((slot) => ({
|
||||
label: pluginLabelForSlot(slot),
|
||||
onSelect: (ctx: LayerContext) => {
|
||||
openDashboardSlot(slot, ctx);
|
||||
},
|
||||
render: ({ image, x, y }: { image: GrayImage; x: number; y: number }) => {
|
||||
image.drawText(dashboardFont, x, y + 3, pluginLabelForSlot(slot), 200);
|
||||
},
|
||||
})),
|
||||
{
|
||||
label: "System",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createSystemMenuLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createAppsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Apps",
|
||||
[
|
||||
{
|
||||
label: "Teleprompt",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new TelepromptLayer(dashboardState.telepromptDocumentText));
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Stopwatch",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new StopwatchLayer());
|
||||
void ctx.actions.setStopwatchRenderActive(true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Transcribe",
|
||||
onSelect: (ctx) => {
|
||||
const layer = new TranscribeLayer();
|
||||
ctx.stack.push(layer);
|
||||
layer.start(ctx);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Screen test",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new ScreenTestLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createSystemMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"System",
|
||||
[
|
||||
{
|
||||
label: "About",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new AboutLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Quit / Disconnect",
|
||||
onSelect: async (ctx) => {
|
||||
ctx.stack.clearToBase();
|
||||
await ctx.actions.disconnect();
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function openDashboardSlot(slot: DashboardSlotId, ctx: LayerContext): void {
|
||||
const pluginId = getPluginIdForSlot(slot);
|
||||
if (isBlankDashboardPlugin(pluginId)) {
|
||||
return;
|
||||
}
|
||||
if (pluginId === "nightscout" && !isNightscoutSettingsConfigured()) {
|
||||
ctx.stack.push(createNightscoutSettingsMenuLayer());
|
||||
return;
|
||||
}
|
||||
const layer = getDashboardPlugin(pluginId).createFullscreenLayer?.(getPluginState);
|
||||
if (layer) {
|
||||
ctx.stack.push(layer);
|
||||
}
|
||||
}
|
||||
|
||||
function createSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings",
|
||||
[
|
||||
{
|
||||
label: "Display",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createDisplaySettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Dashboard",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createDashboardSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Voice",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createVoiceSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Integrations",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createIntegrationsMenuLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createDisplaySettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Display",
|
||||
[
|
||||
enumSettingMenuItem(screenTimeoutSetting, {
|
||||
onChange: (newValue, oldValue) => {
|
||||
dashboardState.lastInputAtMs = Date.now();
|
||||
},
|
||||
}),
|
||||
enumSettingMenuItem(wakeModeSetting),
|
||||
toggleSettingMenuItem(estimateCompressionRatiosSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createVoiceSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Voice",
|
||||
[
|
||||
toggleSettingMenuItem(voiceControlEnabledSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createDashboardSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Dashboard",
|
||||
[
|
||||
{
|
||||
label: "System Card",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createSystemCardSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
...dashboardSlotIds.map((slot) => enumSettingMenuItem(dashboardSlotSettings[slot], {
|
||||
style: "submenu",
|
||||
})),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createSystemCardSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Dashboard > System Card",
|
||||
[
|
||||
textSettingMenuItem(systemCardNameSetting),
|
||||
toggleSettingMenuItem(showFaceclawLogoSetting),
|
||||
toggleSettingMenuItem(showBatteryIndicatorsSetting),
|
||||
toggleSettingMenuItem(showAndroidNotificationsSetting),
|
||||
toggleSettingMenuItem(showSignalStrengthSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createIntegrationsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Integrations",
|
||||
[
|
||||
{
|
||||
label: "Nightscout",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createNightscoutSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createNightscoutSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Integrations > Nightscout",
|
||||
[
|
||||
textSettingMenuItem(nightscoutSiteUrlSetting),
|
||||
textSettingMenuItem(nightscoutApiTokenSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
class AboutLayer implements Layer {
|
||||
paint(): GrayImage {
|
||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const logo = getDashboardLogo();
|
||||
image.drawText(dashboardFont, 22, 16, "About Faceclaw", 220);
|
||||
if (logo) {
|
||||
image.bitBlt(logo, 22, 42);
|
||||
}
|
||||
image.drawText(dashboardFont, 108, 48, "Faceclaw", 220);
|
||||
image.drawText(dashboardFont, 108, 64, "Dashboard prototype", 180);
|
||||
|
||||
image.drawTextWrapped({
|
||||
font: dashboardFont,
|
||||
x: 22, y: 128,
|
||||
width: G2_LENS_WIDTH - 44,
|
||||
text: "By James Babcock. Distributed under the GNU General Public License, version 3. Version 0.1.0. Too much of an early janky development prototype to have proper numbered releases.",
|
||||
value: 180
|
||||
});
|
||||
return image;
|
||||
}
|
||||
|
||||
handleInput(event: DashboardInputEvent, ctx: { stack: LayerStack }): void {
|
||||
if (event.type === "double-click") {
|
||||
ctx.stack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPluginState(): DashboardPluginState {
|
||||
export function getPluginState(): DashboardPluginState {
|
||||
return {
|
||||
logLines: dashboardState.logLines,
|
||||
media: mediaControllerBridge.snapshot(),
|
||||
@@ -588,10 +283,6 @@ function getCardBounds(card: DashboardCardId): DashboardPluginCardBounds {
|
||||
}
|
||||
}
|
||||
|
||||
function pluginLabelForSlot(slot: DashboardSlotId): string {
|
||||
return getDashboardPlugin(getPluginIdForSlot(slot)).label;
|
||||
}
|
||||
|
||||
const dashboardLayers = new LayerStack(new DashboardLayer(), dashboardActions);
|
||||
dashboardLayers.push(createRootMenuLayer());
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { getDefaultSmallFont } from "~/graphics/bdffont";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "~/graphics/image";
|
||||
import { getDashboardLogo } from "~/graphics/logo";
|
||||
import { DashboardInputEvent, Layer, LayerStack } from "../layers";
|
||||
|
||||
export class AboutPage implements Layer {
|
||||
paint(): GrayImage {
|
||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const logo = getDashboardLogo();
|
||||
const dashboardFont = getDefaultSmallFont();
|
||||
image.drawText(dashboardFont, 22, 16, "About Faceclaw", 220);
|
||||
if (logo) {
|
||||
image.bitBlt(logo, 22, 42);
|
||||
}
|
||||
image.drawText(dashboardFont, 108, 48, "Faceclaw", 220);
|
||||
image.drawText(dashboardFont, 108, 64, "Dashboard prototype", 180);
|
||||
|
||||
image.drawTextWrapped({
|
||||
font: dashboardFont,
|
||||
x: 22, y: 128,
|
||||
width: G2_LENS_WIDTH - 44,
|
||||
text: "By James Babcock. Distributed under the GNU General Public License, version 3. Version 0.1.0. Too much of an early janky development prototype to have proper numbered releases.",
|
||||
value: 180
|
||||
});
|
||||
return image;
|
||||
}
|
||||
|
||||
handleInput(event: DashboardInputEvent, ctx: { stack: LayerStack }): void {
|
||||
if (event.type === "double-click") {
|
||||
ctx.stack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import { getDefaultSmallFont } from "~/graphics/bdffont";
|
||||
import { dashboardState, getPluginIdForSlot, getPluginState, TOP_LEFT_MENU_LAYOUT } from "../dashboard";
|
||||
import { getDashboardPlugin, isBlankDashboardPlugin } from "../dashboard-plugins";
|
||||
import { DashboardSlotId, dashboardSlotIds, isNightscoutSettingsConfigured } from "../dashboard-settings";
|
||||
import { DashboardInputEvent, LayerContext } from "../layers";
|
||||
import { MenuLayer } from "../menu";
|
||||
import { NotificationsListLayer } from "../notifications";
|
||||
import { createNightscoutSettingsMenuLayer, createSettingsMenuLayer } from "./settings-menus";
|
||||
import { TelepromptLayer } from "../apps/teleprompt";
|
||||
import { StopwatchLayer } from "../apps/stopwatch";
|
||||
import { TranscribeLayer } from "../apps/transcribe";
|
||||
import { ScreenTestLayer } from "../apps/screen-test";
|
||||
import { AboutPage } from "./about-page";
|
||||
import { GrayImage } from "~/graphics/image";
|
||||
|
||||
const rootMenuFont = getDefaultSmallFont();
|
||||
|
||||
class RootMenuLayer extends MenuLayer {
|
||||
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
|
||||
if (event.type === "double-click") {
|
||||
dashboardState.screenOn = false;
|
||||
ctx.stack.clearToBase();
|
||||
void ctx.actions.endTextSettingEdit();
|
||||
return;
|
||||
}
|
||||
await super.handleInput(event, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
export function createRootMenuLayer(): MenuLayer {
|
||||
return new RootMenuLayer(
|
||||
null,
|
||||
[
|
||||
{
|
||||
label: "Apps",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createAppsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Notifications",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new NotificationsListLayer((ctx) => {
|
||||
ctx.stack.clearToBase();
|
||||
ctx.stack.push(createRootMenuLayer());
|
||||
}));
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Settings",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
...dashboardSlotIds
|
||||
.filter((slot) => !isBlankDashboardPlugin(getPluginIdForSlot(slot)))
|
||||
.map((slot) => ({
|
||||
label: pluginLabelForSlot(slot),
|
||||
onSelect: (ctx: LayerContext) => {
|
||||
openDashboardSlot(slot, ctx);
|
||||
},
|
||||
render: ({ image, x, y }: { image: GrayImage; x: number; y: number }) => {
|
||||
image.drawText(rootMenuFont, x, y + 3, pluginLabelForSlot(slot), 200);
|
||||
},
|
||||
})),
|
||||
{
|
||||
label: "System",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createSystemMenuLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createAppsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Apps",
|
||||
[
|
||||
{
|
||||
label: "Teleprompt",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new TelepromptLayer(dashboardState.telepromptDocumentText));
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Stopwatch",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new StopwatchLayer());
|
||||
void ctx.actions.setStopwatchRenderActive(true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Transcribe",
|
||||
onSelect: (ctx) => {
|
||||
const layer = new TranscribeLayer();
|
||||
ctx.stack.push(layer);
|
||||
layer.start(ctx);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Screen test",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new ScreenTestLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createSystemMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"System",
|
||||
[
|
||||
{
|
||||
label: "About",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new AboutPage());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Quit / Disconnect",
|
||||
onSelect: async (ctx) => {
|
||||
ctx.stack.clearToBase();
|
||||
await ctx.actions.disconnect();
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function openDashboardSlot(slot: DashboardSlotId, ctx: LayerContext): void {
|
||||
const pluginId = getPluginIdForSlot(slot);
|
||||
if (isBlankDashboardPlugin(pluginId)) {
|
||||
return;
|
||||
}
|
||||
if (pluginId === "nightscout" && !isNightscoutSettingsConfigured()) {
|
||||
ctx.stack.push(createNightscoutSettingsMenuLayer());
|
||||
return;
|
||||
}
|
||||
const layer = getDashboardPlugin(pluginId).createFullscreenLayer?.(getPluginState);
|
||||
if (layer) {
|
||||
ctx.stack.push(layer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function pluginLabelForSlot(slot: DashboardSlotId): string {
|
||||
return getDashboardPlugin(getPluginIdForSlot(slot)).label;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import { dashboardState, TOP_LEFT_MENU_LAYOUT } from "../dashboard";
|
||||
import { dashboardSlotIds, enumSettingMenuItem, estimateCompressionRatiosSetting, showSignalStrengthSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, systemCardNameSetting, textSettingMenuItem, toggleSettingMenuItem, voiceControlEnabledSetting, wakeModeSetting, dashboardSlotSettings, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
|
||||
import { MenuLayer } from "../menu";
|
||||
|
||||
export function createSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings",
|
||||
[
|
||||
{
|
||||
label: "Display",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createDisplaySettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Dashboard",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createDashboardSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Voice",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createVoiceSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Integrations",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createIntegrationsMenuLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createDisplaySettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Display",
|
||||
[
|
||||
enumSettingMenuItem(screenTimeoutSetting, {
|
||||
onChange: (ctx, newValue, oldValue) => {
|
||||
dashboardState.lastInputAtMs = Date.now();
|
||||
},
|
||||
}),
|
||||
enumSettingMenuItem(wakeModeSetting),
|
||||
toggleSettingMenuItem(estimateCompressionRatiosSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createVoiceSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Voice",
|
||||
[
|
||||
toggleSettingMenuItem(voiceControlEnabledSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createDashboardSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Dashboard",
|
||||
[
|
||||
{
|
||||
label: "System Card",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createSystemCardSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
...dashboardSlotIds.map((slot) => enumSettingMenuItem(dashboardSlotSettings[slot], {
|
||||
style: "submenu",
|
||||
})),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createSystemCardSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Dashboard > System Card",
|
||||
[
|
||||
textSettingMenuItem(systemCardNameSetting),
|
||||
toggleSettingMenuItem(showFaceclawLogoSetting),
|
||||
toggleSettingMenuItem(showBatteryIndicatorsSetting),
|
||||
toggleSettingMenuItem(showAndroidNotificationsSetting),
|
||||
toggleSettingMenuItem(showSignalStrengthSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
function createIntegrationsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Integrations",
|
||||
[
|
||||
{
|
||||
label: "Nightscout",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(createNightscoutSettingsMenuLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
|
||||
export function createNightscoutSettingsMenuLayer(): MenuLayer {
|
||||
return new MenuLayer(
|
||||
"Settings > Integrations > Nightscout",
|
||||
[
|
||||
textSettingMenuItem(nightscoutSiteUrlSetting),
|
||||
textSettingMenuItem(nightscoutApiTokenSetting),
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user