mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-04-25 14:12:43 +08:00
Compare commits
3 Commits
af8aa6cf7c
...
11e9c4bffa
Author | SHA1 | Date | |
---|---|---|---|
|
11e9c4bffa | ||
|
a9952f16c8 | ||
|
8a73559962 |
@ -1,26 +1,27 @@
|
|||||||
import { ipcRenderer, contextBridge } from 'electron'
|
import { ipcRenderer, contextBridge } from 'electron'
|
||||||
|
|
||||||
// --------- Expose some API to the Renderer process ---------
|
// --------- Expose some API to the Renderer process ---------
|
||||||
contextBridge.exposeInMainWorld('ipcRenderer', withPrototype(ipcRenderer))
|
contextBridge.exposeInMainWorld('ipcRenderer', {
|
||||||
|
on(...args: Parameters<typeof ipcRenderer.on>) {
|
||||||
|
const [channel, listener] = args
|
||||||
|
ipcRenderer.on(channel, (event, ...args) => listener(event, ...args))
|
||||||
|
},
|
||||||
|
off(...args: Parameters<typeof ipcRenderer.off>) {
|
||||||
|
const [channel, ...omit] = args
|
||||||
|
ipcRenderer.off(channel, ...omit)
|
||||||
|
},
|
||||||
|
send(...args: Parameters<typeof ipcRenderer.send>) {
|
||||||
|
const [channel, ...omit] = args
|
||||||
|
ipcRenderer.send(channel, ...omit)
|
||||||
|
},
|
||||||
|
invoke(...args: Parameters<typeof ipcRenderer.invoke>) {
|
||||||
|
const [channel, ...omit] = args
|
||||||
|
ipcRenderer.invoke(channel, ...omit)
|
||||||
|
},
|
||||||
|
|
||||||
// `exposeInMainWorld` can't detect attributes and methods of `prototype`, manually patching it.
|
// You can expose other APTs you need here.
|
||||||
function withPrototype(obj: Record<string, any>) {
|
// ...
|
||||||
const protos = Object.getPrototypeOf(obj)
|
})
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(protos)) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, key)) continue
|
|
||||||
|
|
||||||
if (typeof value === 'function') {
|
|
||||||
// Some native APIs, like `NodeJS.EventEmitter['on']`, don't work in the Renderer process. Wrapping them into a function.
|
|
||||||
obj[key] = function (...args: any) {
|
|
||||||
return value.call(obj, ...args)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
obj[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------- Preload scripts loading ---------
|
// --------- Preload scripts loading ---------
|
||||||
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
|
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
|
||||||
|
17
package.json
17
package.json
@ -25,15 +25,14 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^5.0.1",
|
"@vitejs/plugin-vue": "^5.0.4",
|
||||||
"electron": "^28.1.0",
|
"electron": "^29.1.1",
|
||||||
"electron-builder": "^24.9.1",
|
"electron-builder": "^24.13.3",
|
||||||
"tree-kill": "^1.2.2",
|
"typescript": "^5.4.2",
|
||||||
"typescript": "^5.3.3",
|
"vite": "^5.1.5",
|
||||||
"vite": "^5.0.10",
|
"vite-plugin-electron": "^0.28.2",
|
||||||
"vite-plugin-electron": "^0.28.0",
|
|
||||||
"vite-plugin-electron-renderer": "^0.14.5",
|
"vite-plugin-electron-renderer": "^0.14.5",
|
||||||
"vue": "^3.4.1",
|
"vue": "^3.4.21",
|
||||||
"vue-tsc": "^1.8.27"
|
"vue-tsc": "^2.0.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user