diff --git a/src/helpers/ipc/context-exposer.ts b/src/helpers/ipc/context-exposer.ts deleted file mode 100644 index 28dcc10..0000000 --- a/src/helpers/ipc/context-exposer.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { exposeThemeContext } from "./theme/theme-context"; -import { exposeWindowContext } from "./window/window-context"; -import { exposeRecordingContext } from "./recording/recording-context"; - -export default function exposeContexts() { - exposeWindowContext(); - exposeThemeContext(); - exposeRecordingContext(); -} diff --git a/src/helpers/ipc/listeners-register.ts b/src/helpers/ipc/listeners-register.ts deleted file mode 100644 index b24d9ca..0000000 --- a/src/helpers/ipc/listeners-register.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { BrowserWindow } from "electron"; -import { addWindowEventListeners } from "./window/window-listeners"; - -export default function registerListeners(mainWindow: BrowserWindow) { - addWindowEventListeners(mainWindow); -} diff --git a/src/helpers/ipc/recording/recording-channels.ts b/src/helpers/ipc/recording/recording-channels.ts deleted file mode 100644 index 6b11e43..0000000 --- a/src/helpers/ipc/recording/recording-channels.ts +++ /dev/null @@ -1,5 +0,0 @@ -// 自动化录制相关的 IPC 通道 - -export const RUN_RECORDING_SCRIPT_CHANNEL = "run-recording-script"; -export const RUN_RECORDING_SCRIPT_SAVE_CHANNEL = "run-recording-script-save"; -export const RUN_RECORDING_SCRIPT_EDIT_CHANNEL = "run-recording-script-edit"; diff --git a/src/helpers/ipc/recording/recording-context.ts b/src/helpers/ipc/recording/recording-context.ts deleted file mode 100644 index 5493d43..0000000 --- a/src/helpers/ipc/recording/recording-context.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - RUN_RECORDING_SCRIPT_CHANNEL, - RUN_RECORDING_SCRIPT_SAVE_CHANNEL, - RUN_RECORDING_SCRIPT_EDIT_CHANNEL, -} from "./recording-channels"; -import { contextBridge, ipcRenderer } from "electron"; - -export function exposeRecordingContext() { - contextBridge.exposeInMainWorld("recording", { - // 运行录制脚本 - runRecordingScript: () => ipcRenderer.invoke(RUN_RECORDING_SCRIPT_CHANNEL), - - // 监听录制脚本输出(保存) - onRecordingSave: (callback: (payload: unknown) => void) => { - ipcRenderer.on(RUN_RECORDING_SCRIPT_SAVE_CHANNEL, (_event, payload) => { - try { - callback(payload); - } catch (err) { - console.error("onRecordingSave callback error:", err); - } - }); - }, - - // 监听录制脚本输出(编辑) - onRecordingEdit: (callback: (payload: unknown) => void) => { - ipcRenderer.on(RUN_RECORDING_SCRIPT_EDIT_CHANNEL, (_event, payload) => { - try { - callback(payload); - } catch (err) { - console.error("onRecordingEdit callback error:", err); - } - }); - }, - }); -} diff --git a/src/helpers/ipc/recording/recording-listeners.ts b/src/helpers/ipc/recording/recording-listeners.ts deleted file mode 100644 index 1f506e6..0000000 --- a/src/helpers/ipc/recording/recording-listeners.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { BrowserWindow, ipcMain, app } from "electron"; -import { spawn } from "child_process"; -import path from "path"; -import { RUN_RECORDING_SCRIPT_CHANNEL } from "./recording-channels"; - -export function addRecordingEventListeners(mainWindow: BrowserWindow) { - // 监听运行录制脚本的请求 - ipcMain.handle(RUN_RECORDING_SCRIPT_CHANNEL, async () => { - try { - console.log('🎬 主进程:开始执行录制脚本'); - - const basePath = app.isPackaged ? process.resourcesPath : app.getAppPath(); - const scriptPath = app.isPackaged - ? path.join(basePath, 'automation', 'recording-automation.js') - : path.join(basePath, 'src', 'automation', 'recording-automation.js'); - - // 启动录制脚本 - const recordingProcess = spawn('node', [scriptPath], { - stdio: ['pipe', 'pipe', 'pipe'], - detached: false - }); - - let stdout = ''; - let stderr = ''; - - // 监听标准输出 - recordingProcess.stdout.on('data', (data) => { - const message = data.toString(); - stdout += message; - console.log('录制脚本输出:', message); - - // 发送输出到渲染进程 - mainWindow.webContents.send(RECORDING_CHANNELS.RECORDING_SCRIPT_RESULT, { - type: 'stdout', - message: message - }); - }); - - // 监听错误输出 - recordingProcess.stderr.on('data', (data) => { - const message = data.toString(); - stderr += message; - console.error('录制脚本错误:', message); - - // 发送错误到渲染进程 - mainWindow.webContents.send(RECORDING_CHANNELS.RECORDING_SCRIPT_ERROR, { - type: 'stderr', - message: message - }); - }); - - // 监听进程退出 - recordingProcess.on('close', (code) => { - console.log(`录制脚本退出,退出码: ${code}`); - - mainWindow.webContents.send(RECORDING_CHANNELS.RECORDING_SCRIPT_RESULT, { - type: 'exit', - code: code, - stdout: stdout, - stderr: stderr - }); - }); - - // 监听进程错误 - recordingProcess.on('error', (error) => { - console.error('录制脚本启动失败:', error); - - mainWindow.webContents.send(RECORDING_CHANNELS.RECORDING_SCRIPT_ERROR, { - type: 'error', - message: error.message - }); - }); - - return { success: true, message: '录制脚本已启动' }; - - } catch (error) { - console.error('执行录制脚本失败:', error); - return { success: false, error: (error as Error).message }; - } - }); -} \ No newline at end of file diff --git a/src/helpers/ipc/theme/theme-channels.ts b/src/helpers/ipc/theme/theme-channels.ts deleted file mode 100644 index a41ad8a..0000000 --- a/src/helpers/ipc/theme/theme-channels.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const THEME_MODE_CURRENT_CHANNEL = "theme-mode:current"; -export const THEME_MODE_TOGGLE_CHANNEL = "theme-mode:toggle"; -export const THEME_MODE_DARK_CHANNEL = "theme-mode:dark"; -export const THEME_MODE_LIGHT_CHANNEL = "theme-mode:light"; -export const THEME_MODE_SYSTEM_CHANNEL = "theme-mode:system"; diff --git a/src/helpers/ipc/theme/theme-context.ts b/src/helpers/ipc/theme/theme-context.ts deleted file mode 100644 index ec0c7e9..0000000 --- a/src/helpers/ipc/theme/theme-context.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { - THEME_MODE_CURRENT_CHANNEL, - THEME_MODE_DARK_CHANNEL, - THEME_MODE_LIGHT_CHANNEL, - THEME_MODE_SYSTEM_CHANNEL, - THEME_MODE_TOGGLE_CHANNEL, -} from "./theme-channels"; -import { contextBridge, ipcRenderer } from "electron"; - -export function exposeThemeContext() { - - contextBridge.exposeInMainWorld("themeMode", { - current: () => ipcRenderer.invoke(THEME_MODE_CURRENT_CHANNEL), - toggle: () => ipcRenderer.invoke(THEME_MODE_TOGGLE_CHANNEL), - dark: () => ipcRenderer.invoke(THEME_MODE_DARK_CHANNEL), - light: () => ipcRenderer.invoke(THEME_MODE_LIGHT_CHANNEL), - system: () => ipcRenderer.invoke(THEME_MODE_SYSTEM_CHANNEL), - }); -} diff --git a/src/helpers/ipc/theme/window-channels.ts b/src/helpers/ipc/theme/window-channels.ts deleted file mode 100644 index 4a2591b..0000000 --- a/src/helpers/ipc/theme/window-channels.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { nativeTheme } from "electron"; -import { ipcMain } from "electron"; -import { - THEME_MODE_CURRENT_CHANNEL, - THEME_MODE_DARK_CHANNEL, - THEME_MODE_LIGHT_CHANNEL, - THEME_MODE_SYSTEM_CHANNEL, - THEME_MODE_TOGGLE_CHANNEL, -} from "./theme-channels"; - -export function addThemeEventListeners() { - ipcMain.handle(THEME_MODE_CURRENT_CHANNEL, () => nativeTheme.themeSource); - - ipcMain.handle(THEME_MODE_TOGGLE_CHANNEL, () => { - if (nativeTheme.shouldUseDarkColors) { - nativeTheme.themeSource = "light"; - } else { - nativeTheme.themeSource = "dark"; - } - return nativeTheme.shouldUseDarkColors; - }); - - ipcMain.handle( - THEME_MODE_DARK_CHANNEL, - () => (nativeTheme.themeSource = "dark") - ); - - ipcMain.handle( - THEME_MODE_LIGHT_CHANNEL, - () => (nativeTheme.themeSource = "light") - ); - - ipcMain.handle(THEME_MODE_SYSTEM_CHANNEL, () => { - nativeTheme.themeSource = "system"; - return nativeTheme.shouldUseDarkColors; - }); -} diff --git a/src/helpers/ipc/window/window-channels.ts b/src/helpers/ipc/window/window-channels.ts deleted file mode 100644 index 3760008..0000000 --- a/src/helpers/ipc/window/window-channels.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const WIN_MINIMIZE_CHANNEL = "window:minimize"; -export const WIN_MAXIMIZE_CHANNEL = "window:maximize"; -export const WIN_CLOSE_CHANNEL = "window:close"; diff --git a/src/helpers/ipc/window/window-context.ts b/src/helpers/ipc/window/window-context.ts deleted file mode 100644 index c1cdba3..0000000 --- a/src/helpers/ipc/window/window-context.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { - WIN_MINIMIZE_CHANNEL, - WIN_MAXIMIZE_CHANNEL, - WIN_CLOSE_CHANNEL -} from "./window-channels"; -import { contextBridge, ipcRenderer } from "electron"; - -export function exposeWindowContext() { - contextBridge.exposeInMainWorld("electronWindow", { - minimize: () => ipcRenderer.invoke(WIN_MINIMIZE_CHANNEL), - maximize: () => ipcRenderer.invoke(WIN_MAXIMIZE_CHANNEL), - close: () => ipcRenderer.invoke(WIN_CLOSE_CHANNEL) - }); -} diff --git a/src/helpers/ipc/window/window-listeners.ts b/src/helpers/ipc/window/window-listeners.ts deleted file mode 100644 index 76086b3..0000000 --- a/src/helpers/ipc/window/window-listeners.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { BrowserWindow, ipcMain } from "electron"; -import { - WIN_CLOSE_CHANNEL, - WIN_MAXIMIZE_CHANNEL, - WIN_MINIMIZE_CHANNEL -} from "./window-channels"; - -export function addWindowEventListeners(mainWindow: BrowserWindow) { - ipcMain.handle(WIN_MINIMIZE_CHANNEL, () => { - mainWindow.minimize(); - }); - - ipcMain.handle(WIN_MAXIMIZE_CHANNEL, () => { - if (mainWindow.isMaximized()) { - mainWindow.unmaximize(); - } else { - mainWindow.maximize(); - } - }); - - ipcMain.handle(WIN_CLOSE_CHANNEL, () => { - mainWindow.close(); - }); -} diff --git a/src/helpers/language_helper.ts b/src/helpers/language_helper.ts deleted file mode 100644 index 2d47a5e..0000000 --- a/src/helpers/language_helper.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { i18n } from "i18next"; - -const languageLocalStorageKey = "lang"; - -export function setAppLanguage(lang: string, i18n: i18n) { - localStorage.setItem(languageLocalStorageKey, lang); - i18n.changeLanguage(lang); - document.documentElement.lang = lang; -} - -export function updateAppLanguage(i18n: i18n) { - const localLang = localStorage.getItem(languageLocalStorageKey); - if (!localLang) { - return; - } - - i18n.changeLanguage(localLang); - document.documentElement.lang = localLang; -} diff --git a/src/helpers/theme_helpers.ts b/src/helpers/theme_helpers.ts deleted file mode 100644 index afbe325..0000000 --- a/src/helpers/theme_helpers.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { ThemeMode } from "@types/theme-mode"; - -const THEME_KEY = "theme"; - -export interface ThemePreferences { - system: ThemeMode; - local: ThemeMode | null; -} - -export async function getCurrentTheme(): Promise { - const currentTheme = await window.themeMode.current(); - const localTheme = localStorage.getItem(THEME_KEY) as ThemeMode | null; - - return { - system: currentTheme, - local: localTheme, - }; -} - -export async function setTheme(newTheme: ThemeMode) { - switch (newTheme) { - case "dark": - await window.themeMode.dark(); - updateDocumentTheme(true); - break; - case "light": - await window.themeMode.light(); - updateDocumentTheme(false); - break; - case "system": { - const isDarkMode = await window.themeMode.system(); - updateDocumentTheme(isDarkMode); - break; - } - } - - localStorage.setItem(THEME_KEY, newTheme); -} - - - - -export async function syncThemeWithLocal() { - const { local } = await getCurrentTheme(); - if (!local) { - setTheme("system"); - return; - } - - await setTheme(local); -} - -function updateDocumentTheme(isDarkMode: boolean) { - if (!isDarkMode) { - document.documentElement.classList.remove("dark"); - } else { - document.documentElement.classList.add("dark"); - } -} diff --git a/src/helpers/window_helpers.ts b/src/helpers/window_helpers.ts deleted file mode 100644 index 1b25c18..0000000 --- a/src/helpers/window_helpers.ts +++ /dev/null @@ -1,11 +0,0 @@ -export async function minimizeWindow() { - await window.electronWindow.minimize(); -} - -export async function maximizeWindow() { - await window.electronWindow.maximize(); -} - -export async function closeWindow() { - await window.electronWindow.close(); -} diff --git a/src/main.ts b/src/main.ts index 3d896de..c498ea8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,4 @@ -import { app, BrowserWindow } from "electron"; -import registerListeners from "./helpers/ipc/listeners-register"; +import { app, BrowserWindow, ipcMain } from "electron"; import path from "node:path"; // import started from "electron-squirrel-startup"; @@ -24,8 +23,9 @@ const createWindow = () => { }, }); - // 注册 IPC 事件监听器(包括录制功能) - registerListeners(mainWindow); + ipcMain.on('open-baidu', () => { + mainWindow.loadURL("https://www.baidu.com") + }) // and load the index.html of the app. if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { diff --git a/src/preload.ts b/src/preload.ts index 78d0e3c..e69de29 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -1,3 +0,0 @@ -import exposeContexts from "./helpers/ipc/context-exposer"; - -exposeContexts(); diff --git a/src/types.d.ts b/src/types.d.ts deleted file mode 100644 index cdd3d9d..0000000 --- a/src/types.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Vite -// plugin that tells the Electron app where to look for the Vite-bundled app code (depending on -// whether you're running in development or production). - -// Preload types -interface ThemeModeContext { - toggle: () => Promise; - dark: () => Promise; - light: () => Promise; - system: () => Promise; - current: () => Promise<"dark" | "light" | "system">; -} - -interface ElectronWindow { - minimize: () => Promise; - maximize: () => Promise; - close: () => Promise; -} - -interface RecordingContext { - runRecordingScript: () => Promise; - onRecordingSave: (callback: (payload: unknown) => void) => void; - onRecordingEdit: (callback: (payload: unknown) => void) => void; -} - -declare interface Window { - themeMode: ThemeModeContext; - electronWindow: ElectronWindow; - recording: RecordingContext; -} diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 49d1e18..258a58b 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -4,6 +4,7 @@
@@ -12,5 +13,9 @@