-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ensure settings are initialized + app splash screen (#309)
* Rename EmptyView to WelcomeView * Add splashscreen and load settings and project structure before app renders Note that the webkit white background is a pending tauri issue: tauri-apps/tauri#1564 * Fix imports * Add splash.tsx to the entry list of knip * Fix PR comments and move AppStartup to own file * Add unit tests * Make transparent splashscreen * Revert "Make transparent splashscreen" This reverts commit 0b267ce.
- Loading branch information
Showing
15 changed files
with
223 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/splash.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { invoke } from '@tauri-apps/api'; | ||
import { useState } from 'react'; | ||
|
||
import { App } from './application/App'; | ||
import { useAsyncEffect } from './hooks/useAsyncEffect'; | ||
import { ensureProjectFileStructure } from './io/filesystem'; | ||
import { noop } from './lib/noop'; | ||
import { notifyInfo } from './notifications/notifications'; | ||
import { interceptConsoleMessages } from './notifications/notifications.console'; | ||
import { initSettings } from './settings/settingsManager'; | ||
|
||
// Note: Intercepting INFO, WARN and ERROR console.* | ||
interceptConsoleMessages(true, true, true); | ||
|
||
export function AppStartup() { | ||
const [initialized, setInitialized] = useState(false); | ||
|
||
useAsyncEffect( | ||
async (isMounted) => { | ||
if (initialized) { | ||
return; | ||
} | ||
|
||
notifyInfo('Application Startup'); | ||
await initSettings(); | ||
await ensureProjectFileStructure(); | ||
await invoke('close_splashscreen'); | ||
|
||
notifyInfo('Application Initialized'); | ||
|
||
if (isMounted()) { | ||
setInitialized(true); | ||
} | ||
}, | ||
noop, | ||
[initialized], | ||
); | ||
|
||
if (!initialized) { | ||
return null; | ||
} | ||
|
||
return <App />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { clearMocks, mockIPC } from '@tauri-apps/api/mocks'; | ||
|
||
import { App } from '../application/App'; | ||
import { AppStartup } from '../AppStartup'; | ||
import { render, waitFor } from '../test/test-utils'; | ||
|
||
vi.mock('../events'); | ||
vi.mock('../io/filesystem'); | ||
vi.mock('../settings/settingsManager'); | ||
vi.mock('../application/App', () => { | ||
const FakeApp = vi.fn(() => <div>App</div>); | ||
return { | ||
App: FakeApp, | ||
}; | ||
}); | ||
|
||
describe('AppStartup', () => { | ||
beforeEach(() => { | ||
clearMocks(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should render null while initializing', () => { | ||
const { container } = render(<AppStartup />); | ||
expect(vi.mocked(App)).not.toHaveBeenCalled(); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render <App /> while initializing', async () => { | ||
mockIPC((cmd) => { | ||
switch (cmd) { | ||
case 'close_splashscreen': | ||
return; | ||
default: | ||
break; | ||
} | ||
}); | ||
|
||
render(<AppStartup />); | ||
|
||
await waitFor(() => { | ||
expect(vi.mocked(App)).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { cx } from '../../lib/cx'; | ||
|
||
export function WelcomeView({ hideShortcuts, className }: { hideShortcuts?: boolean; className?: string }) { | ||
return ( | ||
<div | ||
className={cx( | ||
'pointer-events-none select-none', | ||
'flex w-full flex-col items-center justify-center gap-2', | ||
'bg-slate-300', | ||
className, | ||
)} | ||
> | ||
<div className="relative border border-slate-500 text-[160px] font-extrabold leading-none"> | ||
<WelcomeViewLetter className="bg-slate-500/50 text-slate-200/50" letter="R" /> | ||
<WelcomeViewLetter className="bg-slate-200/50 text-slate-500/50" letter="S" /> | ||
</div> | ||
|
||
{!hideShortcuts && ( | ||
<div className="mt-10 space-y-4"> | ||
<WelcomeViewShortcut keys={['⌘', 'K']} text="Show Commands" /> | ||
<WelcomeViewShortcut keys={['⌘', 'R']} text="Show References" /> | ||
<WelcomeViewShortcut keys={['⌘', 'N']} text="New File" /> | ||
<WelcomeViewShortcut keys={['⌘', ',']} text="Show Settings" /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
function WelcomeViewShortcut({ text, keys }: { text: string; keys: string[] }) { | ||
return ( | ||
<div className="flex items-center gap-2"> | ||
<div className="min-w-[135px] px-1 text-right text-slate-500">{text}</div> | ||
<div className="flex gap-1"> | ||
{keys.map((key) => ( | ||
<kbd className="rounded-sm bg-slate-500 px-2 py-0.5 font-mono text-slate-200" key={key}> | ||
{key} | ||
</kbd> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function WelcomeViewLetter({ letter, className = '' }: { letter: string; className?: string }) { | ||
return ( | ||
<div className={cx('inline-flex items-center justify-center px-4 text-center', className)}> | ||
<span>{letter}</span> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { render, screen } from '../../../test/test-utils'; | ||
import { WelcomeView } from '../WelcomeView'; | ||
|
||
describe('WelcomeView', () => { | ||
it('should render with shortcuts', () => { | ||
render(<WelcomeView />); | ||
expect(screen.getByText('Show Commands')).toBeInTheDocument(); | ||
expect(screen.getByText('Show References')).toBeInTheDocument(); | ||
expect(screen.getByText('New File')).toBeInTheDocument(); | ||
expect(screen.getByText('Show Settings')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render without shortcuts', () => { | ||
render(<WelcomeView hideShortcuts />); | ||
expect(screen.getByText('R')).toBeInTheDocument(); | ||
expect(screen.getByText('S')).toBeInTheDocument(); | ||
expect(screen.queryByText('Show Commands')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('Show References')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('New File')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('Show Settings')).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import './index.css'; | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
|
||
import { WelcomeView } from './application/views/WelcomeView'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<WelcomeView className="h-screen bg-white" hideShortcuts /> | ||
</React.StrictMode>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters