[Utils > Win] Make standard win constructor

This commit is contained in:
Ducko 2022-04-17 22:46:38 +01:00
parent 376567c97e
commit 8bfca99053
3 changed files with 38 additions and 43 deletions

View File

@ -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');
};

View File

@ -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');
};

30
src/utils/win.js Normal file
View File

@ -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;
};