[CmdSwitches] Total rewrite (fixes parser for combining presets)
This commit is contained in:
parent
91a4f7377a
commit
316b458eee
|
@ -6,43 +6,22 @@ const presets = {
|
||||||
'battery': '--enable-features=TurnOffStreamingMediaCachingOnBattery --force_low_power_gpu' // Known to have better battery life for Chromium?
|
'battery': '--enable-features=TurnOffStreamingMediaCachingOnBattery --force_low_power_gpu' // Known to have better battery life for Chromium?
|
||||||
};
|
};
|
||||||
|
|
||||||
const combinePresets = (keys) => {
|
const combinePresets = (...keys) => Object.values(keys.reduce((acc, x) => {
|
||||||
let total = {};
|
for (const cmd of presets[x].split(' ')) {
|
||||||
for (const pre of keys) {
|
if (!cmd) continue;
|
||||||
for (const cmd of presets[pre].split(' ')) {
|
|
||||||
const [ key, value ] = cmd.split('=');
|
|
||||||
|
|
||||||
if (total[key]) {
|
const [ key, value ] = cmd.split('=');
|
||||||
if (value) total[key] += ',' + value; // Concat value with , for flags like --enable-features
|
|
||||||
} else total[key] = value;
|
if (!acc[key]) acc[key] = [key];
|
||||||
}
|
acc[key].push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.keys(total).reduce((acc, x) => acc += (x + (total[x] ? ('=' + total[x]) : '') + ' '), '');
|
return acc;
|
||||||
};
|
}, {}));
|
||||||
|
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
const preset = oaConfig.cmdPreset || 'perf'; // Default to perf enhance
|
for (const [ key, ...values ] of combinePresets('base', ...(oaConfig.cmdPreset || 'perf').split(','))) {
|
||||||
let cmdSwitches = presets.base + ' ' + (presets[preset] || '');
|
app.commandLine.appendSwitch(key.replace('--', ''), values.join(','));
|
||||||
|
|
||||||
log('CmdSwitches', 'Preset:', preset);
|
|
||||||
|
|
||||||
if (preset.includes(',')) cmdSwitches = combinePresets(preset.split(','));
|
|
||||||
|
|
||||||
if (cmdSwitches) {
|
|
||||||
module.exports.cmd = cmdSwitches;
|
|
||||||
module.exports.preset = preset;
|
|
||||||
|
|
||||||
const switches = cmdSwitches.split(' ');
|
|
||||||
|
|
||||||
for (const cmd of switches) {
|
|
||||||
if (!cmd) continue;
|
|
||||||
|
|
||||||
let [ key, value ] = cmd.split('=');
|
|
||||||
key = key.replace('--', ''); // Replace --key with key (?)
|
|
||||||
|
|
||||||
app.commandLine.appendSwitch(key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue