From 37877bd7fb50c9d83080f02146b0ef11ba297372 Mon Sep 17 00:00:00 2001 From: Oj Date: Fri, 21 Jan 2022 12:39:00 +0000 Subject: [PATCH 1/4] [Utils > Backoff] Fix syntax error --- src/utils/Backoff.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/Backoff.js b/src/utils/Backoff.js index 20adc96..460f244 100644 --- a/src/utils/Backoff.js +++ b/src/utils/Backoff.js @@ -34,7 +34,7 @@ module.exports = class Backoff { // Internal library / utility for a class to re try { callback(); // Run callback } finally { - this_timeoutId = null; // Stop tracking timeout internally as it's been executed + this._timeoutId = null; // Stop tracking timeout internally as it's been executed } }, this.current); From 107e710c91a3a73e67d83ce3b2e7b5f6fa204c1f Mon Sep 17 00:00:00 2001 From: Oj Date: Fri, 21 Jan 2022 12:47:23 +0000 Subject: [PATCH 2/4] [Bootstrap] Tweak source to not duplicate argv handling code --- src/bootstrap.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bootstrap.js b/src/bootstrap.js index 84dcd90..2842b41 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -128,7 +128,6 @@ const startUpdate = () => { }); }; -const hasArgvFlag = (flag) => (process.argv || []).slice(1).includes(flag); module.exports = () => { // Paths logging @@ -140,7 +139,7 @@ getModuleDataPath: ${paths.getModuleDataPath()} getInstallPath: ${paths.getInstallPath()}`); const instanceLock = app.requestSingleInstanceLock(); - const allowMultiInstance = hasArgvFlag('--multi-instance') || oaConfig.multiInstance === true; // argv flag or config + const allowMultiInstance = argv.hasFlag('--multi-instance') || oaConfig.multiInstance === true; // argv flag or config console.log(instanceLock, allowMultiInstance); @@ -154,4 +153,4 @@ getInstallPath: ${paths.getInstallPath()}`); } else { app.once('ready', startUpdate); } -}; +}; \ No newline at end of file From 48de8a1da6ac9bb32241aa52a4cc5244d8801a35 Mon Sep 17 00:00:00 2001 From: Oj Date: Fri, 21 Jan 2022 12:56:47 +0000 Subject: [PATCH 3/4] [SecurityUtils] Rewrite ssoe to simpler one-liner --- src/utils/securityUtils.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/utils/securityUtils.js b/src/utils/securityUtils.js index a27dbc6..5649fe2 100644 --- a/src/utils/securityUtils.js +++ b/src/utils/securityUtils.js @@ -1,17 +1,7 @@ const { shell } = require('electron'); -const allowedProtocols = [ 'https:', 'http:' ]; -exports.saferShellOpenExternal = (url) => { - let parsed; - - try { - parsed = new URL(url); - } catch (_e) { return Promise.reject(); } - - if (!allowedProtocols.includes(parsed.protocol?.toLowerCase())) return Promise.reject(); // Only allow some protocols - - return shell.openExternal(url); -}; +const allowedProtocols = [ 'https', 'http' ]; // Only allow some protocols +exports.saferShellOpenExternal = (url) => allowedProtocols.includes(url.split(':')[0].toLowerCase()) ? shell.openExternal(url) : Promise.reject(); exports.checkUrlOriginMatches = (url1, url2) => { let parse1, parse2; From 62c01b6fc0b0b6636f7f58cfe69bcdca632a14e0 Mon Sep 17 00:00:00 2001 From: Oj Date: Fri, 21 Jan 2022 13:23:39 +0000 Subject: [PATCH 4/4] [Splash] Rewrites for splashText and themesync injection to be main-side --- src/splash/index.html | 8 -------- src/splash/preload.js | 9 --------- src/splash/splashScreen.js | 17 ++++++++++------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/splash/index.html b/src/splash/index.html index afef31b..33d70a8 100644 --- a/src/splash/index.html +++ b/src/splash/index.html @@ -141,12 +141,4 @@ barFill.style.visibility = ''; } }); - - document.querySelector('#debug').textContent = DiscordSplash.getDebugInfo(); - - DiscordSplash.getCSS((css) => { - const cssInject = document.createElement('style'); - cssInject.appendChild(document.createTextNode(css)); - document.body.appendChild(cssInject); - }); \ No newline at end of file diff --git a/src/splash/preload.js b/src/splash/preload.js index 3b1952c..eb4dbe8 100644 --- a/src/splash/preload.js +++ b/src/splash/preload.js @@ -17,15 +17,6 @@ contextBridge.exposeInMainWorld('DiscordSplash', { openUrl: saferShellOpenExternal, quitDiscord: () => ipcRenderer.send('DISCORD_SPLASH_SCREEN_QUIT'), - getDebugInfo: () => { - if (oaConfig.splashText === false) return ''; - - const buildInfo = require('../utils/buildInfo'); - - return `${buildInfo.releaseChannel} ${buildInfo.version} - OpenAsar ${urlParams.get('oaVersion')}`; - }, - getCSS: callback => oaConfig.themeSync !== false ? ipcRenderer.on('DISCORD_GET_CSS', (_, value) => { callback(value); }) : {} diff --git a/src/splash/splashScreen.js b/src/splash/splashScreen.js index 090473f..d67bd5f 100644 --- a/src/splash/splashScreen.js +++ b/src/splash/splashScreen.js @@ -456,6 +456,15 @@ function launchSplashWindow(startMinimized) { _ipcMain.default.on('SPLASH_SCREEN_READY', () => { log('Splash', 'Window declared ready, showing and starting update process'); + if (oaConfig.themeSync !== false) try { // Inject themesync CSS + splashWindow.webContents.insertCSS(JSON.parse(_fs.default.readFileSync(_path.default.join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS); + } catch (e) { } + + if (oaConfig.splashText !== false) try { + const buildInfo = require('../utils/buildInfo.js'); + splashWindow.webContents.executeJavaScript(`debug.textContent = '${buildInfo.releaseChannel} ${buildInfo.version}\\nOpenAsar ${oaVersion}'`); + } catch (e) { } + if (splashWindow && !startMinimized) { splashWindow.show(); } @@ -471,13 +480,7 @@ function launchSplashWindow(startMinimized) { pathname: _path.default.join(__dirname, 'index.html') }); - try { - webContentsSend(splashWindow, 'GET_CSS', JSON.parse(_fs.default.readFileSync(_path.default.join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS); - } catch (e) { - log('Splash', 'Failed to inject splash CSS'); - } - - splashWindow.loadURL(splashUrl + '?oaVersion=' + global.oaVersion + '&oaConfig=' + JSON.stringify(oaConfig)); + splashWindow.loadURL(splashUrl); log('Splash', `Loading window (with url ${splashUrl})`); }