diff --git a/README.md b/README.md index 04d2ab1..b92271f 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,20 @@ ipcMain.handle('get-data', () => { └─────────────────────────────────────────────────────────┘ ``` +``` + ┌─────────────┬─────────────────────────────────────────┐ + │ 旧文件 │ → 新文件 │ + ├─────────────┼─────────────────────────────────────────┤ + │ main.js │ src/main/index.ts │ + ├─────────────┼─────────────────────────────────────────┤ + │ preload.js │ src/preload/index.ts │ + ├─────────────┼─────────────────────────────────────────┤ + │ index.html │ src/renderer/index.html │ + ├─────────────┼─────────────────────────────────────────┤ + │ renderer.js │ src/renderer/src/components/Counter.vue │ + └─────────────┴─────────────────────────────────────────┘ +``` + electron-vite 自动处理: - 主进程和预加载脚本的 CommonJS/ESM 兼容 - 渲染进程的热模块替换 (HMR) diff --git a/index.html b/index.html deleted file mode 100644 index 06a7e59..0000000 --- a/index.html +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - 实时计数器 - - - -
-

实时计数器

-
0
-
- 运行中 -
-
- - - \ No newline at end of file diff --git a/main.js b/main.js deleted file mode 100644 index aa82437..0000000 --- a/main.js +++ /dev/null @@ -1,34 +0,0 @@ -const { app, BrowserWindow } = require('electron'); -const path = require('path'); - -let win; - -function createWindow() { - win = new BrowserWindow({ - width: 500, - height: 400, - webPreferences: { - nodeIntegration: false, - contextIsolation: true, - preload: path.join(__dirname, 'preload.js') - } - }); - - win.loadFile('index.html'); - // 打开开发者工具方便调试 - // win.webContents.openDevTools(); -} - -app.whenReady().then(createWindow); - -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit(); - } -}); - -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow(); - } -}); \ No newline at end of file diff --git a/preload.js b/preload.js deleted file mode 100644 index fa7eed2..0000000 --- a/preload.js +++ /dev/null @@ -1,7 +0,0 @@ -const { contextBridge, ipcRenderer } = require('electron'); - -// 暴露安全的 API 给渲染进程 -contextBridge.exposeInMainWorld('electronAPI', { - // 可扩展更多功能 - platform: process.platform -}); \ No newline at end of file diff --git a/renderer.js b/renderer.js deleted file mode 100644 index 24fac08..0000000 --- a/renderer.js +++ /dev/null @@ -1,16 +0,0 @@ -// 死循环计数器,每秒增加并刷新 UI -let count = 0; -const counterElement = document.getElementById('counter'); - -function updateCounter() { - count++; - counterElement.textContent = count.toLocaleString(); - - // 立即安排下一次更新 - setTimeout(updateCounter, 1000); -} - -// 启动计数器 -updateCounter(); - -console.log('计数器已启动'); \ No newline at end of file