From 67518d6be968919dd14ce9abf18a8dd61e1714b5 Mon Sep 17 00:00:00 2001 From: Latta Date: Fri, 1 Nov 2024 10:06:24 +0100 Subject: [PATCH] Fix white screen issue on startup --- scripts/patch-desktop-app.mjs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) mode change 100755 => 100644 scripts/patch-desktop-app.mjs diff --git a/scripts/patch-desktop-app.mjs b/scripts/patch-desktop-app.mjs old mode 100755 new mode 100644 index 3588d86..2a61fb5 --- a/scripts/patch-desktop-app.mjs +++ b/scripts/patch-desktop-app.mjs @@ -47,7 +47,7 @@ const patches = { // enable the notion:// protocol, windows-style tab layouts, and // quitting the app when the last window is closed on linux const isWindows = - /(?:"win32"===process\.platform(?:(?=,isFullscreen)|(?=&&\w\.BrowserWindow)|(?=&&\(\w\.app\.requestSingleInstanceLock)))/g, + /(?:"win32"===process\.platform(?:(?=,isFullscreen)|(?=&&\w\.BrowserWindow)|(?=&&\(\w\.app\.requestSingleInstanceLock))))/g, isWindowsOrLinux = '["win32","linux"].includes(process.platform)'; replace(isWindows, isWindowsOrLinux); @@ -63,11 +63,10 @@ const patches = { protocolInterceptor = `{const n="notion://www.notion.so/__notion-enhancer/";if(e.url.startsWith(n))return require("electron").net.fetch(\`file://\${require("path").join(__dirname,"..","..","node_modules","notion-enhancer",e.url.slice(n.length))}\`)}`; prepend(protocolHandler, protocolInterceptor); - // disable csp entirely. risky? yes. necessary? also yes. - // potentially could extend default policy instead someday. + // Modify CSP instead of disabling it entirely const headerHandler = /\.onHeadersReceived\(\(\((\w),\w\)=>{/, - cspDisabler = `{const responseHeaders=$1.responseHeaders;if(responseHeaders){delete responseHeaders["content-security-policy"];return t({responseHeaders})}}` - append(headerHandler, cspDisabler); + cspModifier = `{const responseHeaders=$1.responseHeaders;if(responseHeaders && responseHeaders["content-security-policy"]){responseHeaders["content-security-policy"] = responseHeaders["content-security-policy"][0].replace(/script-src/g, 'script-src notion: file:');return t({responseHeaders})}}` + append(headerHandler, cspModifier); // expose the app's config + cache + preferences to the global namespace // e.g. to enable development mode or check if keep in background is enabled