2021-12-16 16:52:25 +00:00
|
|
|
const { app, BrowserWindow } = require('electron');
|
|
|
|
const { readFileSync } = require('fs');
|
|
|
|
const { join } = require('path');
|
2021-12-09 16:25:14 +00:00
|
|
|
|
2022-01-13 17:33:27 +00:00
|
|
|
if (process.platform === 'linux') { // Discord is a well-made app which properly implements WebRTC
|
|
|
|
if (process.env.PULSE_LATENCY_MSEC === undefined) {
|
|
|
|
process.env.PULSE_LATENCY_MSEC = 30;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-10 21:31:40 +00:00
|
|
|
log('Bootstrap', 'Forcing Electron props');
|
2021-12-10 21:44:19 +00:00
|
|
|
app.name = 'discord'; // Force name as sometimes breaks data path even with "discord" name (also fixes kernel?)
|
2021-12-10 21:31:40 +00:00
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
const requireNative = require('./utils/requireNative');
|
2021-12-26 17:48:09 +00:00
|
|
|
const argv = require('./utils/argv');
|
2021-12-10 18:37:50 +00:00
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
const paths = require('./paths');
|
2021-12-10 18:37:50 +00:00
|
|
|
global.moduleDataPath = paths.getModuleDataPath(); // Global because discord
|
2021-12-11 12:41:08 +00:00
|
|
|
app.setPath('userData', paths.getUserData()); // Set userData properly because electron
|
2021-12-10 18:37:50 +00:00
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
const buildInfo = require('./utils/buildInfo');
|
2021-12-10 18:37:50 +00:00
|
|
|
app.setVersion(buildInfo.version); // More global because discord / electron
|
2021-12-11 11:11:42 +00:00
|
|
|
global.releaseChannel = buildInfo.releaseChannel;
|
2021-12-09 16:25:14 +00:00
|
|
|
|
2021-12-09 19:26:22 +00:00
|
|
|
log('BuildInfo', 'Loaded build info', buildInfo);
|
|
|
|
|
2021-12-11 19:51:36 +00:00
|
|
|
const errorHandler = require('./errorHandler');
|
|
|
|
errorHandler.init();
|
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
// Just required for startup
|
|
|
|
const appSettings = require('./appSettings');
|
|
|
|
const GPUSettings = require('./GPUSettings');
|
|
|
|
const crashReporterSetup = require('./crashReporterSetup');
|
2022-01-28 20:47:31 +00:00
|
|
|
const splashScreen = require('./splash');
|
2021-12-09 16:25:14 +00:00
|
|
|
const Constants = require('./Constants');
|
|
|
|
const autoStart = require('./autoStart');
|
|
|
|
|
|
|
|
const updater = require('./updater/updater');
|
|
|
|
const moduleUpdater = require('./updater/moduleUpdater');
|
|
|
|
const appUpdater = require('./updater/appUpdater');
|
|
|
|
|
2021-12-10 14:21:35 +00:00
|
|
|
const settings = appSettings.getSettings();
|
|
|
|
if (!settings.get('enableHardwareAcceleration', true)) app.disableHardwareAcceleration();
|
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
let desktopCore;
|
|
|
|
const startCore = () => {
|
|
|
|
desktopCore = requireNative('discord_desktop_core');
|
|
|
|
log('Bootstrap', 'Required desktop_core:', desktopCore);
|
|
|
|
|
|
|
|
desktopCore.startup({
|
|
|
|
paths,
|
|
|
|
splashScreen,
|
|
|
|
moduleUpdater,
|
|
|
|
autoStart,
|
|
|
|
buildInfo,
|
|
|
|
appSettings,
|
|
|
|
Constants,
|
|
|
|
GPUSettings,
|
|
|
|
updater,
|
2021-12-16 22:13:42 +00:00
|
|
|
crashReporterSetup,
|
|
|
|
|
|
|
|
// OpenCore additionals (non-standard)
|
|
|
|
securityUtils: require('./utils/securityUtils.js')
|
2021-12-09 16:25:14 +00:00
|
|
|
});
|
2021-12-16 16:52:25 +00:00
|
|
|
|
|
|
|
const i = setImmediate(() => {
|
|
|
|
log('MainWindowInject', 'Attempting to get main window');
|
|
|
|
|
|
|
|
if (!global.mainWindowId) return;
|
|
|
|
|
|
|
|
log('MainWindowInject', 'Success, adding dom-ready handler');
|
|
|
|
|
|
|
|
clearInterval(i);
|
|
|
|
|
|
|
|
const bw = BrowserWindow.fromId(global.mainWindowId);
|
|
|
|
|
2021-12-27 22:51:22 +00:00
|
|
|
let donePageReady = false;
|
2021-12-16 16:52:25 +00:00
|
|
|
bw.webContents.on('dom-ready', () => {
|
2021-12-27 22:51:22 +00:00
|
|
|
if (!donePageReady) { // Only run once
|
|
|
|
splashScreen.pageReady(); // Override Core's pageReady with our own on dom-ready to show main window earlier
|
|
|
|
donePageReady = true;
|
|
|
|
}
|
2021-12-18 21:56:13 +00:00
|
|
|
|
2021-12-16 16:52:25 +00:00
|
|
|
log('MainWindowInject', 'dom-ready triggered, injecting JS');
|
|
|
|
|
2021-12-26 17:47:04 +00:00
|
|
|
const cmdSwitches = require('./cmdSwitches');
|
|
|
|
|
2021-12-17 23:00:33 +00:00
|
|
|
let injectJs = readFileSync(join(__dirname, 'mainWindowInject.js'), 'utf8');
|
|
|
|
|
|
|
|
const [ version1, version2 ] = oaVersion.split('-'); // Split via -
|
2021-12-26 17:47:04 +00:00
|
|
|
injectJs = injectJs
|
|
|
|
.replaceAll('<oa_version_channel>', version1[0].toUpperCase() + version1.substring(1).toLowerCase())
|
|
|
|
.replaceAll('<oa_version_hash>', version2 || 'custom')
|
|
|
|
.replaceAll('<oa_cmd_preset>', cmdSwitches.preset)
|
|
|
|
.replaceAll('<oa_cmd_full>', cmdSwitches.cmd);
|
2021-12-17 23:00:33 +00:00
|
|
|
|
|
|
|
bw.webContents.executeJavaScript(injectJs);
|
2021-12-16 16:52:25 +00:00
|
|
|
});
|
|
|
|
});
|
2021-12-09 16:25:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const startUpdate = () => {
|
2021-12-26 17:48:09 +00:00
|
|
|
const startMinimized = argv.hasFlag('--start-minimized');
|
|
|
|
log('Bootstrap', 'Start minimized:', startMinimized);
|
|
|
|
|
|
|
|
appUpdater.update(startMinimized, () => {
|
2021-12-12 11:45:25 +00:00
|
|
|
if (process.env.OPENASAR_NOSTART) {
|
|
|
|
log('Bootstrap', 'Found nostart variable, halting bootstrap');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
startCore();
|
|
|
|
}, () => {
|
2021-12-09 20:20:57 +00:00
|
|
|
log('Bootstrap', 'Setting main window visible');
|
2021-12-26 17:48:09 +00:00
|
|
|
desktopCore.setMainWindowVisible(!startMinimized);
|
2021-12-11 09:59:39 +00:00
|
|
|
|
|
|
|
setTimeout(() => { // Try to update our asar
|
2021-12-11 13:28:47 +00:00
|
|
|
if (oaConfig.autoupdate === false) return; // If autoupdate disabled, don't update
|
2021-12-11 09:59:39 +00:00
|
|
|
|
|
|
|
const asarUpdate = require('./asarUpdate');
|
|
|
|
|
|
|
|
try {
|
|
|
|
asarUpdate();
|
|
|
|
} catch (e) {
|
|
|
|
log('AsarUpdate', 'Failed to update', e);
|
|
|
|
}
|
|
|
|
}, 1000);
|
2021-12-09 16:25:14 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-12-11 10:37:43 +00:00
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
module.exports = () => {
|
|
|
|
// Paths logging
|
|
|
|
log('Paths', `Init! Returns:
|
|
|
|
getUserData: ${paths.getUserData()}
|
|
|
|
getUserDataVersioned: ${paths.getUserDataVersioned()}
|
|
|
|
getResources: ${paths.getResources()}
|
|
|
|
getModuleDataPath: ${paths.getModuleDataPath()}
|
|
|
|
getInstallPath: ${paths.getInstallPath()}`);
|
|
|
|
|
2021-12-11 10:37:43 +00:00
|
|
|
const instanceLock = app.requestSingleInstanceLock();
|
2022-01-21 12:47:23 +00:00
|
|
|
const allowMultiInstance = argv.hasFlag('--multi-instance') || oaConfig.multiInstance === true; // argv flag or config
|
2021-12-11 10:37:43 +00:00
|
|
|
|
2021-12-11 12:41:08 +00:00
|
|
|
console.log(instanceLock, allowMultiInstance);
|
|
|
|
|
2021-12-11 10:37:43 +00:00
|
|
|
if (!instanceLock && !allowMultiInstance) {
|
|
|
|
log('Bootstrap', 'Non-first instance, quitting (multi-instance disabled)');
|
|
|
|
return app.quit();
|
|
|
|
}
|
|
|
|
|
2021-12-09 16:25:14 +00:00
|
|
|
if (app.isReady()) {
|
|
|
|
startUpdate();
|
|
|
|
} else {
|
|
|
|
app.once('ready', startUpdate);
|
|
|
|
}
|
2022-01-21 12:47:23 +00:00
|
|
|
};
|