idle: add linux/mac hibernation support

This commit is contained in:
Oj 2023-01-09 11:03:59 +00:00
parent 7774f39a0c
commit 73a4ddff08

View File

@ -1,6 +1,6 @@
import { exec } from 'child_process'; import { exec } from 'child_process';
const killProcesses = async pids => process.platform !== 'win32' ? Promise.resolve('') : new Promise(resolve => exec(`taskkill /F ${pids.map(x => `/PID ${x}`).join(' ')}`, (e, out) => resolve(out))); const killProcesses = async pids => new Promise(resolve => exec(process.platform !== 'win32' ? `kill -9 ${pids.join(' ')}` : `taskkill /F ${pids.map(x => `/PID ${x}`).join(' ')}`, (e, out) => resolve(out)));
export default async (CDP, { browserEngine, closeHandlers }) => { export default async (CDP, { browserEngine, closeHandlers }) => {
if (browserEngine !== 'chromium') { // current implementation is for chromium-based only if (browserEngine !== 'chromium') { // current implementation is for chromium-based only
@ -44,7 +44,7 @@ export default async (CDP, { browserEngine, closeHandlers }) => {
let wakeUrl, hibernating = false; let wakeUrl, hibernating = false;
const hibernate = async () => { // hibernate - crashing chromium internally to save max memory. users will see a crash/gone wrong page but we hopefully "reload" quick enough once visible again for not much notice. const hibernate = async () => { // hibernate - crashing chromium internally to save max memory. users will see a crash/gone wrong page but we hopefully "reload" quick enough once visible again for not much notice.
if (hibernating) return; if (hibernating) return;
if (process.platform !== 'win32') return sleep(); // sleep instead - full hibernation is windows only for now due to needing to do native things // if (process.platform !== 'win32') return sleep(); // sleep instead - full hibernation is windows only for now due to needing to do native things
hibernating = true; hibernating = true;