feat: 打开百度事件通信

This commit is contained in:
duanshuwen
2025-10-19 21:04:13 +08:00
parent ac9078aa01
commit 73dabd19ac
4 changed files with 22 additions and 16 deletions

View File

@@ -1,29 +1,31 @@
import { app, BrowserWindow, ipcMain } from "electron";
import path from "node:path";
// import started from "electron-squirrel-startup";
import started from "electron-squirrel-startup";
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
// if (started) {
// app.quit();
// }
if (started) {
app.quit();
}
const inDevelopment = process.env.NODE_ENV === "development";
// const inDevelopment = process.env.NODE_ENV === "development";
const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 900,
height: 670,
autoHideMenuBar: true,
resizable: false, // 禁止拖拽放大缩小
maximizable: false, // 禁止最大化
minimizable: true, // 允许最小化
// autoHideMenuBar: true,
// resizable: false, // 禁止拖拽放大缩小
// maximizable: false, // 禁止最大化
// minimizable: true, // 允许最小化
webPreferences: {
devTools: inDevelopment,
// devTools: inDevelopment,
// nodeIntegration: true,
// contextIsolation: false,
preload: path.join(__dirname, "preload.js"),
},
});
ipcMain.on('open-baidu', () => {
ipcMain.handle('open-baidu', () => {
mainWindow.loadURL("https://www.baidu.com")
})

View File

@@ -0,0 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
openBaidu: () => ipcRenderer.invoke('open-baidu')
});

View File

@@ -13,9 +13,8 @@
</template>
<script setup lang="ts">
const { ipcRenderer } = require("electron")
const openBaidu = async () => {
ipcRenderer.send('open-baidu')
};
const openBaidu = () => {
(window as any).electronAPI?.openBaidu()
}
</script>