-
Notifications
You must be signed in to change notification settings - Fork 4
/
preload.js
69 lines (59 loc) · 1.66 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
const electron = require('electron')
const electronStore = require('electron-store')
const { sockets, setMainWindow } = require('./server')
const { shell } = require('electron')
const https = require('https')
const semver = require('semver')
const updateJsonLink =
'https://chainx-signer-release.oss-cn-hangzhou.aliyuncs.com/update.json'
setMainWindow(electron.remote.getCurrentWindow())
electron.ipcRenderer.on('socketResponse', (event, data) =>
window.wallet.socketResponse(data)
)
window.sockets = sockets
window.wallet = {
// Placeholder function. Will be rewrite in page script.
socketResponse: () => {
console.log('哈哈哈哈哈哈')
}
}
window.require = require
window.ElectronStore = function(...args) {
return new electronStore(...args)
}
window.accountStore = new window.ElectronStore({
name: 'accounts',
defaults: {}
})
window.nodeStore = new window.ElectronStore({ name: 'nodes', defaults: {} })
window.settingStore = new window.ElectronStore({
name: 'settings',
default: {}
})
window.fetchLatestVersion = async function fetchLatestVersion() {
const latestInfo = await new Promise((resolve, reject) => {
https
.get(updateJsonLink, res => {
let body = ''
res.on('data', d => {
body += d
})
res.on('end', function() {
try {
const parsed = JSON.parse(body)
resolve(parsed)
} catch (err) {
reject(err)
}
})
})
.on('error', e => {
reject(e)
})
})
return latestInfo
}
window.versionLte = function versionLte(v1, v2) {
return semver.lte(v1, v2)
}
window.openExternal = url => shell.openExternal(url)