()
| 72 | let cancelled = false; |
| 73 | |
| 74 | async function init() { |
| 75 | if (!activeWorkspace) { |
| 76 | try { |
| 77 | const defaultRelayUrl = await getDefaultRelayUrl(); |
| 78 | |
| 79 | if (isSharedIdentity) { |
| 80 | const identity = await getIdentity(); |
| 81 | if (cancelled) return; |
| 82 | initFirstWorkspace(defaultRelayUrl, identity.pubkey); |
| 83 | if (!cancelled) { |
| 84 | window.location.reload(); |
| 85 | } |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | if (!cancelled) { |
| 90 | setResult({ |
| 91 | isReady: false, |
| 92 | needsSetup: true, |
| 93 | defaultRelayUrl, |
| 94 | }); |
| 95 | } |
| 96 | } catch { |
| 97 | if (!cancelled) { |
| 98 | setResult({ |
| 99 | isReady: false, |
| 100 | needsSetup: true, |
| 101 | defaultRelayUrl: "ws://localhost:3000", |
| 102 | }); |
| 103 | } |
| 104 | } |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | // Mark this workspace config as pending while it is applied to the |
| 109 | // backend. App.tsx also checks appliedKey against the active workspaceKey, |
| 110 | // which prevents rendering workspace-scoped UI for a new workspace until |
| 111 | // that exact config has finished applying. |
| 112 | setResult({ |
| 113 | isReady: false, |
| 114 | needsSetup: false, |
| 115 | appliedKey: workspaceKey, |
| 116 | }); |
| 117 | |
| 118 | // On workspace switch (not initial mount), reset module singletons |
| 119 | // so the new tree starts with a clean slate. |
| 120 | if (hasInitializedRef.current) { |
| 121 | resetWorkspaceState(); |
| 122 | } |
| 123 | hasInitializedRef.current = true; |
| 124 | |
| 125 | // Apply workspace config to the Tauri backend. |
| 126 | // |
| 127 | // Note: we deliberately do NOT pass an nsec here. The persisted |
| 128 | // `identity.key` file (resolved at startup by `resolve_persisted_identity`, |
| 129 | // and updated atomically by `import_identity`) is the single source of |
| 130 | // truth for the active key. Older builds stored the nsec in localStorage |
| 131 | // and re-applied it on every reload, which silently overwrote any |
no test coverage detected