diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts index c975b79..19da3f6 100644 --- a/apps/desktop/src/main/index.ts +++ b/apps/desktop/src/main/index.ts @@ -40,14 +40,18 @@ const canOpenExternally = (url: string): boolean => { } } -const createWindow = async () => { - if (mainWindow && !mainWindow.isDestroyed()) { - mainWindow.focus() +const loadSplash = async (windowRef: BrowserWindow) => { + if (process.env.ELECTRON_RENDERER_URL) { + await windowRef.loadURL(process.env.ELECTRON_RENDERER_URL) return } - const targetUrl = await sidecar.resolveUrl() - if (isQuitting) { + await windowRef.loadFile(join(__dirname, '../renderer/index.html')) +} + +const createWindow = async () => { + if (mainWindow && !mainWindow.isDestroyed()) { + mainWindow.focus() return } @@ -82,7 +86,7 @@ const createWindow = async () => { }) try { - await windowRef.loadURL(targetUrl) + await loadSplash(windowRef) } catch (error) { if (mainWindow === windowRef) { mainWindow = null @@ -98,6 +102,25 @@ const createWindow = async () => { if (!windowRef.isDestroyed()) { windowRef.show() } + + const targetUrl = await sidecar.resolveUrl() + if (isQuitting || windowRef.isDestroyed()) { + return + } + + try { + await windowRef.loadURL(targetUrl) + } catch (error) { + if (mainWindow === windowRef) { + mainWindow = null + } + + if (!windowRef.isDestroyed()) { + windowRef.destroy() + } + + throw error + } } const ensureWindow = async () => {