2021-12-21 10:38:18 +00:00
|
|
|
const { app } = require('electron');
|
|
|
|
|
|
|
|
const presets = {
|
2022-01-30 19:23:14 +00:00
|
|
|
'base': '--autoplay-policy=no-user-gesture-required --disable-features=WinRetrieveSuggestionsOnlyOnDemand', // Base Discord
|
2022-01-19 17:19:17 +00:00
|
|
|
'perf': `--enable-gpu-rasterization --enable-zero-copy --ignore-gpu-blocklist --enable-hardware-overlays=single-fullscreen,single-on-top,underlay --enable-features=EnableDrDc,CanvasOopRasterization,BackForwardCache:TimeToLiveInBackForwardCacheInSeconds/300/should_ignore_blocklists/true/enable_same_site/true,ThrottleDisplayNoneAndVisibilityHiddenCrossOriginIframes,UseSkiaRenderer,WebAssemblyLazyCompilation --disable-features=Vulkan --force_high_performance_gpu --enable-quic`, // Performance
|
2022-01-13 13:42:04 +00:00
|
|
|
'disablemediakeys': '--disable-features=HardwareMediaKeyHandling', // Disables media keys (common want?)
|
2022-01-19 17:19:17 +00:00
|
|
|
'battery': '--enable-features=TurnOffStreamingMediaCachingOnBattery --force_low_power_gpu' // Known to have better battery life for Chromium?
|
2021-12-21 10:38:18 +00:00
|
|
|
};
|
|
|
|
|
2022-01-13 13:42:04 +00:00
|
|
|
const combinePresets = (keys) => {
|
|
|
|
let total = {};
|
|
|
|
for (const pre of keys) {
|
|
|
|
for (const cmd of presets[pre].split(' ')) {
|
|
|
|
const [ key, value ] = cmd.split('=');
|
2021-12-21 10:38:18 +00:00
|
|
|
|
2022-01-13 13:42:04 +00:00
|
|
|
if (total[key]) {
|
2022-01-30 19:23:14 +00:00
|
|
|
if (value) total[key] += ',' + value; // Concat value with , for flags like --enable-features
|
|
|
|
} else total[key] = value;
|
2021-12-21 10:38:18 +00:00
|
|
|
}
|
2022-01-13 13:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Object.keys(total).reduce((acc, x) => acc += (x + (total[x] ? ('=' + total[x]) : '') + ' '), '');
|
|
|
|
};
|
2021-12-21 10:38:18 +00:00
|
|
|
|
|
|
|
|
2022-01-13 13:42:04 +00:00
|
|
|
module.exports = () => {
|
2022-01-30 19:23:14 +00:00
|
|
|
const preset = oaConfig.cmdPreset || 'perf'; // Default to perf enhance
|
2022-02-01 20:35:59 +00:00
|
|
|
let cmdSwitches = presets.base + ' ' + (presets[preset] || '');
|
2022-01-13 13:42:04 +00:00
|
|
|
|
|
|
|
log('CmdSwitches', 'Preset:', preset);
|
|
|
|
|
|
|
|
if (preset.includes(',')) cmdSwitches = combinePresets(preset.split(','));
|
2021-12-21 10:38:18 +00:00
|
|
|
|
|
|
|
if (cmdSwitches) {
|
|
|
|
cmdSwitches = `--flag-switches-begin ` + cmdSwitches + ` --flag-switches-end`; // Probably unneeded for Chromium / Electron manual flags but add anyway
|
|
|
|
|
|
|
|
log('CmdSwitches', 'Switches:', cmdSwitches);
|
|
|
|
|
2022-01-13 13:42:04 +00:00
|
|
|
module.exports.cmd = cmdSwitches;
|
|
|
|
module.exports.preset = preset;
|
|
|
|
|
2021-12-21 10:38:18 +00:00
|
|
|
const switches = cmdSwitches.split(' ');
|
|
|
|
|
|
|
|
for (const cmd of switches) {
|
2022-02-01 20:35:59 +00:00
|
|
|
if (!cmd) continue;
|
|
|
|
|
2022-01-13 13:42:04 +00:00
|
|
|
let [ key, value ] = cmd.split('=');
|
|
|
|
key = key.replace('--', ''); // Replace --key with key (?)
|
2021-12-21 10:38:18 +00:00
|
|
|
|
|
|
|
app.commandLine.appendSwitch(key, value);
|
|
|
|
log('CmdSwitches', 'Appended switch', key, value);
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 13:42:04 +00:00
|
|
|
}
|