forked from Blendman974/faceclaw
Terminal connection string management, multi-host
This commit is contained in:
1 parent
6f45888627
commit
6df7e9bc81
7 files changed
+825
-225
No files matched your search
@@ -170,6 +170,15 @@ type ConfigSettingStringOptions<TId extends string> = ConfigSettingOptions<strin
|
||||
normalize?: (value: string | null | undefined) => string;
|
||||
};
|
||||
|
||||
// Every string setting by id, so isolates that can only pass an id over a
|
||||
// message channel (e.g. a worker app requesting the phone text editor) can be
|
||||
// resolved back to the setting instance on the main thread.
|
||||
const stringSettingsById = new Map<string, ConfigSettingString>();
|
||||
|
||||
export function getStringSettingById(id: string): ConfigSettingString | null {
|
||||
return stringSettingsById.get(id) ?? null;
|
||||
}
|
||||
|
||||
export class ConfigSettingString<TId extends string = string> extends ConfigSetting<string, TId> {
|
||||
readonly editorTitle: string;
|
||||
readonly glassesEditTitle: string;
|
||||
@@ -180,6 +189,7 @@ export class ConfigSettingString<TId extends string = string> extends ConfigSett
|
||||
this.editorTitle = options.editorTitle ?? options.label;
|
||||
this.glassesEditTitle = options.glassesEditTitle ?? `Edit ${options.label}`;
|
||||
this.normalizer = options.normalize ?? ((value) => value ?? "");
|
||||
stringSettingsById.set(this.id, this);
|
||||
}
|
||||
|
||||
get(): string {
|
||||
@@ -487,34 +497,21 @@ export const mapboxApiKeySetting = new ConfigSettingString({
|
||||
description: "Mapbox public token (pk. prefix), used by the Navigate app for maps, geocoding, and directions.",
|
||||
});
|
||||
|
||||
export const terminalHostSetting = new ConfigSettingString({
|
||||
id: "terminal-host",
|
||||
label: "Host",
|
||||
storageKey: "terminal.host",
|
||||
/**
|
||||
* Staging buffer for the Terminal app's "Add connection" flow: the worker
|
||||
* asks the shell to open the phone text editor on this setting, the user
|
||||
* types the g2mirror:// connection string there, and the worker reads (and
|
||||
* clears) the draft when the user confirms on the glasses. Deliberately not
|
||||
* listed in the Settings app; connections are managed inside the Terminal app.
|
||||
*/
|
||||
export const terminalNewConnectionSetting = new ConfigSettingString({
|
||||
id: "terminal-new-connection",
|
||||
label: "New connection",
|
||||
storageKey: "terminal.newConnectionDraft",
|
||||
defaultValue: "",
|
||||
editorTitle: "g2mirror host (tailscale IP)",
|
||||
glassesEditTitle: "Edit terminal host",
|
||||
description: "Hostname or IP address (e.g. a Tailscale address) of the machine running g2mirror, for the Terminal app.",
|
||||
});
|
||||
|
||||
export const terminalPortSetting = new ConfigSettingString({
|
||||
id: "terminal-port",
|
||||
label: "Port",
|
||||
storageKey: "terminal.port",
|
||||
defaultValue: "8737",
|
||||
editorTitle: "g2mirror port",
|
||||
glassesEditTitle: "Edit terminal port",
|
||||
description: "TCP port the g2mirror server listens on. The default is 8737.",
|
||||
});
|
||||
|
||||
export const terminalAuthTokenSetting = new ConfigSettingString({
|
||||
id: "terminal-auth-token",
|
||||
label: "Auth token",
|
||||
storageKey: "terminal.authToken",
|
||||
defaultValue: "",
|
||||
editorTitle: "g2mirror auth token",
|
||||
glassesEditTitle: "Edit terminal auth token",
|
||||
description: "Shared secret that must match the g2mirror server's configured auth token.",
|
||||
editorTitle: "g2mirror connection string (g2mirror://token@host)",
|
||||
glassesEditTitle: "Add connection",
|
||||
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, "").trim(),
|
||||
});
|
||||
|
||||
export const terminalLaunchPresetsSetting = new ConfigSettingString({
|
||||
|
||||
@@ -37,11 +37,8 @@ import {
|
||||
lockScreenEnabledSetting,
|
||||
saveVoiceRecordingsSetting,
|
||||
suspendEvenHubWhenScreenOffSetting,
|
||||
terminalAuthTokenSetting,
|
||||
terminalAutoReconnectSetting,
|
||||
terminalHostSetting,
|
||||
terminalLaunchPresetsSetting,
|
||||
terminalPortSetting,
|
||||
terminalWakeOnBellSetting,
|
||||
textSettingMenuItem,
|
||||
timeFormatSetting,
|
||||
@@ -119,10 +116,9 @@ function settingsSections(): SettingsSection[] {
|
||||
},
|
||||
{
|
||||
label: "Terminal",
|
||||
// Connections (g2mirror:// strings) are managed inside the Terminal
|
||||
// app's Manage Connections section, not here.
|
||||
items: [
|
||||
textSettingMenuItem(terminalHostSetting),
|
||||
textSettingMenuItem(terminalPortSetting),
|
||||
textSettingMenuItem(terminalAuthTokenSetting),
|
||||
textSettingMenuItem(terminalLaunchPresetsSetting),
|
||||
toggleSettingMenuItem(terminalAutoReconnectSetting),
|
||||
toggleSettingMenuItem(terminalWakeOnBellSetting),
|
||||
|
||||
@@ -67,6 +67,17 @@ export type WorkerAppReply =
|
||||
type: "open-settings";
|
||||
section?: string;
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* Open the phone app's text editor on a string setting (by id, resolved
|
||||
* on the main thread). The worker paints its own "type on the phone"
|
||||
* UI and watches the setting for changes; it must post
|
||||
* end-text-setting-edit when its flow finishes.
|
||||
*/
|
||||
type: "start-text-setting-edit";
|
||||
settingId: string;
|
||||
}
|
||||
| { type: "end-text-setting-edit" }
|
||||
| {
|
||||
/**
|
||||
* Set or clear the app's top-bar tray icon. Pixels ride the JSON
|
||||
@@ -117,6 +128,10 @@ export type WorkerAppHostOptions = {
|
||||
requestShellRender: () => void;
|
||||
/** Open or focus the Settings app, optionally selecting a section. */
|
||||
openSettings: (section?: string) => void;
|
||||
/** Open the phone app's text editor on a string setting (by id). */
|
||||
startTextSettingEdit: (settingId: string) => void;
|
||||
/** Close the phone text editor opened by startTextSettingEdit. */
|
||||
endTextSettingEdit: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -200,6 +215,12 @@ export class WorkerAppHost {
|
||||
case "open-settings":
|
||||
this.options.openSettings(message.section);
|
||||
break;
|
||||
case "start-text-setting-edit":
|
||||
this.options.startTextSettingEdit(message.settingId);
|
||||
break;
|
||||
case "end-text-setting-edit":
|
||||
this.options.endTextSettingEdit();
|
||||
break;
|
||||
case "set-tray-icon": {
|
||||
let icon: GrayImage | null = null;
|
||||
if (message.icon) {
|
||||
|
||||
Reference in new issue
Block a user