mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-08 08:57:24 +08:00
add the entry for manually access boss
This commit is contained in:
@@ -0,0 +1,69 @@
|
|||||||
|
import { initPuppeteer } from '@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs'
|
||||||
|
import extractZip from 'extract-zip'
|
||||||
|
import { readStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||||
|
import { setDomainLocalStorage } from '@geekgeekrun/utils/puppeteer/local-storage.mjs'
|
||||||
|
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import os from 'node:os'
|
||||||
|
import path from 'node:path'
|
||||||
|
import url from 'url'
|
||||||
|
import packageJson from '@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension/package.json' assert { type: 'json' }
|
||||||
|
|
||||||
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||||
|
const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE)
|
||||||
|
|
||||||
|
const runtimeFolderPath = path.join(os.homedir(), '.geekgeekrun')
|
||||||
|
const extensionDir = path.join(runtimeFolderPath, 'chrome-extensions')
|
||||||
|
if (!fs.existsSync(runtimeFolderPath)) {
|
||||||
|
fs.mkdirSync(runtimeFolderPath)
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(extensionDir)) {
|
||||||
|
fs.mkdirSync(extensionDir)
|
||||||
|
}
|
||||||
|
const editThisCookieExtensionPath = path.join(extensionDir, 'EditThisCookie')
|
||||||
|
|
||||||
|
let editThisCookieZipPath
|
||||||
|
async function getEditThisCookieZipPath() {
|
||||||
|
if (editThisCookieZipPath) {
|
||||||
|
return editThisCookieZipPath
|
||||||
|
}
|
||||||
|
if (isRunFromUi) {
|
||||||
|
const { app } = await import('electron')
|
||||||
|
editThisCookieZipPath = path.join(
|
||||||
|
app.getAppPath(),
|
||||||
|
'./node_modules',
|
||||||
|
packageJson.name,
|
||||||
|
'extensions',
|
||||||
|
'EditThisCookie.zip'
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
editThisCookieZipPath = path.join(__dirname, 'extensions', 'EditThisCookie.zip')
|
||||||
|
}
|
||||||
|
return editThisCookieZipPath
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function launchBossSite() {
|
||||||
|
if (!fs.existsSync(path.join(editThisCookieExtensionPath, 'manifest.json'))) {
|
||||||
|
await extractZip(await getEditThisCookieZipPath(), {
|
||||||
|
dir: extensionDir
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const bossCookies = readStorageFile('boss-cookies.json')
|
||||||
|
const bossLocalStorage = readStorageFile('boss-local-storage.json')
|
||||||
|
|
||||||
|
const { puppeteer } = await initPuppeteer()
|
||||||
|
const browser = await puppeteer.launch({
|
||||||
|
headless: false,
|
||||||
|
args: [`--load-extension=${editThisCookieExtensionPath}`]
|
||||||
|
})
|
||||||
|
const [page] = await browser.pages()
|
||||||
|
for (let i = 0; i < bossCookies.length; i++) {
|
||||||
|
await page.setCookie(bossCookies[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
const localStoragePageUrl = `https://www.zhipin.com/desktop/`
|
||||||
|
await setDomainLocalStorage(browser, localStoragePageUrl, bossLocalStorage)
|
||||||
|
|
||||||
|
await page.goto('https://www.zhipin.com/web/user/')
|
||||||
|
}
|
||||||
@@ -265,6 +265,44 @@ export default function initIpc() {
|
|||||||
return a
|
return a
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let subProcessOfOpenBossSite: ChildProcess | undefined
|
||||||
|
let subProcessOfOpenBossSiteLaunching = false
|
||||||
|
ipcMain.handle('open-boss-site', async () => {
|
||||||
|
if (subProcessOfOpenBossSiteLaunching) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
subProcessOfOpenBossSiteLaunching = true
|
||||||
|
const defer = Promise.withResolvers()
|
||||||
|
if (subProcessOfOpenBossSite) {
|
||||||
|
subProcessOfOpenBossSite.once('exit', defer.resolve)
|
||||||
|
subProcessOfOpenBossSite.once('error', console.error)
|
||||||
|
try {
|
||||||
|
process.kill(subProcessOfOpenBossSite.pid!)
|
||||||
|
await sleep(500)
|
||||||
|
process.kill(subProcessOfOpenBossSite.pid!, 'SIGKILL')
|
||||||
|
} catch {
|
||||||
|
defer.resolve(undefined)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defer.resolve(undefined)
|
||||||
|
}
|
||||||
|
defer.promise.then(() => {
|
||||||
|
subProcessOfOpenBossSite = undefined
|
||||||
|
})
|
||||||
|
await defer.promise
|
||||||
|
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
|
||||||
|
const subProcessEnv = {
|
||||||
|
...process.env,
|
||||||
|
MAIN_BOSSGEEKGO_UI_RUN_MODE: 'launchBossSite',
|
||||||
|
PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable!.executablePath
|
||||||
|
}
|
||||||
|
subProcessOfOpenBossSite = childProcess.spawn(process.argv[0], process.argv.slice(1), {
|
||||||
|
env: subProcessEnv,
|
||||||
|
stdio: [null, null, null]
|
||||||
|
})
|
||||||
|
subProcessOfOpenBossSiteLaunching = false
|
||||||
|
})
|
||||||
|
|
||||||
ipcMain.handle('exit-app-immediately', () => {
|
ipcMain.handle('exit-app-immediately', () => {
|
||||||
app.exit(0)
|
app.exit(0)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ const runMode = process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE
|
|||||||
launchBossZhipinLoginPageWithPreloadExtension()
|
launchBossZhipinLoginPageWithPreloadExtension()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case 'launchBossSite': {
|
||||||
|
const { launchBossSite } = await import('./flow/LAUNCH_BOSS_SITE')
|
||||||
|
launchBossSite()
|
||||||
|
break
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
const { openSettingWindow } = await import('./flow/OPEN_SETTING_WINDOW/index')
|
const { openSettingWindow } = await import('./flow/OPEN_SETTING_WINDOW/index')
|
||||||
openSettingWindow()
|
openSettingWindow()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<div class="nav-list flex-1 of-auto">
|
<div class="nav-list flex-1 of-auto">
|
||||||
<RouterLink to="./GeekAutoStartChatWithBoss">Boss炸弹</RouterLink>
|
<RouterLink to="./GeekAutoStartChatWithBoss">Boss炸弹</RouterLink>
|
||||||
<RouterLink to="./StartChatRecord">开聊记录</RouterLink>
|
<RouterLink to="./StartChatRecord">开聊记录</RouterLink>
|
||||||
|
<a href="javascript:void(0)" @click="handleLaunchBossSite">手动逛Boss</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-16px pb-16px flex-0 font-size-12px">
|
<div class="pt-16px pb-16px flex-0 font-size-12px">
|
||||||
<div>当前版本: {{ buildInfo.version }}({{ buildInfo.buildVersion }})</div>
|
<div>当前版本: {{ buildInfo.version }}({{ buildInfo.buildVersion }})</div>
|
||||||
@@ -85,6 +86,10 @@ const handleFeedbackClick = () => {
|
|||||||
const handleGotoProjectPageClick = () => {
|
const handleGotoProjectPageClick = () => {
|
||||||
electron.ipcRenderer.send('open-external-link', 'https://github.com/geekgeekrun/geekgeekrun')
|
electron.ipcRenderer.send('open-external-link', 'https://github.com/geekgeekrun/geekgeekrun')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleLaunchBossSite = async () => {
|
||||||
|
await electron.ipcRenderer.invoke('open-boss-site')
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user