feat: 打开百度事件通信
This commit is contained in:
24
src/main.ts
24
src/main.ts
@@ -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")
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
const { contextBridge, ipcRenderer } = require('electron');
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
openBaidu: () => ipcRenderer.invoke('open-baidu')
|
||||
});
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user