From 323a1f7649aeffaabfa335d205eda841bc8ec1a1 Mon Sep 17 00:00:00 2001 From: Szymon Kaliski Date: Tue, 15 Aug 2023 11:45:46 +0200 Subject: [PATCH 1/3] minimize white flashes --- src/createWindow.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/createWindow.ts b/src/createWindow.ts index 384fd87..d540d4b 100644 --- a/src/createWindow.ts +++ b/src/createWindow.ts @@ -108,14 +108,20 @@ export function createWindow(props?: WindowProps): BrowserWindow { minHeight: 420, backgroundColor, autoHideMenuBar: true, // Window & Linux only, hides the menubar unless `Alt` is held + show: false, // We're starting with the window hidden, as we are still setting it up using imperative methods below ...platformStyling, }); // Add a custom string to user agent to make it easier to differentiate requests from desktop app window.webContents.setUserAgent( - `${window.webContents.getUserAgent()} ReplitDesktop` + `${window.webContents.getUserAgent()} ReplitDesktop`, ); + // Bypass the browser's cache when initially loading the remote URL + // in order to ensure that we load the latest web build. + // See: https://github.com/electron/electron/issues/1360#issuecomment-156506130 + window.loadURL(url, { extraHeaders: "pragma: no-cache\n" }); + // Prevent any URLs opened via a target="_blank" anchor tag or programmatically using `window.open` from // opening in an Electron window and open in the user's external browser instead. window.webContents.setWindowOpenHandler((details) => { @@ -156,7 +162,7 @@ export function createWindow(props?: WindowProps): BrowserWindow { window.on("close", async () => { // We're capturing the background color to use as main browser window background color. const backgroundColor = await window.webContents.executeJavaScript( - `getComputedStyle(document.body).getPropertyValue('--background-root');` + `getComputedStyle(document.body).getPropertyValue('--background-root');`, ); store.setLastSeenBackgroundColor(backgroundColor); store.setWindowBounds(window.getBounds()); @@ -175,10 +181,8 @@ export function createWindow(props?: WindowProps): BrowserWindow { window.webContents.send(events.ON_LEAVE_FULLSCREEN); }); - // Bypass the browser's cache when initially loading the remote URL - // in order to ensure that we load the latest web build. - // See: https://github.com/electron/electron/issues/1360#issuecomment-156506130 - window.loadURL(url, { extraHeaders: "pragma: no-cache\n" }); + // We've set up the window, so let's show it! + window.show(); return window; } From 7a8fc4060d9e0e9be00b9e0fe396d03e21d0f608 Mon Sep 17 00:00:00 2001 From: Szymon Kaliski Date: Tue, 15 Aug 2023 14:26:36 +0200 Subject: [PATCH 2/3] `loadURL` after we set the event listeners on `window` --- src/createWindow.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/createWindow.ts b/src/createWindow.ts index d540d4b..bb1a56a 100644 --- a/src/createWindow.ts +++ b/src/createWindow.ts @@ -117,11 +117,6 @@ export function createWindow(props?: WindowProps): BrowserWindow { `${window.webContents.getUserAgent()} ReplitDesktop`, ); - // Bypass the browser's cache when initially loading the remote URL - // in order to ensure that we load the latest web build. - // See: https://github.com/electron/electron/issues/1360#issuecomment-156506130 - window.loadURL(url, { extraHeaders: "pragma: no-cache\n" }); - // Prevent any URLs opened via a target="_blank" anchor tag or programmatically using `window.open` from // opening in an Electron window and open in the user's external browser instead. window.webContents.setWindowOpenHandler((details) => { @@ -149,7 +144,7 @@ export function createWindow(props?: WindowProps): BrowserWindow { }); // If the previous bounds are no longer in-bounds with the current set of - // displays, then bail and fallback to the defaul behavior to prevent the app + // displays, then bail and fallback to the default behavior to prevent the app // from opening stretched out or sticking outside the screens. const inBounds = isInBounds(store.getWindowBounds()); @@ -180,6 +175,11 @@ export function createWindow(props?: WindowProps): BrowserWindow { window.on("leave-full-screen", () => { window.webContents.send(events.ON_LEAVE_FULLSCREEN); }); + + // Bypass the browser's cache when initially loading the remote URL + // in order to ensure that we load the latest web build. + // See: https://github.com/electron/electron/issues/1360#issuecomment-156506130 + window.loadURL(url, { extraHeaders: "pragma: no-cache\n" }); // We've set up the window, so let's show it! window.show(); From d091c5cc14b208a69b610a284f2be025677f22cf Mon Sep 17 00:00:00 2001 From: Szymon Kaliski Date: Tue, 15 Aug 2023 14:27:06 +0200 Subject: [PATCH 3/3] whitespace --- src/createWindow.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/createWindow.ts b/src/createWindow.ts index bb1a56a..cfa60c1 100644 --- a/src/createWindow.ts +++ b/src/createWindow.ts @@ -175,7 +175,7 @@ export function createWindow(props?: WindowProps): BrowserWindow { window.on("leave-full-screen", () => { window.webContents.send(events.ON_LEAVE_FULLSCREEN); }); - + // Bypass the browser's cache when initially loading the remote URL // in order to ensure that we load the latest web build. // See: https://github.com/electron/electron/issues/1360#issuecomment-156506130