mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-05 23:47:54 +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 fs, { WriteStream } from 'node:fs'
|
||||||
import { pipeWriteRegardlessError } from '../utils/pipe'
|
import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||||
import * as JSONStream from 'JSONStream'
|
import * as JSONStream from 'JSONStream'
|
||||||
|
import { initPowerSaveBlocker } from './power-saver-blocker'
|
||||||
|
|
||||||
const rerunInterval = (() => {
|
const rerunInterval = (() => {
|
||||||
let v = Number(process.env.MAIN_BOSSGEEKGO_RERUN_INTERVAL)
|
let v = Number(process.env.MAIN_BOSSGEEKGO_RERUN_INTERVAL)
|
||||||
@@ -89,6 +90,9 @@ export function runAutoChatWithDaemon() {
|
|||||||
app.exit(1)
|
app.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const disposePowerSaveBlocker = initPowerSaveBlocker()
|
||||||
|
app.once('quit', disposePowerSaveBlocker)
|
||||||
|
|
||||||
const pipeForRead: fs.ReadStream = fs.createReadStream(null, { fd: 3 })
|
const pipeForRead: fs.ReadStream = fs.createReadStream(null, { fd: 3 })
|
||||||
const pipeForReadWithJsonParser = pipeForRead.pipe(JSONStream.parse())
|
const pipeForReadWithJsonParser = pipeForRead.pipe(JSONStream.parse())
|
||||||
pipeForReadWithJsonParser?.on('data', function waitForCanRun(data) {
|
pipeForReadWithJsonParser?.on('data', function waitForCanRun(data) {
|
||||||
|
|||||||
+10
@@ -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