From 55cc92a4981c3c5bd04a8b8362b8d94d76d7f45d Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Mon, 11 Mar 2024 07:03:11 +0800 Subject: [PATCH] change exit code; make enum for exit code --- .../index.mjs | 9 +++++++-- .../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts | 5 ++--- .../main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS/index.ts | 11 ++++++++--- packages/ui/src/main/window/mainWindow.ts | 5 +++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs b/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs index 641b305..4a33475 100644 --- a/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs +++ b/packages/run-core-of-geek-auto-start-chat-with-boss/index.mjs @@ -17,10 +17,15 @@ const initPlugins = (hooks) => { new DingtalkPlugin(dingTalkAccessToken).apply(hooks) } +const AUTO_CHAT_ERROR_EXIT_CODE = { + COOKIE_INVALID: 81, + LOGIN_STATUS_INVALID: 82 +} + ;(async () => { if (!bossCookies?.length) { console.error('There is no cookies. You can save a copy with EditThisCookie extension.') - process.exit(1) + process.exit(AUTO_CHAT_ERROR_EXIT_CODE.COOKIE_INVALID) } const hooks = { puppeteerLaunched: new SyncHook(), @@ -39,7 +44,7 @@ const initPlugins = (hooks) => { } catch (err) { console.log(err) if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) { - process.exit(2) + process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID) break } await sleep(3000) diff --git a/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts b/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts index f2bb775..2f2402d 100644 --- a/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts +++ b/packages/ui/src/main/flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index.ts @@ -5,8 +5,7 @@ import { pipeWriteRegardlessError } from '../utils/pipe' import { sleep } from '@geekgeekrun/utils/sleep.mjs' export enum DOWNLOAD_ERROR_EXIT_CODE { - NO_ERROR = 0, - DOWNLOAD_ERROR = 1 + DOWNLOAD_ERROR = 80 } export const checkAndDownloadDependenciesForInit = async () => { @@ -84,7 +83,7 @@ export const checkAndDownloadDependenciesForInit = async () => { }) await promiseWithResolver.promise - app.exit(DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR) + app.exit() } catch (err) { console.error(err) pipeWriteRegardlessError( diff --git a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS/index.ts b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS/index.ts index 1a051ed..49e3428 100644 --- a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS/index.ts +++ b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS/index.ts @@ -7,6 +7,11 @@ import { pipeWriteRegardlessError } from '../utils/pipe' import { getAnyAvailablePuppeteerExecutable } from '../CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable' import { sleep } from '@geekgeekrun/utils/sleep.mjs' +export enum AUTO_CHAT_ERROR_EXIT_CODE { + PUPPETEER_IS_NOT_EXECUTABLE = 81, + LOGIN_STATUS_INVALID = 82 +} + const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json') const initPlugins = (hooks) => { @@ -47,13 +52,13 @@ export const runAutoChat = async () => { ) } catch (err) { console.error(err) - app.exit(1) + app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE) return } const isPuppeteerExecutable = !!(await getAnyAvailablePuppeteerExecutable()) if (!isPuppeteerExecutable) { - app.exit(1) + app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE) return } @@ -90,7 +95,7 @@ export const runAutoChat = async () => { } catch (err) { console.log(err) if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) { - process.exit(2) + process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID) break } await sleep(3000) diff --git a/packages/ui/src/main/window/mainWindow.ts b/packages/ui/src/main/window/mainWindow.ts index 03e5dae..f4d11b5 100644 --- a/packages/ui/src/main/window/mainWindow.ts +++ b/packages/ui/src/main/window/mainWindow.ts @@ -16,6 +16,7 @@ import { checkCookieListFormat } from '../../common/utils/cookie' import { getAnyAvailablePuppeteerExecutable } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable/index' import { DOWNLOAD_ERROR_EXIT_CODE } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index' import { sleep } from '@geekgeekrun/utils/sleep.mjs' +import { AUTO_CHAT_ERROR_EXIT_CODE } from '../flow/GEEK_AUTO_START_CHAT_WITH_BOSS' let mainWindow: BrowserWindow | null = null export function createMainWindow(): void { @@ -151,7 +152,7 @@ export function createMainWindow(): void { subProcessOfPuppeteer!.once('exit', (exitCode) => { subProcessOfPuppeteer = null - if (exitCode === 1) { + if (exitCode === AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE) { // means cannot find downloaded puppeteer reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES') } else { @@ -211,7 +212,7 @@ export function createMainWindow(): void { ) subProcessOfCheckAndDownloadDependencies!.once('exit', (exitCode) => { switch (exitCode) { - case DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR: { + case 0: { resolve(exitCode) break }