Skip to content

Commit fffc54b

Browse files
committed
Fix flash of white background and scrollbar on startup
- Add backgroundColor to BrowserWindow based on theme setting to prevent white flash before page loads in dark mode - Inject scrollbar-hiding CSS via webFrame in preload script to prevent white scrollbar flash during startup and Cmd+R refresh - Remove old JavaScript workaround that excluded macOS
1 parent 8b6be82 commit fffc54b

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

source/browser.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import process from 'node:process';
2+
import {webFrame} from 'electron';
23
import {ipcRenderer as ipc} from 'electron-better-ipc';
34
import {is} from 'electron-util';
45
import elementReady from 'element-ready';
@@ -10,6 +11,9 @@ import {IToggleSounds, IToggleMuteNotifications} from './types';
1011

1112
type ThemeSource = typeof nativeTheme.themeSource;
1213

14+
// Inject scrollbar-hiding CSS immediately in preload to prevent white flash
15+
webFrame.insertCSS('html::-webkit-scrollbar { display: none !important; }');
16+
1317
async function withMenu(
1418
menuButtonElement: HTMLElement,
1519
callback: () => Promise<void> | void,
@@ -851,12 +855,6 @@ document.addEventListener('DOMContentLoaded', async () => {
851855
await updateDoNotDisturb();
852856
}
853857

854-
// Prevent flash of white on startup when in dark mode
855-
// TODO: find a CSS-only solution
856-
if (!is.macos && nativeTheme.shouldUseDarkColors) {
857-
document.documentElement.style.backgroundColor = '#1e1e1e';
858-
}
859-
860858
// Disable autoplay if set in settings
861859
toggleVideoAutoplay();
862860

source/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ function createMainWindow(): BrowserWindow {
284284
? 'https://work.facebook.com/chat'
285285
: 'https://www.facebook.com/messages/';
286286

287+
// Determine background color based on theme to prevent flash of white
288+
const theme = config.get('theme');
289+
const shouldUseDarkColors = theme === 'dark' || (theme === 'system' && nativeTheme.shouldUseDarkColors);
290+
const backgroundColor = shouldUseDarkColors ? '#1e1e1e' : undefined;
291+
287292
const win = new BrowserWindow({
288293
title: app.name,
289294
show: false,
@@ -301,6 +306,7 @@ function createMainWindow(): BrowserWindow {
301306
y: 16,
302307
},
303308
autoHideMenuBar: config.get('autoHideMenuBar'),
309+
backgroundColor,
304310
webPreferences: {
305311
preload: path.join(__dirname, 'browser.js'),
306312
contextIsolation: true,

0 commit comments

Comments
 (0)