forked from Blendman974/faceclaw
Merge optional R1 health export
This commit is contained in:
10 files changed
+348
-1
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { readHealthExportSecret, writeHealthExportSecret } from "../native/health-export-secret";
|
||||
import { normalizeNightscoutThreshold, type NightscoutThresholds } from "../apps/nightscout/nightscout-alerts";
|
||||
import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures";
|
||||
import { DEFAULT_BRIGHTNESS_CURVE, normalizeBrightnessCurve, brightnessCurveError } from "../g2/brightness-curve";
|
||||
@@ -301,6 +302,39 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
|
||||
}
|
||||
|
||||
|
||||
/** A changed credential starts a new delivery history without retaining the old secret. */
|
||||
class HealthExportKeySetting extends ConfigSettingString {
|
||||
get(): string { return readHealthExportSecret(); }
|
||||
set(value: string): string {
|
||||
const normalized = value.trim();
|
||||
if (normalized !== this.get()) {
|
||||
writeHealthExportSecret(normalized);
|
||||
setStringSetting("health.export.cursor", "");
|
||||
setStringSetting("health.export.generation", String(Number(getStringSetting("health.export.generation", "0")) + 1));
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
getValidValue(): string { return this.get(); }
|
||||
}
|
||||
|
||||
export const healthExportEnabledSetting = new ConfigSettingBoolean({
|
||||
id: "healthExportEnabled", label: "Export health data", storageKey: "health.export.enabled",
|
||||
defaultValue: false, reportInAnalytics: false,
|
||||
description: "Send saved R1 health history to your server over HTTPS. Retries while Faceclaw is running; phone storage is retained.",
|
||||
});
|
||||
export const healthExportUrlSetting = new ConfigSettingString({
|
||||
id: "healthExportUrl", label: "Endpoint URL", storageKey: "health.export.url", defaultValue: "",
|
||||
normalize: value => (value ?? "").trim(),
|
||||
validate: value => !value || /^https:\/\/[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::\d{1,5})?(?:\/[^\s?#]*)?$/i.test(value)
|
||||
? null : "Use an HTTPS URL without credentials, query or fragment",
|
||||
description: "Full ingestion URL, for example https://health.undefined-dev.fr/v1/health",
|
||||
});
|
||||
export const healthExportKeySetting = new HealthExportKeySetting({
|
||||
id: "healthExportKey", label: "API key", storageKey: "health.export.key", defaultValue: "",
|
||||
inputKind: "password", formatValue: value => value ? "Configured" : "(empty)",
|
||||
description: "Device-specific write-only key, stored using Android Keystore.",
|
||||
});
|
||||
|
||||
export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMode>({
|
||||
id: "batteryDisplayMode",
|
||||
label: "Style",
|
||||
@@ -1778,7 +1812,7 @@ export class EditTextSettingLayer implements Layer {
|
||||
for (let index = 0; index < message.length; index++) {
|
||||
image.drawText(font, 22, messageTop + index * step, message[index]!, 200);
|
||||
}
|
||||
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.get(), 52), 220);
|
||||
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.inputKind === "password" ? this.setting.displayValue() : this.setting.get(), 52), 220);
|
||||
const error = this.setting.validationError();
|
||||
if (error) wrapText(font, error, width - 48).forEach((line, index) =>
|
||||
image.drawText(font, 22, messageTop + (message.length + 4 + index) * step, line, 180));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { healthExportStatus, syncHealthExport } from "../../health/health-export";
|
||||
import { remoteInputMenuItem } from "./remote-input-menu";
|
||||
import { knownFolders } from "@nativescript/core";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
@@ -28,6 +29,9 @@ import type { LayerContext } from "../layers";
|
||||
import { drawRightValueMenuItem, openModalMenu, submenuItem, type MenuItem } from "../menu";
|
||||
import { shell } from "../shell/shell";
|
||||
import {
|
||||
healthExportEnabledSetting,
|
||||
healthExportUrlSetting,
|
||||
healthExportKeySetting,
|
||||
anthropicApiKeySetting,
|
||||
appSwitcherPositionSetting,
|
||||
statusBarPositionSetting,
|
||||
@@ -195,6 +199,16 @@ function settingsSections(): SettingsSection[] {
|
||||
];
|
||||
},
|
||||
},
|
||||
...(!global.isIOS ? [{
|
||||
label: "Health export",
|
||||
get items() { return [
|
||||
toggleSettingMenuItem(healthExportEnabledSetting),
|
||||
textSettingMenuItem(healthExportUrlSetting),
|
||||
textSettingMenuItem(healthExportKeySetting),
|
||||
{ label: "Sync now", description: healthExportStatus(), onSelect: () => { void syncHealthExport(); } },
|
||||
{ label: healthExportStatus(), disabled: true, onSelect: () => {} },
|
||||
]; },
|
||||
}] : []),
|
||||
{
|
||||
label: "API Keys",
|
||||
items: [
|
||||
|
||||
Reference in new issue
Block a user