Files
holesail-browser/native-host/holesail-manager/settings.js
T
Raven Scott 6fcd9fcf2b
CI / Build & Test (push) Successful in 3m19s
eat: implement Holesail-Browser enhancement plan
- Add unit tests (hostname-validator, TLDs, payload-schemas) and integration tests for message handler registry
- Refactor native host message router into handler registry (handlers/state, tunnels, ssh, rdp, backup, ca, connections)
- Add ESLint config and npm test + lint steps in CI
- Dashboard: visibility-based refresh pause, configurable refresh interval (2s/5s/10s/paused)
- Accessibility: ARIA on nav and modals, focus trap and restore, prefers-reduced-motion
- Empty states: primary action buttons for virtual hosts, servers, service tunnels
- Native host rate limiting for backup and CA operations; update SECURITY.md
- CONTRIBUTING: "Adding a new dashboard page", dev workflow; add npm run dev script
2026-03-15 00:24:31 -04:00

63 lines
3.2 KiB
JavaScript

/**
* Settings management — in-memory settings with persistence via saveStateSync.
* Depends on: state.js (SETTINGS_DEFAULTS, saveStateSync via the index snapshot callback)
*/
const { SETTINGS_DEFAULTS } = require('./state.js');
let currentSettings = { ...SETTINGS_DEFAULTS };
let runtimeProxyPort = SETTINGS_DEFAULTS.proxyPort;
let _saveState = null; // injected by index.js
function init(saveStateFn) {
_saveState = saveStateFn;
}
function applyLoaded(loaded) {
currentSettings = { ...SETTINGS_DEFAULTS, ...loaded };
if (currentSettings.proxyPort) runtimeProxyPort = currentSettings.proxyPort;
}
function getSettings() {
return { ...currentSettings };
}
function updateSettings(patch) {
if (!patch || typeof patch !== 'object') return { requiresRestart: false };
let requiresRestart = false;
if (typeof patch.proxyPort === 'number' && patch.proxyPort > 0 && patch.proxyPort < 65536) {
if (patch.proxyPort !== currentSettings.proxyPort) requiresRestart = true;
currentSettings.proxyPort = patch.proxyPort;
runtimeProxyPort = patch.proxyPort;
}
if (typeof patch.connectProxyPort === 'number' && patch.connectProxyPort > 0 && patch.connectProxyPort < 65536) {
if (patch.connectProxyPort !== currentSettings.connectProxyPort) requiresRestart = true;
currentSettings.connectProxyPort = patch.connectProxyPort;
}
if (typeof patch.readyTimeoutMs === 'number') currentSettings.readyTimeoutMs = patch.readyTimeoutMs;
if (typeof patch.notifyOnDisconnect === 'boolean') currentSettings.notifyOnDisconnect = patch.notifyOnDisconnect;
if (typeof patch.notifyOnTunnelError === 'boolean') currentSettings.notifyOnTunnelError = patch.notifyOnTunnelError;
if (typeof patch.debug === 'boolean') currentSettings.debug = patch.debug;
if (typeof patch.disableOnFileUrls === 'boolean') currentSettings.disableOnFileUrls = patch.disableOnFileUrls;
if (typeof patch.backupRetention === 'number') currentSettings.backupRetention = patch.backupRetention;
if (typeof patch.backupIntervalHours === 'number') currentSettings.backupIntervalHours = patch.backupIntervalHours;
if (typeof patch.tunnelAutoReconnect === 'boolean') currentSettings.tunnelAutoReconnect = patch.tunnelAutoReconnect;
if (typeof patch.latencyPingEnabled === 'boolean') currentSettings.latencyPingEnabled = patch.latencyPingEnabled;
if (typeof patch.latencyPingIntervalMs === 'number' && patch.latencyPingIntervalMs > 0) currentSettings.latencyPingIntervalMs = patch.latencyPingIntervalMs;
if (typeof patch.dashboardRefreshIntervalMs === 'number' && patch.dashboardRefreshIntervalMs >= 0 && [0, 2000, 5000, 10000].includes(patch.dashboardRefreshIntervalMs)) {
currentSettings.dashboardRefreshIntervalMs = patch.dashboardRefreshIntervalMs;
}
if (_saveState) _saveState();
return { requiresRestart };
}
function getProxyPort() { return runtimeProxyPort; }
function setProxyPort(port) {
if (typeof port === 'number' && port > 0 && port < 65536) runtimeProxyPort = port;
}
function getReadyTimeoutMs() { return currentSettings.readyTimeoutMs; }
function getTunnelAutoReconnect() { return !!currentSettings.tunnelAutoReconnect; }
module.exports = { init, applyLoaded, getSettings, updateSettings, getProxyPort, setProxyPort, getReadyTimeoutMs, getTunnelAutoReconnect };