From 8bfca99053bb7c5f9714783fde505a59283f83f0 Mon Sep 17 00:00:00 2001 From: Oj Date: Sun, 17 Apr 2022 22:46:38 +0100 Subject: [PATCH] [Utils > Win] Make standard win constructor --- src/config/index.js | 18 ++++-------------- src/splash/index.js | 33 ++++----------------------------- src/utils/win.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 src/utils/win.js diff --git a/src/config/index.js b/src/config/index.js index 6a1ae52..78c4a14 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,4 +1,4 @@ -const { BrowserWindow, ipcMain, app } = require('electron'); +const { ipcMain, app } = require('electron'); const { join } = require('path'); ipcMain.on('DISCORD_UPDATED_QUOTES', (e, c) => { @@ -6,18 +6,10 @@ ipcMain.on('DISCORD_UPDATED_QUOTES', (e, c) => { }); const open = exports.open = () => { - const win = new BrowserWindow({ + const win = require('../utils/win')({ width: 500, - height: 650, - center: true, - frame: false, - resizable: false, - center: true, - backgroundColor: '#101418', - webPreferences: { - preload: join(__dirname, 'preload.js') - } - }); + height: 650 + }, join(__dirname, 'preload.js'), 'https://cdn.openasar.dev/config'); let config = settings.get('openasar', {}); config.setup = true; @@ -39,6 +31,4 @@ const open = exports.open = () => { app.relaunch(); app.exit(); }); - - win.loadURL('https://cdn.openasar.dev/config'); }; \ No newline at end of file diff --git a/src/splash/index.js b/src/splash/index.js index f51c743..0e0ca35 100644 --- a/src/splash/index.js +++ b/src/splash/index.js @@ -1,8 +1,6 @@ const { join } = require('path'); -const fs = require('fs'); -const { BrowserWindow, app } = require('electron'); +const { app } = require('electron'); -const paths = require('../paths'); const moduleUpdater = require("../updater/moduleUpdater"); const updater = require("../updater/updater"); @@ -67,37 +65,14 @@ const sendState = (status) => { const launchSplash = (startMin) => { - win = new BrowserWindow({ + win = require('../utils/win')({ width: 300, - height: process.platform === 'darwin' ? 300 : 350, - frame: false, - resizable: false, - center: true, - show: false, - backgroundColor: '#2f3136', - webPreferences: { - preload: join(__dirname, 'preload.js') - } - }); - - const wc = win.webContents; + height: process.platform === 'darwin' ? 300 : 350 + }, join(__dirname, 'preload.js'), 'https://cdn.openasar.dev/splash'); if (process.platform !== 'darwin') win.on('closed', () => !launchedMainWindow && app.quit()); - wc.once('dom-ready', () => { - if (oaConfig.themeSync !== false) try { - wc.insertCSS(JSON.parse(fs.readFileSync(join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS); - } catch { } - - if (oaConfig.splashText === true) { - const buildInfo = require('../utils/buildInfo.js'); - wc.executeJavaScript(`debug.textContent = '${buildInfo.releaseChannel} ${buildInfo.version}\\nOpenAsar ${oaVersion}'`); - } - }); - if (!startMin) win.once('ready-to-show', () => win.show()); - - win.loadURL('https://cdn.openasar.dev/splash'); }; diff --git a/src/utils/win.js b/src/utils/win.js new file mode 100644 index 0000000..5760092 --- /dev/null +++ b/src/utils/win.js @@ -0,0 +1,30 @@ +const { BrowserWindow } = require('electron'); + +const paths = require('../paths'); +const fs = require('fs'); + + +module.exports = (opts, preload, url) => { + const win = new BrowserWindow({ + center: true, + frame: false, + resizable: false, + center: true, + backgroundColor: '#2f3136', + webPreferences: { + preload + }, + ...opts + }); + + const wc = win.webContents; + wc.once('dom-ready', () => { + if (oaConfig.themeSync !== false) try { + wc.insertCSS(JSON.parse(fs.readFileSync(join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS); + } catch { } + }); + + win.loadURL(url); + + return win; +}; \ No newline at end of file