-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathconsumer.js
63 lines (59 loc) · 1.7 KB
/
consumer.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
const {BrowserWindow, shell} = require('electron')
const { createWindow } = require('../window')
const { getServerUrl } = require('../utils')
const url = require('url')
const fetch = require('node-fetch')
const semver = require('semver')
function sendToWebContent (event) {
const win = BrowserWindow.getFocusedWindow()
const webContent = win && win.webContents
if (webContent) {
webContent.send(event)
}
}
module.exports = function (commandId, args = {}) {
switch (commandId) {
case 'createWindow':
createWindow(args)
break
case 'refreshWindow':
sendToWebContent('web:refresh')
break
case 'learnMore':
shell.openExternal('https://hackmd.io')
break
case 'goForward':
sendToWebContent('web:go-forward')
break
case 'goBack':
sendToWebContent('web:go-back')
break
case 'configServerUrl':
sendToWebContent('config-serverurl')
break
case 'openFromUrl':
sendToWebContent('open-from-url')
break
case 'checkVersion':
return fetch(url.resolve(getServerUrl(), '/status')).then(response => {
var browserWindows = BrowserWindow.getAllWindows()
if (!semver.satisfies(response.headers.get('HackMD-Version'), '>= 0.5.1')) {
browserWindows.forEach(browserWindow => {
browserWindow.send('unsupported-version')
})
} else {
browserWindows.forEach(browserWindow => {
browserWindow.send('supported-version')
})
}
}).catch(err => console.log(err))
case 'copyUrl':
sendToWebContent('copy-url')
break
case 'toggleSearch':
sendToWebContent('toggle-search')
break
default:
break
}
}