@@ -7,28 +7,36 @@ const url = require('url')
7
7
const fetch = require ( 'node-fetch' )
8
8
const semver = require ( 'semver' )
9
9
10
+ function sendToWebContent ( event ) {
11
+ const win = BrowserWindow . getFocusedWindow ( )
12
+ const webContent = win && win . webContents
13
+ if ( webContent ) {
14
+ webContent . send ( event )
15
+ }
16
+ }
17
+
10
18
module . exports = function ( commandId , args = { } ) {
11
19
switch ( commandId ) {
12
20
case 'createWindow' :
13
21
createWindow ( args )
14
22
break
15
23
case 'refreshWindow' :
16
- BrowserWindow . getFocusedWindow ( ) . webContents . send ( 'web:refresh' )
24
+ sendToWebContent ( 'web:refresh' )
17
25
break
18
26
case 'learnMore' :
19
27
shell . openExternal ( 'https://hackmd.io' )
20
28
break
21
29
case 'goForward' :
22
- BrowserWindow . getFocusedWindow ( ) . webContents . send ( 'web:go-forward' )
30
+ sendToWebContent ( 'web:go-forward' )
23
31
break
24
32
case 'goBack' :
25
- BrowserWindow . getFocusedWindow ( ) . webContents . send ( 'web:go-back' )
33
+ sendToWebContent ( 'web:go-back' )
26
34
break
27
35
case 'configServerUrl' :
28
- BrowserWindow . getFocusedWindow ( ) . webContents . send ( 'config-serverurl' )
36
+ sendToWebContent ( 'config-serverurl' )
29
37
break
30
38
case 'openFromUrl' :
31
- BrowserWindow . getFocusedWindow ( ) . webContents . send ( 'open-from-url' )
39
+ sendToWebContent ( 'open-from-url' )
32
40
break
33
41
case 'checkVersion' :
34
42
return fetch ( url . resolve ( getServerUrl ( ) , '/status' ) ) . then ( response => {
@@ -44,10 +52,10 @@ module.exports = function (commandId, args = {}) {
44
52
}
45
53
} ) . catch ( err => console . log ( err ) )
46
54
case 'copyUrl' :
47
- BrowserWindow . getFocusedWindow ( ) . webContents . send ( 'copy-url' )
55
+ sendToWebContent ( 'copy-url' )
48
56
break
49
57
case 'toggleSearch' :
50
- BrowserWindow . getFocusedWindow ( ) . webContents . send ( 'toggle-search' )
58
+ sendToWebContent ( 'toggle-search' )
51
59
break
52
60
default :
53
61
break
0 commit comments