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 37
/
Copy pathpreload.js
159 lines (147 loc) · 3.57 KB
/
preload.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const { ipcRenderer, remote, webFrame } = require('electron')
const { shell } = remote
const {
getLaunchOnBoot,
hideWindow,
notify,
openExternalLink,
setLaunchOnBoot,
showOpenDialog
} = require('./utils/renderer/electron')
const { resolveRuntimeDependency } = require('./utils/main/util')
// Enabling spectron integration https://github.com/electron/spectron#node-integration
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') {
window.electronRequire = require
}
const openCache = clientName => {
try {
const PluginHost = remote.getGlobal('PluginHost')
const client = PluginHost.getPluginByName(clientName)
if (!client) {
return
}
shell.openItem(client.cacheDir)
} catch (error) {
console.log('error', error)
}
}
// const rpc = require('./Rpc')
// const thisWin = remote.getCurrentWindow()
// see contextIsolation for more info:
// pass the initial data to the isolated window context and de-serialize it:
/*
webFrame.executeJavaScript(`
window.data = ${thisWin.data}
try {
// window.data = JSON.parse(window.data)
} catch (error) {
console.error(error)
}
`)
ipcRenderer.on('__update', async (event, data) => {
let dataString = JSON.stringify(data)
let result = await webFrame.executeJavaScript(`
try {
window.dispatchEvent(new CustomEvent('update', {detail: ${dataString} }));
} catch (error) {
console.error(error)
}
`)
})
*/
// https://developer.chrome.com/extensions/content_scripts#host-page-communication
/*
window.addEventListener('message', function(event) {
console.log('received event', event)
// We only accept messages from ourselves
if (event.source != window)
return;
if (event.data.type && (event.data.type == "FROM_PAGE")) {
console.log("Content script received: " + event.data.text);
}
}, false);
*/
console.log('grid preload script loaded')
const currentWindow = remote.getCurrentWindow()
const Grid = {
PluginHost: remote.getGlobal('PluginHost'),
AppManager: remote.getGlobal('AppManager'),
Config: remote.getGlobal('UserConfig'),
window: {
getArgs: () => currentWindow.args,
close: () => {
currentWindow.close()
},
maximize: () => {
currentWindow.maximize()
},
minimize: () => {
currentWindow.minimize()
},
restore: () => {
currentWindow.restore()
},
unmaximize: () => {
currentWindow.unmaximize()
},
hasFrame: () => {
currentWindow.hasFrame
}
},
platform: {
name: process.platform,
hasRuntime: dependency => {
const result = resolveRuntimeDependency(dependency) !== undefined
return result
}
},
notify,
showOpenDialog,
openExternalLink,
getLaunchOnBoot,
hideWindow,
setLaunchOnBoot,
openCache
}
/*
const Geth = {
checkForUpdates: async () => {
return rpc.send("geth.checkForUpdates")
},
setConfig: async config => {
return rpc.send("geth.setConfig", config)
},
getConfig: async () => {
return rpc.send("geth.getConfig")
},
getStatus: async () => {
return rpc.send("geth.getStatus")
},
getReleases: async () => {
return rpc.send("geth.getReleases")
},
start: async () => {
return rpc.send("geth.start")
},
stop: async () => {
return rpc.send("geth.stop")
},
version: async () => {
return rpc.send("geth.version")
},
rpc: async (call) => {
return rpc.send("geth.rpc", call)
}
}
const Mist = {
geth: Geth
}
*/
window.Mist = Grid
window.Grid = Grid
/*
webFrame.executeJavaScript(`window.Mist = {geth: {
getStatus: () => {return{}},
getConfig: () => {return{}}
}}`)
*/