add pre-run-check handler

This commit is contained in:
geekgeekrun
2026-02-08 19:39:37 +08:00
parent c298904d25
commit 68170e8b60
3 changed files with 60 additions and 50 deletions

View File

@@ -13,7 +13,6 @@ import { ChildProcess } from 'child_process'
import * as JSONStream from 'JSONStream'
import { checkCookieListFormat } from '../../../../common/utils/cookie'
import { getAnyAvailablePuppeteerExecutable } from '../../DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable/index'
import { AUTO_CHAT_ERROR_EXIT_CODE } from '../../../../common/enums/auto-start-chat'
import { mainWindow } from '../../../window/mainWindow'
import {
getAutoStartChatRecord,
@@ -21,8 +20,7 @@ import {
getCompanyLibrary,
getJobLibrary,
getJobHistoryByEncryptId,
getMarkAsNotSuitRecord,
saveAndGetCurrentRunRecord,
getMarkAsNotSuitRecord
} from '../utils/db/index'
import { PageReq } from '../../../../common/types/pagination'
import { pipeWriteRegardlessError } from '../../utils/pipe'
@@ -54,6 +52,12 @@ import { daemonEE, sendToDaemon } from '../connect-to-daemon'
import { runCommon } from '../../../features/run-common'
import { loginWithCookieAssistant } from '../../../features/login-with-cookie-assistant'
import { configWithBrowserAssistant } from '../../../features/config-with-browser-assistant'
import {
createFirstLaunchNoticeApproveFlag,
isFirstLaunchNoticeApproveFlagExist,
waitForUserApproveAgreement
} from '../../../features/first-launch-notice-window'
import { getLastUsedAndAvailableBrowser } from '../../DOWNLOAD_DEPENDENCIES/utils/browser-history'
export default function initIpc() {
ipcMain.handle('fetch-config-file-content', async () => {
@@ -192,7 +196,7 @@ export default function initIpc() {
ipcMain.handle('run-geek-auto-start-chat-with-boss', async (ev) => {
const mode = 'geekAutoStartWithBossMain'
const { runRecordId } = await runCommon({ mode })
daemonEE.on('message', function handler (message) {
daemonEE.on('message', function handler(message) {
if (message.workerId !== mode) {
return
}
@@ -206,7 +210,7 @@ export default function initIpc() {
ipcMain.handle('run-read-no-reply-auto-reminder', async () => {
const mode = 'readNoReplyAutoReminderMain'
const { runRecordId } = await runCommon({ mode })
daemonEE.on('message', function handler (message) {
daemonEE.on('message', function handler(message) {
if (message.workerId !== mode) {
return
}
@@ -220,7 +224,7 @@ export default function initIpc() {
ipcMain.handle('stop-geek-auto-start-chat-with-boss', async () => {
mainWindow?.webContents.send('geek-auto-start-chat-with-boss-stopping')
const p = new Promise((resolve) => {
daemonEE.on('message', function handler (message) {
daemonEE.on('message', function handler(message) {
if (message.workerId !== 'geekAutoStartWithBossMain') {
return
}
@@ -233,7 +237,7 @@ export default function initIpc() {
await sendToDaemon(
{
type: 'stop-worker',
workerId: 'geekAutoStartWithBossMain',
workerId: 'geekAutoStartWithBossMain'
},
{
needCallback: true
@@ -246,8 +250,8 @@ export default function initIpc() {
ipcMain.handle('stop-read-no-reply-auto-reminder', async () => {
mainWindow?.webContents.send('read-no-reply-auto-reminder-stopping')
const p = new Promise(resolve => {
daemonEE.on('message', function handler (message) {
const p = new Promise((resolve) => {
daemonEE.on('message', function handler(message) {
if (message.workerId !== 'readNoReplyAutoReminderMain') {
return
}
@@ -260,7 +264,7 @@ export default function initIpc() {
await sendToDaemon(
{
type: 'stop-worker',
workerId: 'readNoReplyAutoReminderMain',
workerId: 'readNoReplyAutoReminderMain'
},
{
needCallback: true
@@ -536,6 +540,42 @@ export default function initIpc() {
})
})
ipcMain.handle('pre-enter-setting-ui', async () => {
if (!isFirstLaunchNoticeApproveFlagExist()) {
try {
await waitForUserApproveAgreement({
windowOption: {
parent: mainWindow!,
modal: true,
show: true
}
})
createFirstLaunchNoticeApproveFlag()
} catch {
app.exit(0)
return
}
}
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
if (!puppeteerExecutable) {
const lastBrowser = await getLastUsedAndAvailableBrowser()
if (!lastBrowser) {
try {
await configWithBrowserAssistant({
windowOption: {
parent: mainWindow!,
modal: true,
show: true
},
autoFind: true
})
} catch (err) {
void err
}
}
}
})
ipcMain.handle('exit-app-immediately', () => {
app.exit(0)
})

View File

@@ -1,14 +1,7 @@
import { app, BrowserWindow, shell } from 'electron'
import { BrowserWindow, shell } from 'electron'
import path from 'path'
import { openDevTools } from '../commands'
import {
createFirstLaunchNoticeApproveFlag,
isFirstLaunchNoticeApproveFlagExist,
waitForUserApproveAgreement
} from '../features/first-launch-notice-window'
import { daemonEE } from '../flow/OPEN_SETTING_WINDOW/connect-to-daemon'
import { getLastUsedAndAvailableBrowser } from '../flow/DOWNLOAD_DEPENDENCIES/utils/browser-history'
import { configWithBrowserAssistant } from '../features/config-with-browser-assistant'
export let mainWindow: BrowserWindow | null = null
export function createMainWindow(): BrowserWindow {
@@ -33,36 +26,6 @@ export function createMainWindow(): BrowserWindow {
mainWindow.on('ready-to-show', () => {
mainWindow.show()
})
mainWindow.on('ready-to-show', async () => {
if (!isFirstLaunchNoticeApproveFlagExist()) {
try {
await waitForUserApproveAgreement({
windowOption: {
parent: mainWindow!,
modal: true,
show: true
}
})
createFirstLaunchNoticeApproveFlag()
} catch {
app.exit(0)
return
}
}
const lastBrowser = await getLastUsedAndAvailableBrowser()
if (!lastBrowser) {
try {
await configWithBrowserAssistant({
windowOption: {
parent: mainWindow!,
modal: true,
show: true
},
autoFind: true
})
} catch (err) {}
}
})
mainWindow.on('ready-to-show', async () => {
process.env.NODE_ENV === 'development' &&
setTimeout(() => {

View File

@@ -27,7 +27,14 @@ const router = useRouter()
onMounted(async () => {
gtagRenderer('bootstrap_mounted')
await sleep(2000)
router.replace('/main-layout')
await sleep(1500)
try {
await electron.ipcRenderer.invoke('pre-enter-setting-ui')
} catch (err) {
console.log('pre-enter-setting-ui error', err)
} finally {
await sleep(500)
router.replace('/main-layout')
}
})
</script>