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 { app, BrowserWindow, ipcMain } from "electron";
|
||||||
import path from "node:path";
|
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.
|
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
||||||
// if (started) {
|
if (started) {
|
||||||
// app.quit();
|
app.quit();
|
||||||
// }
|
}
|
||||||
|
|
||||||
const inDevelopment = process.env.NODE_ENV === "development";
|
// const inDevelopment = process.env.NODE_ENV === "development";
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
width: 900,
|
width: 900,
|
||||||
height: 670,
|
height: 670,
|
||||||
autoHideMenuBar: true,
|
// autoHideMenuBar: true,
|
||||||
resizable: false, // 禁止拖拽放大缩小
|
// resizable: false, // 禁止拖拽放大缩小
|
||||||
maximizable: false, // 禁止最大化
|
// maximizable: false, // 禁止最大化
|
||||||
minimizable: true, // 允许最小化
|
// minimizable: true, // 允许最小化
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
devTools: inDevelopment,
|
// devTools: inDevelopment,
|
||||||
|
// nodeIntegration: true,
|
||||||
|
// contextIsolation: false,
|
||||||
preload: path.join(__dirname, "preload.js"),
|
preload: path.join(__dirname, "preload.js"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('open-baidu', () => {
|
ipcMain.handle('open-baidu', () => {
|
||||||
mainWindow.loadURL("https://www.baidu.com")
|
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>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { ipcRenderer } = require("electron")
|
const openBaidu = () => {
|
||||||
const openBaidu = async () => {
|
(window as any).electronAPI?.openBaidu()
|
||||||
ipcRenderer.send('open-baidu')
|
}
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user