add logic to detect and handle login invalid - will exit auto start chat and show cookie assistant. add the logic to store cookie and local storage while auto start chat running.

This commit is contained in:
geekgeekrun
2024-03-03 23:28:36 +08:00
parent 6a7b402101
commit a25e7aedb9
7 changed files with 106 additions and 18 deletions
@@ -15,7 +15,7 @@ const initPlugins = (hooks) => {
let isParentProcessDisconnect = false
export const runAutoChat = async () => {
const { initPuppeteer, mainLoop, closeBrowserWindow } = await import(
const { initPuppeteer, mainLoop, closeBrowserWindow, autoStartChatEventBus } = await import(
'@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs'
)
process.on('disconnect', () => {
@@ -73,16 +73,27 @@ export const runAutoChat = async () => {
type: 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED' //geek-auto-start-chat-with-boss-started
}) + '\r\n'
)
while (!([isParentProcessDisconnect].includes(true))) {
autoStartChatEventBus.once('LOGIN_STATUS_INVALID', () => {
pipeWriteRegardlessError(
pipe,
JSON.stringify({
type: 'LOGIN_STATUS_INVALID' //geek-auto-start-chat-with-boss-started
}) + '\r\n'
)
})
while (![isParentProcessDisconnect].includes(true)) {
try {
await mainLoop(hooks)
} catch (err) {
console.log(err)
// if(err instanceof Error && err.message.includes('ERR_MODULE_NOT_FOUND')) {
// throw err
// } else {
void err
// }
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
process.exit(2)
break
} else {
throw err
}
}
}
closeBrowserWindow()
+7 -1
View File
@@ -19,6 +19,7 @@ import {
DOWNLOAD_ERROR_EXIT_CODE,
getAnyAvailablePuppeteerExecutable
} from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES'
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
let mainWindow: BrowserWindow | null = null
export function createMainWindow(): void {
@@ -123,13 +124,18 @@ export function createMainWindow(): void {
})
console.log(subProcessOfPuppeteer)
return new Promise((resolve, reject) => {
subProcessOfPuppeteer!.stdio[3]!.pipe(JSONStream.parse()).on('data', (raw) => {
subProcessOfPuppeteer!.stdio[3]!.pipe(JSONStream.parse()).on('data', async (raw) => {
const data = raw
switch (data.type) {
case 'GEEK_AUTO_START_CHAT_WITH_BOSS_STARTED': {
resolve(data)
break
}
case 'LOGIN_STATUS_INVALID': {
await sleep(500)
mainWindow?.webContents.send('check-boss-zhipin-cookie-file')
return
}
default: {
return
}
@@ -1,7 +1,7 @@
<template><RouterView /></template>
<script lang="ts" setup>
import { onUnmounted } from 'vue'
import { onMounted, onUnmounted } from 'vue'
import { mountGlobalDialog as mountDependenciesSetupProgressIndicatorDialog } from '@renderer/features/DependenciesSetupProgressIndicatorDialog/operations'
import { mountGlobalDialog as mountWaitForLoginDialog } from '@renderer/features/WaitForLoginDialog/operations'
@@ -14,6 +14,12 @@ onUnmounted(() => {
} catch {}
}
})
onMounted(() => {
electron.ipcRenderer.on('check-boss-zhipin-cookie-file', mountWaitForLoginDialog)
})
onUnmounted(() => {
electron.ipcRenderer.removeListener('check-boss-zhipin-cookie-file', mountWaitForLoginDialog)
})
;(async () => {
const checkDependenciesResult = await electron.ipcRenderer.invoke('check-dependencies')
if (Object.values(checkDependenciesResult).includes(false)) {