[General] Electron 17 minor rewrite, large logging cleanup
This commit is contained in:
parent
97ab2297ff
commit
9fd8dc8530
5 changed files with 14 additions and 13 deletions
6
src/bootstrap.js
vendored
6
src/bootstrap.js
vendored
|
@ -29,8 +29,7 @@ if (!settings.get('enableHardwareAcceleration', true)) app.disableHardwareAccele
|
||||||
|
|
||||||
let desktopCore;
|
let desktopCore;
|
||||||
const startCore = () => {
|
const startCore = () => {
|
||||||
desktopCore = require('discord_desktop_core');
|
desktopCore = require('./utils/requireNative')('discord_desktop_core');
|
||||||
log('Bootstrap', 'Required core');
|
|
||||||
|
|
||||||
desktopCore.startup({
|
desktopCore.startup({
|
||||||
splashScreen,
|
splashScreen,
|
||||||
|
@ -77,7 +76,6 @@ const startUpdate = async () => {
|
||||||
|
|
||||||
startCore();
|
startCore();
|
||||||
}, () => {
|
}, () => {
|
||||||
log('Bootstrap', 'Main window visible');
|
|
||||||
desktopCore.setMainWindowVisible(!startMinimized);
|
desktopCore.setMainWindowVisible(!startMinimized);
|
||||||
|
|
||||||
setTimeout(() => { // Try to update our asar
|
setTimeout(() => { // Try to update our asar
|
||||||
|
@ -88,7 +86,7 @@ const startUpdate = async () => {
|
||||||
try {
|
try {
|
||||||
require('./asarUpdate')();
|
require('./asarUpdate')();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('AsarUpdate', 'Failed', e);
|
log('AsarUpdate', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
|
@ -13,8 +13,8 @@ global.oaConfig = require('./appSettings').getSettings().get('openasar', {});
|
||||||
require('./cmdSwitches')();
|
require('./cmdSwitches')();
|
||||||
|
|
||||||
if (process.argv.includes('--overlay-host')) { // If overlay
|
if (process.argv.includes('--overlay-host')) { // If overlay
|
||||||
require('./utils/u2QuickLoad'); // Manually load updater 2 module paths (all modules)
|
require('./utils/u2QuickLoad'); // Manually load Updater v2 module paths (all modules)
|
||||||
require('discord_overlay2/standalone_host.js'); // Start overlay
|
require('./utils/requireNative')('discord_overlay2', 'standalone_host.js'); // Start overlay
|
||||||
} else {
|
} else {
|
||||||
require('./bootstrap')(); // Start bootstrap
|
require('./bootstrap')(); // Start bootstrap
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@ let splashWindow, updateTimeout, newUpdater;
|
||||||
|
|
||||||
|
|
||||||
exports.initSplash = (startMinimized = false) => {
|
exports.initSplash = (startMinimized = false) => {
|
||||||
log('Splash', `Initing`);
|
log('Splash', `Init`);
|
||||||
|
|
||||||
newUpdater = updater.getUpdater();
|
newUpdater = updater.getUpdater();
|
||||||
|
|
||||||
|
@ -32,8 +32,6 @@ exports.initSplash = (startMinimized = false) => {
|
||||||
if (process.env.OPENASAR_QUICKSTART || oaConfig.quickstart) setTimeout(() => {
|
if (process.env.OPENASAR_QUICKSTART || oaConfig.quickstart) setTimeout(() => {
|
||||||
destroySplash();
|
destroySplash();
|
||||||
|
|
||||||
if (newUpdater != null) require('../utils/u2QuickLoad'); // Manually load desktop_core module path for faster requiring
|
|
||||||
|
|
||||||
launchMainWindow();
|
launchMainWindow();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -62,8 +60,6 @@ const destroySplash = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const launchMainWindow = () => {
|
const launchMainWindow = () => {
|
||||||
log('Splash', 'Launch main');
|
|
||||||
|
|
||||||
for (const e in modulesListeners) moduleUpdater.events.removeListener(e, modulesListeners[e]); // Remove updater v1 listeners
|
for (const e in modulesListeners) moduleUpdater.events.removeListener(e, modulesListeners[e]); // Remove updater v1 listeners
|
||||||
|
|
||||||
if (!launchedMainWindow && splashWindow != null) {
|
if (!launchedMainWindow && splashWindow != null) {
|
||||||
|
@ -204,8 +200,9 @@ const updateUntilCurrent = async () => {
|
||||||
return launchMainWindow();
|
return launchMainWindow();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('Splash', 'Update failed', e);
|
log('Splash', e);
|
||||||
sendState('fail');
|
sendState('fail');
|
||||||
|
|
||||||
await new Promise(res => scheduleNextUpdate(res));
|
await new Promise(res => scheduleNextUpdate(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,7 @@ exports.installPendingUpdates = () => {
|
||||||
installModule(m, 0, join(bootstrapPath, m)); // Intentional invalid path
|
installModule(m, 0, join(bootstrapPath, m)); // Intentional invalid path
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('Modules', 'Bootstrap fail', e);
|
log('Modules', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
6
src/utils/requireNative.js
Normal file
6
src/utils/requireNative.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// Custom requireNative as Electron >=17 breaks Module.globalPaths for some reason
|
||||||
|
// For Updater v2: get direct path in globalPaths ("d")
|
||||||
|
// For Module Updater: get root path for all modules in globalPaths
|
||||||
|
|
||||||
|
const g = require('module').globalPaths;
|
||||||
|
module.exports = (n, e = '') => require(require('path').join(g.find((x) => x.includes(n)) ?? g[0], n, e));
|
Loading…
Add table
Add a link
Reference in a new issue