mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 08:27:13 +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)
|
new DingtalkPlugin(dingTalkAccessToken).apply(hooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AUTO_CHAT_ERROR_EXIT_CODE = {
|
||||||
|
COOKIE_INVALID: 81,
|
||||||
|
LOGIN_STATUS_INVALID: 82
|
||||||
|
}
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
if (!bossCookies?.length) {
|
if (!bossCookies?.length) {
|
||||||
console.error('There is no cookies. You can save a copy with EditThisCookie extension.')
|
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 = {
|
const hooks = {
|
||||||
puppeteerLaunched: new SyncHook(),
|
puppeteerLaunched: new SyncHook(),
|
||||||
@@ -39,7 +44,7 @@ const initPlugins = (hooks) => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
|
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
|
||||||
process.exit(2)
|
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
await sleep(3000)
|
await sleep(3000)
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import { pipeWriteRegardlessError } from '../utils/pipe'
|
|||||||
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
|
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
|
||||||
|
|
||||||
export enum DOWNLOAD_ERROR_EXIT_CODE {
|
export enum DOWNLOAD_ERROR_EXIT_CODE {
|
||||||
NO_ERROR = 0,
|
DOWNLOAD_ERROR = 80
|
||||||
DOWNLOAD_ERROR = 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const checkAndDownloadDependenciesForInit = async () => {
|
export const checkAndDownloadDependenciesForInit = async () => {
|
||||||
@@ -84,7 +83,7 @@ export const checkAndDownloadDependenciesForInit = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
await promiseWithResolver.promise
|
await promiseWithResolver.promise
|
||||||
app.exit(DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR)
|
app.exit()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
pipeWriteRegardlessError(
|
pipeWriteRegardlessError(
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ import { pipeWriteRegardlessError } from '../utils/pipe'
|
|||||||
import { getAnyAvailablePuppeteerExecutable } from '../CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
|
import { getAnyAvailablePuppeteerExecutable } from '../CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
|
||||||
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
|
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 { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json')
|
||||||
|
|
||||||
const initPlugins = (hooks) => {
|
const initPlugins = (hooks) => {
|
||||||
@@ -47,13 +52,13 @@ export const runAutoChat = async () => {
|
|||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
app.exit(1)
|
app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const isPuppeteerExecutable = !!(await getAnyAvailablePuppeteerExecutable())
|
const isPuppeteerExecutable = !!(await getAnyAvailablePuppeteerExecutable())
|
||||||
if (!isPuppeteerExecutable) {
|
if (!isPuppeteerExecutable) {
|
||||||
app.exit(1)
|
app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +95,7 @@ export const runAutoChat = async () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
|
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
|
||||||
process.exit(2)
|
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
await sleep(3000)
|
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 { getAnyAvailablePuppeteerExecutable } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable/index'
|
||||||
import { DOWNLOAD_ERROR_EXIT_CODE } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index'
|
import { DOWNLOAD_ERROR_EXIT_CODE } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index'
|
||||||
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
|
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
|
let mainWindow: BrowserWindow | null = null
|
||||||
|
|
||||||
export function createMainWindow(): void {
|
export function createMainWindow(): void {
|
||||||
@@ -151,7 +152,7 @@ export function createMainWindow(): void {
|
|||||||
|
|
||||||
subProcessOfPuppeteer!.once('exit', (exitCode) => {
|
subProcessOfPuppeteer!.once('exit', (exitCode) => {
|
||||||
subProcessOfPuppeteer = null
|
subProcessOfPuppeteer = null
|
||||||
if (exitCode === 1) {
|
if (exitCode === AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE) {
|
||||||
// means cannot find downloaded puppeteer
|
// means cannot find downloaded puppeteer
|
||||||
reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')
|
reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')
|
||||||
} else {
|
} else {
|
||||||
@@ -211,7 +212,7 @@ export function createMainWindow(): void {
|
|||||||
)
|
)
|
||||||
subProcessOfCheckAndDownloadDependencies!.once('exit', (exitCode) => {
|
subProcessOfCheckAndDownloadDependencies!.once('exit', (exitCode) => {
|
||||||
switch (exitCode) {
|
switch (exitCode) {
|
||||||
case DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR: {
|
case 0: {
|
||||||
resolve(exitCode)
|
resolve(exitCode)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user