Skip to content

Commit

Permalink
Fix blank window on load on desktop version #348
Browse files Browse the repository at this point in the history
This commit updates the application startup behavior to prevent showing
a blank window until it's fully loaded on all platforms. This enhancement
improves the user experience by ensuring the UI only becomes visible
when it is ready to interact with.

This fix contributes to a smoother user experience by aligning the
window display timing with content readiness, thus avoiding the brief
display of an empty screen.

Changes:

- Set window to initially hide until fully loaded using the
  `ready-to-show` event.
- Parametrize the behavior of opening developer tools for easier
  configuration during testing.
  • Loading branch information
undergroundwires committed May 3, 2024
1 parent 66a5688 commit 5a1f84f
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/presentation/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from './ElectronConfig';
import { registerAllIpcChannels } from './IpcRegistration';

const hideWindowUntilLoaded = true;
const openDevToolsOnDevelopment = true;
const isDevelopment = !app.isPackaged;

// Keep a global reference of the window object, if you don't, the window will
Expand Down Expand Up @@ -48,12 +50,14 @@ function createWindow() {
preload: PRELOADER_SCRIPT_PATH,
},
icon: APP_ICON_PATH,
show: !hideWindowUntilLoaded,
});

if (hideWindowUntilLoaded) {
showOnceLoaded(win);
}
win.setMenuBarVisibility(false);
configureExternalsUrlsOpenBrowser(win);
loadApplication(win);

win.on('closed', () => {
win = null;
});
Expand Down Expand Up @@ -101,9 +105,8 @@ function loadApplication(window: BrowserWindow) {
} else {
loadUrlWithNodeWorkaround(window, RENDERER_HTML_PATH);
}
if (isDevelopment) {
window.webContents.openDevTools();
} else {
openDevTools(window);
if (!isDevelopment) {
const updater = setupAutoUpdater();
updater.checkForUpdates();
}
Expand Down Expand Up @@ -165,3 +168,19 @@ function configureAppQuitBehavior() {
});
}
}

function showOnceLoaded(window: BrowserWindow) {
window.once('ready-to-show', () => {
window.show();
});
}

function openDevTools(window: BrowserWindow) {
if (!isDevelopment) {
return;
}
if (!openDevToolsOnDevelopment) {
return;
}
window.webContents.openDevTools();
}

0 comments on commit 5a1f84f

Please sign in to comment.