Files
holesail-browser/native-host/host/handlers/state.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

68 lines
2.7 KiB
JavaScript

/**
* Handlers for getState, getSettings, updateSettings.
* Context: holesailManager, certificateAuthority, httpsProxy, connectProxy, getProxiesReadyPromise, getTunnelsRestoredPromise, scheduleNextAutoBackup, debugLog
*/
function register(deps) {
const { holesailManager, certificateAuthority, httpsProxy, connectProxy, getProxiesReadyPromise, getTunnelsRestoredPromise, scheduleNextAutoBackup, debugLog } = deps;
return [
{
type: 'getState',
handle: async (payload, reply) => {
const proxiesReadyPromise = getProxiesReadyPromise();
const tunnelsRestoredPromise = getTunnelsRestoredPromise();
if (proxiesReadyPromise) await proxiesReadyPromise;
if (tunnelsRestoredPromise) {
let _fallbackTimer;
await Promise.race([
tunnelsRestoredPromise.finally(() => clearTimeout(_fallbackTimer)),
new Promise((r) => { _fallbackTimer = setTimeout(r, 15000); })
]);
}
const servers = holesailManager.getServers();
const virtualHosts = holesailManager.getVirtualHosts();
const serviceTunnels = holesailManager.getServiceTunnels();
const proxyPort = holesailManager.getProxyPort();
const connectProxyPort = connectProxy.getPort();
const settings = holesailManager.getSettings();
const sshConnections = holesailManager.getSshConnections();
const rdpConnections = holesailManager.getRdpConnections();
debugLog('getState: servers=', servers.length, 'virtualHosts=', virtualHosts.length, 'serviceTunnels=', serviceTunnels.length, 'proxyPort=', proxyPort, 'connectProxyPort=', connectProxyPort);
const caInstalled = await new Promise((resolve) => {
certificateAuthority.isRootCAInstalled((installed) => resolve(!!installed));
});
reply({
ok: true,
servers,
virtualHosts,
serviceTunnels,
proxyPort,
connectProxyPort: connectProxyPort ?? null,
caInstalled,
settings,
sshConnections,
rdpConnections,
trafficStats: httpsProxy.getTrafficStats()
});
}
},
{
type: 'getSettings',
handle: async (payload, reply) => {
reply({ ok: true, settings: holesailManager.getSettings() });
}
},
{
type: 'updateSettings',
handle: async (payload, reply) => {
const { requiresRestart } = holesailManager.updateSettings(payload);
debugLog('updateSettings: applied', JSON.stringify(payload), 'requiresRestart=', requiresRestart);
scheduleNextAutoBackup();
reply({ ok: true, settings: holesailManager.getSettings(), requiresRestart });
}
}
];
}
module.exports = { register };