fix screenshot error when page closed; catch EPIPE globally; rigister gui process

This commit is contained in:
geekgeekrun
2026-01-17 18:07:50 +08:00
parent 9639151fdd
commit 5063f9c2aa
5 changed files with 82 additions and 89 deletions
@@ -82,5 +82,13 @@ export function openSettingWindow() {
needCallback: true
}
)
await sendToDaemon(
{
type: 'gui-register'
},
{
needCallback: true
}
)
})
}
@@ -52,7 +52,21 @@ export const pageMapByName: {
async function periodPushCurrentPageScreenshot () {
try {
await pushCurrentPageScreenshot(pageMapByName.boss)
if (pageMapByName.boss?.isClosed()) {
return
}
const shouldExit = await checkShouldExit()
if (shouldExit) {
return
}
try {
await pushCurrentPageScreenshot(pageMapByName.boss)
}
catch (err) {
if (err?.message?.includes(`PAGE_CLOSED`)) {
return
}
}
setTimeout(periodPushCurrentPageScreenshot, SCREENSHOT_INTERVAL_MS)
}
catch {}
+9
View File
@@ -3,6 +3,15 @@ import { runCommon } from './features/run-common';
import { launchDaemon } from './flow/OPEN_SETTING_WINDOW/launch-daemon';
import { connectToDaemon } from './flow/OPEN_SETTING_WINDOW/connect-to-daemon';
import { randomUUID } from 'crypto';
// 捕获未处理的 EPIPE 错误
process.on('uncaughtException', (err) => {
if (err?.code === 'EPIPE' || err?.code === 'ERR_STREAM_DESTROYED') {
return
}
throw err
});
const isUiDev = process.env.NODE_ENV === 'development'
const commandlineArgs = minimist(isUiDev ? process.argv.slice(2) : process.argv.slice(1))
console.log(commandlineArgs)
+11 -4
View File
@@ -26,6 +26,9 @@ export async function pushCurrentPageScreenshot (page) {
}
})
} catch (err) {
if (err?.message?.includes('Session closed')) {
throw new Error(`PAGE_CLOSED`)
}
// 截图失败不应影响主流程
console.warn('[READ_NO_REPLY_AUTO_REMINDER] pushCurrentPageScreenshot error', err)
}
@@ -38,9 +41,6 @@ export class PeriodPushCurrentPageScreenshotPlugin {
(page) => {
async function periodPushCurrentPageScreenshot () {
try {
if (!page) {
return
}
if (page.isClosed()) {
return
}
@@ -48,7 +48,14 @@ export class PeriodPushCurrentPageScreenshotPlugin {
if (shouldExit) {
return
}
await pushCurrentPageScreenshot(page)
try {
await pushCurrentPageScreenshot(page)
}
catch (err) {
if (err?.message?.includes(`PAGE_CLOSED`)) {
return
}
}
setTimeout(periodPushCurrentPageScreenshot, SCREENSHOT_INTERVAL_MS)
}
catch {}