mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 23:50:45 +00:00
Defers Electron window display until the renderer signals first meaningful paint, avoiding initial blank screens or white flashes, especially on startup and settings windows. Implements a handshake using a renderer-to-main process message, color-matches background to the current theme, and falls back to a timeout in development. Also migrates font loading to npm packages, replaces Google Fonts usage, and adds code-splitting for dialogs and quick switcher to improve performance. Restricts console debug output to development.
51 lines
1.3 KiB
TypeScript
Executable File
51 lines
1.3 KiB
TypeScript
Executable File
import { Suspense, lazy } from 'react';
|
|
import ReactDOM from 'react-dom/client';
|
|
import '@fontsource/space-grotesk/400.css';
|
|
import '@fontsource/space-grotesk/500.css';
|
|
import '@fontsource/space-grotesk/600.css';
|
|
import '@fontsource/space-grotesk/700.css';
|
|
import '@fontsource/jetbrains-mono/400.css';
|
|
import '@fontsource/jetbrains-mono/500.css';
|
|
import '@fontsource/jetbrains-mono/600.css';
|
|
import App from './App';
|
|
import { ToastProvider } from './components/ui/toast';
|
|
|
|
const LazySettingsPage = lazy(() => import('./components/SettingsPage'));
|
|
|
|
const rootElement = document.getElementById('root');
|
|
if (!rootElement) {
|
|
throw new Error("Could not find root element to mount to");
|
|
}
|
|
|
|
// Simple hash-based routing for separate windows
|
|
const getRoute = () => {
|
|
const hash = window.location.hash;
|
|
if (hash === '#/settings' || hash.startsWith('#/settings')) {
|
|
return 'settings';
|
|
}
|
|
return 'main';
|
|
};
|
|
|
|
const root = ReactDOM.createRoot(rootElement);
|
|
|
|
const renderApp = () => {
|
|
const route = getRoute();
|
|
if (route === 'settings') {
|
|
root.render(
|
|
<ToastProvider>
|
|
<Suspense fallback={null}>
|
|
<LazySettingsPage />
|
|
</Suspense>
|
|
</ToastProvider>
|
|
);
|
|
} else {
|
|
root.render(<App />);
|
|
}
|
|
};
|
|
|
|
// Initial render
|
|
renderApp();
|
|
|
|
// Listen for hash changes
|
|
window.addEventListener('hashchange', renderApp);
|