mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-12 02:19:55 +08:00
add browser auto find logic to first run
This commit is contained in:
@@ -4,9 +4,9 @@ import {
|
||||
browserAssistantWindow
|
||||
} from '../window/browserAssistantWindow'
|
||||
|
||||
export async function configWithBrowserAssistant({ windowOption } = {}) {
|
||||
export async function configWithBrowserAssistant({ windowOption, autoFind } = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
createBrowserAssistantWindow({ ...windowOption })
|
||||
createBrowserAssistantWindow({ ...windowOption }, { autoFind })
|
||||
|
||||
let processDone = false
|
||||
function handler() {
|
||||
|
||||
@@ -3,6 +3,11 @@ import os from 'os'
|
||||
import path from 'path'
|
||||
import buildInfo from '../../common/build-info.json'
|
||||
import { ensureStorageFileExist } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||
import {
|
||||
createFirstLaunchNoticeWindow,
|
||||
firstLaunchNoticeWindow
|
||||
} from '../window/firstLaunchNoticeWindow'
|
||||
import { ipcMain } from 'electron'
|
||||
|
||||
export const firstLaunchNoticeApproveFlagPath = path.join(
|
||||
os.homedir(),
|
||||
@@ -10,8 +15,28 @@ export const firstLaunchNoticeApproveFlagPath = path.join(
|
||||
'ui-first-launch-notice-flag'
|
||||
)
|
||||
|
||||
export const isFirstLaunchNoticeApproveFlagExist = () => fs.existsSync(firstLaunchNoticeApproveFlagPath)
|
||||
export const isFirstLaunchNoticeApproveFlagExist = () =>
|
||||
fs.existsSync(firstLaunchNoticeApproveFlagPath)
|
||||
export const createFirstLaunchNoticeApproveFlag = () => {
|
||||
ensureStorageFileExist()
|
||||
fs.writeFileSync(firstLaunchNoticeApproveFlagPath, buildInfo.version)
|
||||
}
|
||||
export async function waitForUserApproveAgreement({ windowOption } = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
createFirstLaunchNoticeWindow({ ...windowOption })
|
||||
let processDone = false
|
||||
function handler() {
|
||||
processDone = true
|
||||
firstLaunchNoticeWindow.close()
|
||||
}
|
||||
ipcMain.once('first-launch-notice-approve', handler)
|
||||
firstLaunchNoticeWindow.once('closed', () => {
|
||||
ipcMain.off('first-launch-notice-approve', handler)
|
||||
if (processDone) {
|
||||
resolve(true)
|
||||
} else {
|
||||
reject(new Error('USER_CANCELLED'))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ const registerHandleWithWindow = (
|
||||
}
|
||||
|
||||
export function createBrowserAssistantWindow(
|
||||
opt?: Electron.BrowserWindowConstructorOptions
|
||||
opt?: Electron.BrowserWindowConstructorOptions,
|
||||
{ autoFind } = {}
|
||||
): BrowserWindow {
|
||||
// Create the browser window.
|
||||
if (browserAssistantWindow) {
|
||||
@@ -45,11 +46,15 @@ export function createBrowserAssistantWindow(
|
||||
|
||||
// HMR for renderer base on electron-vite cli.
|
||||
// Load the remote URL for development or the local html file for production.
|
||||
let routePath = '#/browserAssistant'
|
||||
if (autoFind) {
|
||||
routePath = '#/browserAutoFind'
|
||||
}
|
||||
if (process.env.NODE_ENV === 'development' && process.env['ELECTRON_RENDERER_URL']) {
|
||||
browserAssistantWindow.loadURL(process.env['ELECTRON_RENDERER_URL'] + '#/browserAssistant')
|
||||
browserAssistantWindow.loadURL(process.env['ELECTRON_RENDERER_URL'] + routePath)
|
||||
} else {
|
||||
browserAssistantWindow.loadURL(
|
||||
'file://' + path.join(__dirname, '../renderer/index.html') + '#/browserAssistant'
|
||||
'file://' + path.join(__dirname, '../renderer/index.html') + routePath
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { BrowserWindow, ipcMain } from 'electron'
|
||||
import { BrowserWindow } from 'electron'
|
||||
import path from 'path'
|
||||
import { createFirstLaunchNoticeApproveFlag } from '../features/first-launch-notice-window'
|
||||
|
||||
export let firstLaunchNoticeWindow: BrowserWindow | null = null
|
||||
export function createFirstLaunchNoticeWindow(
|
||||
@@ -41,11 +40,3 @@ export function createFirstLaunchNoticeWindow(
|
||||
|
||||
return firstLaunchNoticeWindow!
|
||||
}
|
||||
|
||||
export const initIpc = () => {
|
||||
ipcMain.handle('first-launch-notice-approve', () => {
|
||||
createFirstLaunchNoticeApproveFlag()
|
||||
firstLaunchNoticeWindow?.close()
|
||||
})
|
||||
}
|
||||
initIpc()
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { BrowserWindow, shell } from 'electron'
|
||||
import { app, BrowserWindow, shell } from 'electron'
|
||||
import path from 'path'
|
||||
import { openDevTools } from '../commands'
|
||||
import { createFirstLaunchNoticeWindow } from './firstLaunchNoticeWindow'
|
||||
import { isFirstLaunchNoticeApproveFlagExist } from '../features/first-launch-notice-window'
|
||||
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 {
|
||||
@@ -29,12 +34,34 @@ export function createMainWindow(): BrowserWindow {
|
||||
mainWindow.show()
|
||||
})
|
||||
mainWindow.on('ready-to-show', async () => {
|
||||
!isFirstLaunchNoticeApproveFlagExist() &&
|
||||
createFirstLaunchNoticeWindow({
|
||||
parent: mainWindow!,
|
||||
modal: true,
|
||||
show: true
|
||||
})
|
||||
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' &&
|
||||
|
||||
@@ -50,11 +50,14 @@
|
||||
@click="autoDetectPuppeteerExecutable"
|
||||
>自动检测</a
|
||||
>按钮再次尝试。目前(2026.2.7)已知 Chrome 最新版本为 144.0.7559.133
|
||||
,多数情况下本程序都可以正常工作,但由于浏览器会自动升级,版本不固定,可能存在<span color-orange
|
||||
,多数情况下本程序都可以正常工作,但由于浏览器会自动升级,版本不固定,可能存在<span
|
||||
color-orange
|
||||
>浏览器升级后某些功能不兼容导致本程序不能正确运行</span
|
||||
>的问题。您可以<a href="javascript:;" @click="handleFeedbackClick"
|
||||
>的问题。如果您确实遇到不能正常运行的问题,请<a
|
||||
href="javascript:;"
|
||||
@click="handleFeedbackClick"
|
||||
>提交 Issue</a
|
||||
>来反馈新版本浏览器不能正常运行的问题,同时请再尝试方案一。
|
||||
>来反馈,同时请再尝试方案一。
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -202,7 +205,9 @@ const handleFeedbackClick = () => {
|
||||
}
|
||||
const handleClickLaunchBrowserDownloader = async () => {
|
||||
gtagRenderer('launch_browser_downloader_clicked')
|
||||
const downloadedBrowserPath = await electron.ipcRenderer.invoke('download-browser-with-downloader')
|
||||
const downloadedBrowserPath = await electron.ipcRenderer.invoke(
|
||||
'download-browser-with-downloader'
|
||||
)
|
||||
if (downloadedBrowserPath) {
|
||||
formData.value.browserPath = downloadedBrowserPath
|
||||
ElMessage({
|
||||
|
||||
58
packages/ui/src/renderer/src/page/BrowserAutoFind/index.vue
Normal file
58
packages/ui/src/renderer/src/page/BrowserAutoFind/index.vue
Normal file
@@ -0,0 +1,58 @@
|
||||
<template>
|
||||
<div class="h-screen of-hidden flex flex-col flex-items-center flex-justify-center">
|
||||
<div>
|
||||
<div>你可能是第一次安装本程序</div>
|
||||
<div>正在查找可用浏览器,请稍等...</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { gtagRenderer as baseGtagRenderer } from '@renderer/utils/gtag'
|
||||
|
||||
const { ipcRenderer } = electron
|
||||
const router = useRouter()
|
||||
// const checkDependenciesResult = ref({})
|
||||
// const downloadProcessWaitee = ref(null)
|
||||
|
||||
const gtagRenderer = (name, params?: object) => {
|
||||
return baseGtagRenderer(name, {
|
||||
scene: 'browser-auto-find',
|
||||
...params
|
||||
})
|
||||
}
|
||||
|
||||
async function autoDetectPuppeteerExecutable() {
|
||||
const result = await ipcRenderer.invoke('get-any-available-puppeteer-executable')
|
||||
if (!result) {
|
||||
gtagRenderer('first-run-auto-detect-pptr-exe-fail')
|
||||
ElMessage({
|
||||
message: '未找到可用浏览器的可执行文件,请尝试手动配置',
|
||||
type: 'warning',
|
||||
grouping: true
|
||||
})
|
||||
router.replace({
|
||||
path: '/browserAssistant',
|
||||
query: {
|
||||
firstRun: 1
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
gtagRenderer('first-run-auto-detect-pptr-exe-success')
|
||||
await ipcRenderer.send('browser-config-saved')
|
||||
}
|
||||
|
||||
autoDetectPuppeteerExecutable()
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
a:link,
|
||||
a:visited,
|
||||
a:hover,
|
||||
a:active {
|
||||
color: #409eff;
|
||||
}
|
||||
</style>
|
||||
@@ -129,7 +129,7 @@ const readmeItemCheckStatusList = ref<number[]>([])
|
||||
const handleCancel = async () => {
|
||||
gtagRenderer('cancel_clicked')
|
||||
await sleep(500)
|
||||
electron.ipcRenderer.invoke('exit-app-immediately')
|
||||
window.close()
|
||||
}
|
||||
|
||||
const unreadItemsAfterClickSubmit = ref<Record<number, true>>({})
|
||||
@@ -150,7 +150,7 @@ const handleSubmit = () => {
|
||||
}
|
||||
return
|
||||
}
|
||||
electron.ipcRenderer.invoke('first-launch-notice-approve')
|
||||
electron.ipcRenderer.send('first-launch-notice-approve')
|
||||
gtagRenderer('submit_done')
|
||||
}
|
||||
const handleReadmeItemCheckStatusListChange = (value: number[]) => {
|
||||
|
||||
@@ -24,6 +24,13 @@ const routes: Array<RouteRecordRaw> = [
|
||||
title: '浏览器助手'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/browserAutoFind',
|
||||
component: () => import('@renderer/page/BrowserAutoFind/index.vue'),
|
||||
meta: {
|
||||
title: '浏览器助手 - 自动查找浏览器'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/browserDownloadProgress',
|
||||
component: () => import('@renderer/page/BrowserDownloadProgress/index.vue'),
|
||||
|
||||
Reference in New Issue
Block a user