diff --git a/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs b/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs index 43f212a..7bad52f 100644 --- a/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs +++ b/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs @@ -19,6 +19,10 @@ import JSON5 from 'json5' import url from 'url'; import packageJson from './package.json' assert {type: 'json'} +import { EventEmitter } from 'node:events' + +export const loginEventBus = new EventEmitter() + const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) const isUiDev = process.env.NODE_ENV === 'development' @@ -98,7 +102,7 @@ export async function main() { } }) - const { dispose: disposeNavigation } = await blockNavigation(page, (req) => !req.url().startsWith('https://www.zhipin.com')) + const { dispose: disposeNavigationLock } = await blockNavigation(page, (req) => !req.url().startsWith('https://www.zhipin.com')) await page.goto('https://www.zhipin.com/web/user/'); const loginSuccessPromiseList = [ @@ -138,8 +142,19 @@ export async function main() { }) ]) }).then(async () => { + if ( + page.url().startsWith('https://www.zhipin.com/web/common/security-check.html') + ) { + await page.waitForNavigation({ + timeout: 0, + }) + } await sleep(2000) const cookies = await page.cookies() + loginEventBus.emit( + 'cookie-collected', + cookies + ) return writeStorageFile('boss-cookies.json', cookies) }).catch((err) => { console.log(err) diff --git a/packages/ui/src/main/flow/LAUNCH_BOSS_ZHIPIN_LOGIN_PAGE_WITH_PRELOAD_EXTENSION.ts b/packages/ui/src/main/flow/LAUNCH_BOSS_ZHIPIN_LOGIN_PAGE_WITH_PRELOAD_EXTENSION.ts index 399919a..6a0d63b 100644 --- a/packages/ui/src/main/flow/LAUNCH_BOSS_ZHIPIN_LOGIN_PAGE_WITH_PRELOAD_EXTENSION.ts +++ b/packages/ui/src/main/flow/LAUNCH_BOSS_ZHIPIN_LOGIN_PAGE_WITH_PRELOAD_EXTENSION.ts @@ -1,6 +1,7 @@ import { app } from 'electron' -import { main } from '@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension' +import { main, loginEventBus } from '@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension' import { pipeWriteRegardlessError } from './utils/pipe' +import fs from "node:fs"; export enum DOWNLOAD_ERROR_EXIT_CODE { NO_ERROR = 0, @@ -37,5 +38,14 @@ export const launchBossZhipinLoginPageWithPreloadExtension = async () => { return } + loginEventBus.once('cookie-collected', (cookies) => { + pipeWriteRegardlessError( + pipe, + JSON.stringify({ + type: 'BOSS_ZHIPIN_COOKIE_COLLECTED', + cookies + }) + '\r\n' + ) + }) main() } diff --git a/packages/ui/src/main/window/mainWindow.ts b/packages/ui/src/main/window/mainWindow.ts index ecb2c9b..acedf2a 100644 --- a/packages/ui/src/main/window/mainWindow.ts +++ b/packages/ui/src/main/window/mainWindow.ts @@ -31,8 +31,8 @@ export function createMainWindow(): void { autoHideMenuBar: true, ...(process.platform === 'linux' ? { - /* icon */ - } + /* icon */ + } : {}), webPreferences: { preload: path.join(__dirname, '../preload/index.js'), @@ -59,6 +59,12 @@ export function createMainWindow(): void { mainWindow.loadFile(path.join(__dirname, '../renderer/index.html')) } + ipcMain.on('open-external-link', (_, link) => { + shell.openExternal(link, { + activate: true + }) + }) + ipcMain.handle('fetch-config-file-content', async () => { const configFileContentList = configFileNameList.map((fileName) => { return readConfigFile(fileName) @@ -210,11 +216,6 @@ export function createMainWindow(): void { mainWindow?.webContents.send('geek-auto-start-chat-with-boss-stopping') subProcessOfPuppeteer?.kill('SIGINT') }) - ipcMain.on('open-project-homepage-on-github', () => { - shell.openExternal(`https://github.com/geekgeekrun`, { - activate: true - }) - }) let subProcessOfBossZhipinLoginPageWithPreloadExtension: ChildProcess | null = null ipcMain.on('launch-bosszhipin-login-page-with-preload-extension', async () => { @@ -234,6 +235,21 @@ export function createMainWindow(): void { stdio: [null, null, null, 'pipe', 'ipc'] } ) + subProcessOfBossZhipinLoginPageWithPreloadExtension!.stdio[3]!.pipe(JSONStream.parse()).on( + 'data', + (raw) => { + const data = raw + switch (data.type) { + case 'BOSS_ZHIPIN_COOKIE_COLLECTED': { + mainWindow?.webContents.send(data.type, data) + break + } + default: { + return + } + } + } + ) subProcessOfBossZhipinLoginPageWithPreloadExtension!.once('exit', () => { subProcessOfBossZhipinLoginPageWithPreloadExtension = null diff --git a/packages/ui/src/renderer/src/features/WaitForLoginDialog/index.vue b/packages/ui/src/renderer/src/features/WaitForLoginDialog/index.vue new file mode 100644 index 0000000..9472945 --- /dev/null +++ b/packages/ui/src/renderer/src/features/WaitForLoginDialog/index.vue @@ -0,0 +1,84 @@ + + + diff --git a/packages/ui/src/renderer/src/features/WaitForLoginDialog/operations.ts b/packages/ui/src/renderer/src/features/WaitForLoginDialog/operations.ts new file mode 100644 index 0000000..73265d3 --- /dev/null +++ b/packages/ui/src/renderer/src/features/WaitForLoginDialog/operations.ts @@ -0,0 +1,37 @@ +import { createApp } from 'vue' +import ElementPlus from 'element-plus' +import WaitForLogin from './index.vue' + +export const mountGlobalDialog = () => { + const containerElId = `elForWaitForLogin` + + if (document.getElementById(containerElId)) { + return + } + let containerEl: null | HTMLElement = (() => { + const el = document.createElement('div') + el.id = containerElId + return el + })() + document.body.append(containerEl) + + const dispose = () => { + app?.unmount() + containerEl?.remove() + + app = null + containerEl = null + } + let app: null | ReturnType = createApp(WaitForLogin, { + modelValue: true, + onClosed() { + dispose() + }, + dispose, + }).use(ElementPlus) + app.mount(containerEl) + + return { + dispose + } +} diff --git a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue index 721e199..f1cc71a 100644 --- a/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue +++ b/packages/ui/src/renderer/src/page/Configuration/GeekAutoStartChatWithBoss.vue @@ -10,10 +10,10 @@
- 您可 - 点击此处打开BOSS直聘登录页,按照稍后的提示,使用EditThisCookie复制Cookie,并进行粘贴 + 如果您不清楚如何操作您可 + 点击此处打开BOSS直聘 Cookie助手来帮您填写。
{ .join(',') } -const launchLogin = () => { - electron.ipcRenderer.send('launch-bosszhipin-login-page-with-preload-extension') +const handleClickLaunchLogin = () => { + mountWaitForLoginDialog() }