()
| 83 | // --------------------------------------------------------------------------- |
| 84 | |
| 85 | function SettingsPage() { |
| 86 | const bridge = readBridge(); |
| 87 | const [connection, setConnection] = useState<DesktopServerConnection | null>(null); |
| 88 | const [settings, setSettings] = useState<DesktopServerSettings | null>(null); |
| 89 | const [draft, setDraft] = useState<DesktopServerSettings | null>(null); |
| 90 | const [authToken, setAuthToken] = useState<string | null>(null); |
| 91 | const [status, setStatus] = useState<"idle" | "saving" | "restarting" | "error">("idle"); |
| 92 | const [error, setError] = useState<string | null>(null); |
| 93 | |
| 94 | useEffect(() => { |
| 95 | if (!bridge) return; |
| 96 | void Promise.all([ |
| 97 | bridge.getSettings(), |
| 98 | bridge.getServerConnection(), |
| 99 | bridge.getServerAuthToken?.() ?? Promise.resolve(null), |
| 100 | ]).then(([nextSettings, nextConnection, nextToken]) => { |
| 101 | setSettings(nextSettings); |
| 102 | setDraft(nextSettings); |
| 103 | setConnection(nextConnection); |
| 104 | setAuthToken(nextToken); |
| 105 | }); |
| 106 | }, [bridge]); |
| 107 | |
| 108 | const restartAndRefreshConnection = useCallback(async () => { |
| 109 | if (!bridge) return; |
| 110 | setStatus("restarting"); |
| 111 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: renderer ↔ Electron IPC, errors surface in the form |
| 112 | try { |
| 113 | setConnection(await bridge.restartServer()); |
| 114 | } catch (err) { |
| 115 | setError(describeIpcError(err)); |
| 116 | setStatus("error"); |
| 117 | return; |
| 118 | } |
| 119 | setStatus("idle"); |
| 120 | }, [bridge]); |
| 121 | |
| 122 | const apply = useCallback( |
| 123 | async (patch: Partial<DesktopServerSettings>) => { |
| 124 | if (!bridge) return; |
| 125 | setStatus("saving"); |
| 126 | setError(null); |
| 127 | let next: DesktopServerSettings; |
| 128 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: renderer ↔ Electron IPC, errors surface in the form |
| 129 | try { |
| 130 | next = await bridge.updateSettings(patch); |
| 131 | } catch (err) { |
| 132 | setError(describeIpcError(err)); |
| 133 | setStatus("error"); |
| 134 | return; |
| 135 | } |
| 136 | setSettings(next); |
| 137 | setDraft(next); |
| 138 | await restartAndRefreshConnection(); |
| 139 | }, |
| 140 | [bridge, restartAndRefreshConnection], |
| 141 | ); |
| 142 |
nothing calls this directly
no test coverage detected