diff --git a/src/App.tsx b/src/App.tsx index f850267..0f3367a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import { AppProvider } from './context/AppContext' import { createActionRegistry } from './actions/createActionRegistry' import { autoConnectServers } from './utils/autoConnect' import { copyToClipboard } from './utils/clipboard' +import { shouldOpenInitialConnectModal } from './utils/initialSetup' const registry = createActionRegistry() @@ -29,8 +30,14 @@ export function App() { migratePasswords() loadPersistedUIState() initializeIRC() - // --setup: open the connect modal so the user can fill in server details - if (globalThis.__SETUP_MODE__) { + // Fresh installs land in an empty shell otherwise, so reuse the setup modal + // when there are no configured servers after loading persisted state. + if ( + shouldOpenInitialConnectModal({ + setupMode: globalThis.__SETUP_MODE__, + configuredServerCount: useStore.getState().servers.length, + }) + ) { setTimeout(() => useStore.getState().openModal('connect'), 50) } }, [initializeIRC, loadPersistedServers, loadPersistedUIState, migratePasswords]) diff --git a/src/utils/initialSetup.ts b/src/utils/initialSetup.ts new file mode 100644 index 0000000..ed5e186 --- /dev/null +++ b/src/utils/initialSetup.ts @@ -0,0 +1,11 @@ +export interface InitialSetupOptions { + setupMode: boolean | undefined + configuredServerCount: number +} + +export function shouldOpenInitialConnectModal({ + setupMode, + configuredServerCount, +}: InitialSetupOptions): boolean { + return Boolean(setupMode) || configuredServerCount === 0 +} \ No newline at end of file diff --git a/tests/unit/utils/initialSetup.test.ts b/tests/unit/utils/initialSetup.test.ts new file mode 100644 index 0000000..5027418 --- /dev/null +++ b/tests/unit/utils/initialSetup.test.ts @@ -0,0 +1,28 @@ +import { describe, expect, it } from 'vitest' +import { shouldOpenInitialConnectModal } from '@/utils/initialSetup' + +describe('shouldOpenInitialConnectModal', () => { + it('treats undefined setup mode as false when servers already exist', () => { + expect(shouldOpenInitialConnectModal({ setupMode: undefined, configuredServerCount: 2 })).toBe( + false + ) + }) + + it('opens in explicit setup mode', () => { + expect(shouldOpenInitialConnectModal({ setupMode: true, configuredServerCount: 3 })).toBe( + true + ) + }) + + it('opens on a fresh install with no configured servers', () => { + expect(shouldOpenInitialConnectModal({ setupMode: false, configuredServerCount: 0 })).toBe( + true + ) + }) + + it('does not open when servers already exist and setup mode is off', () => { + expect(shouldOpenInitialConnectModal({ setupMode: false, configuredServerCount: 1 })).toBe( + false + ) + }) +}) \ No newline at end of file