mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-11 18:09:50 +08:00
add power saver blocker
This commit is contained in:
@@ -5,6 +5,7 @@ import { app } from 'electron'
|
||||
import fs, { WriteStream } from 'node:fs'
|
||||
import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||
import * as JSONStream from 'JSONStream'
|
||||
import { initPowerSaveBlocker } from './power-saver-blocker'
|
||||
|
||||
const rerunInterval = (() => {
|
||||
let v = Number(process.env.MAIN_BOSSGEEKGO_RERUN_INTERVAL)
|
||||
@@ -89,6 +90,9 @@ export function runAutoChatWithDaemon() {
|
||||
app.exit(1)
|
||||
}
|
||||
|
||||
const disposePowerSaveBlocker = initPowerSaveBlocker()
|
||||
app.once('quit', disposePowerSaveBlocker)
|
||||
|
||||
const pipeForRead: fs.ReadStream = fs.createReadStream(null, { fd: 3 })
|
||||
const pipeForReadWithJsonParser = pipeForRead.pipe(JSONStream.parse())
|
||||
pipeForReadWithJsonParser?.on('data', function waitForCanRun(data) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { powerSaveBlocker } from 'electron'
|
||||
|
||||
export const initPowerSaveBlocker = (
|
||||
type: 'prevent-app-suspension' | 'prevent-display-sleep' = 'prevent-app-suspension'
|
||||
) => {
|
||||
const id = powerSaveBlocker.start(type)
|
||||
return function disposePowerSaveBlocker() {
|
||||
return powerSaveBlocker.stop(id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user