This repository was archived by the owner on Feb 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathpreload-webview.js
More file actions
56 lines (52 loc) · 1.43 KB
/
Copy pathpreload-webview.js
File metadata and controls
56 lines (52 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { ipcRenderer, remote, webFrame } = require('electron')
const { dialog } = remote
const { notify, showOpenDialog } = require('./utils/renderer/electron')
const PluginHost = remote.getGlobal('PluginHost')
const currentWindow = remote.getCurrentWindow()
const { app } = currentWindow.args
const pluginInterface = plugin => {
return {
name: plugin.name,
displayName: plugin.displayName,
type: plugin.type,
api: plugin.api,
stdinWrite: payload => {
return plugin.write(payload)
},
sendRpc: async (method, params) => {
return plugin.rpc(method, params)
},
getState: () => {
return plugin.state
},
execute: command => {
return plugin.execute(command)
},
start: () => {
plugin.requestStart(app)
},
stop: () => {
console.log('app requested stop')
},
on: (eventName, handler) => {
return plugin.on(eventName, handler)
},
off: (eventName, handler) => {
return plugin.removeListener(eventName, handler)
}
}
}
window.grid = {
version: '0.1.0',
getAllPlugins: () => {
return PluginHost.getAllPlugins().map(plugin => pluginInterface(plugin))
},
getPlugin: name => {
const plugin = PluginHost.getAllPlugins().find(p => p.name === name)
return plugin ? pluginInterface(plugin) : plugin
},
// getClient deprecated, for backwards compat
getClient: name => window.grid.getPlugin(name),
notify,
showOpenDialog
}