mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-08-04 12:46:59 +08:00
change exit code; make enum for exit code
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user