mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-04-25 22:16:59 +08:00
Compare commits
No commits in common. "11e9c4bffaa698a210186ce22f5579f9a930fe21" and "af8aa6cf7c3bc65fa14ae53b0fa31094f0c9f5ea" have entirely different histories.
11e9c4bffa
...
af8aa6cf7c
@ -1,27 +1,26 @@
|
|||||||
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', {
|
contextBridge.exposeInMainWorld('ipcRenderer', withPrototype(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)
|
|
||||||
},
|
|
||||||
|
|
||||||
// You can expose other APTs you need here.
|
// `exposeInMainWorld` can't detect attributes and methods of `prototype`, manually patching it.
|
||||||
// ...
|
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,14 +25,15 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^5.0.4",
|
"@vitejs/plugin-vue": "^5.0.1",
|
||||||
"electron": "^29.1.1",
|
"electron": "^28.1.0",
|
||||||
"electron-builder": "^24.13.3",
|
"electron-builder": "^24.9.1",
|
||||||
"typescript": "^5.4.2",
|
"tree-kill": "^1.2.2",
|
||||||
"vite": "^5.1.5",
|
"typescript": "^5.3.3",
|
||||||
"vite-plugin-electron": "^0.28.2",
|
"vite": "^5.0.10",
|
||||||
|
"vite-plugin-electron": "^0.28.0",
|
||||||
"vite-plugin-electron-renderer": "^0.14.5",
|
"vite-plugin-electron-renderer": "^0.14.5",
|
||||||
"vue": "^3.4.21",
|
"vue": "^3.4.1",
|
||||||
"vue-tsc": "^2.0.6"
|
"vue-tsc": "^1.8.27"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user