feat: update package.json dependencies and enhance webview handling

- Removed the outdated @electron-toolkit/preload dependency and re-added it with the correct version.
- Added a new event listener in WindowService to set the preload script for webviews.
- Updated the openExternal method in preload to handle potential null values.
- Enabled node integration for webviews in the MinApp component for improved functionality.
This commit is contained in:
kangfenmao
2025-03-17 12:38:06 +08:00
parent 1f84f9d744
commit f92c84895d
5 changed files with 12 additions and 3 deletions
+8 -1
View File
@@ -1,5 +1,5 @@
import { is } from '@electron-toolkit/utils'
import { isLinux, isWin } from '@main/constant'
import { isDev, isLinux, isWin } from '@main/constant'
import { getFilesDir } from '@main/utils/file'
import { app, BrowserWindow, ipcMain, Menu, MenuItem, shell } from 'electron'
import Logger from 'electron-log'
@@ -128,6 +128,13 @@ export class WindowService {
this.contextMenu?.popup()
})
// Dangerous API
if (isDev) {
mainWindow.webContents.on('will-attach-webview', (_, webPreferences) => {
webPreferences.preload = join(__dirname, '../preload/index.js')
})
}
// Handle webview context menu
mainWindow.webContents.on('did-attach-webview', (_, webContents) => {
webContents.on('context-menu', () => {