@quiteer/electron-preload
基于electron , 提供预加载功能脚本
安装
npm i @quiteer/electron-preload
yarn add @quiteer/electron-preload
pnpm add @quiteer/electron-preload
使用
在主进程中引入预加载脚本
import preload from '@quiteer/electron-preload'
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
sandbox: false,
preload
}
})
暴露的api
分别暴露了以下api , 具体使用方法可参照官方 api 文档使用
-
ipcRenderer
- send
- sendSync
- invoke
- on
- once
- removeAllListeners
-
clipboard
- readText
- writeText
- readHTML
- writeHTML
- readImage
- writeImage
- readRTF
- writeRTF
- readBookmark
- writeBookmark
- readFindText
- writeFindText
- clear
- availableFormats
- has
- read
- readBuffer
- writeBuffer
- write
-
webFrame
- setZoomFactor
- getZoomFactor
- setZoomLevel
- getZoomLevel
- insertText
- executeJavaScript
- executeJavaScriptInIsolatedWorld
- setIsolatedWorldInfo
- getResourceUsage
- clearCache
- getFrameForSelector
- firstChild
- nextSibling
- opener
- parent
- routingId
- top
-
nodejs 的 path 模块部分 api
- basename
- dirname
- extname
- join
- parse
- relative
- resolve
渲染进程中使用
console.log('window.$ipc :>> ', window.$ipc)
console.log('window.$path :>> ', window.$path)
console.log('window.$clipboard :>> ', window.$clipboard)
console.log('window.$webFrame :>> ', window.$webFrame)
获取类型提示
全局类型声明
interface Window {
$ipc: import('@quiteer/electron-preload').PreloadIpc
$clipboard: import('@quiteer/electron-preload').PreLoadPath
$webFrame: import('@quiteer/electron-preload').PreloadWebFrame
$path: import('@quiteer/electron-preload').PreLoadPath
}