1
1
const { shell, dialog, app} = require ( 'electron' ) ;
2
2
const util = require ( './common/app-util' ) ;
3
3
const https = require ( 'https' ) ;
4
- const jsdom = require ( 'jsdom' ) ;
5
4
const appToast = require ( './common/app-toast' ) ;
6
5
7
- const url = require ( './common/app-link' ) . url ;
8
-
9
- const versionPrefix = require ( './common/app-link' ) . versionPrefix ;
6
+ const url = require ( './common/app-link' ) . package ;
10
7
11
8
// 自动检查更新(bool:是否主动操作)
12
9
function autoUpdateApp ( isTip ) {
@@ -21,19 +18,17 @@ function autoUpdateApp(isTip) {
21
18
} ) ;
22
19
req . on ( 'error' , ( e ) => {
23
20
console . error ( e ) ;
24
- dialog . showMessageBoxSync ( { message : '网络连接异常' } )
21
+ if ( isTip ) {
22
+ dialog . showMessageBoxSync ( { message : '网络链接异常' } )
23
+ }
25
24
} ) ;
26
25
req . end ( ) ;
27
26
}
28
27
29
- exports . autoUpdateApp = autoUpdateApp ;
30
-
31
28
//解析html获取内容
32
29
function parseHtml ( result , isTip ) {
33
- const dom = new jsdom . JSDOM ( result ) ;
34
- const startIndex = dom . window . document . body . innerHTML . indexOf ( versionPrefix ) ;
35
- const endIndex = dom . window . document . body . innerHTML . indexOf ( '"' , startIndex ) ;
36
- const version = dom . window . document . body . innerHTML . substring ( startIndex + versionPrefix . length , endIndex ) ;
30
+ const packageJson = JSON . parse ( result ) ;
31
+ const version = packageJson . version ;
37
32
38
33
if ( ! version ) {
39
34
if ( isTip ) {
@@ -71,4 +66,6 @@ function parseHtml(result, isTip) {
71
66
autoUpdateApp ( false )
72
67
} , 1000 * 60 * 60 )
73
68
}
74
- }
69
+ }
70
+
71
+ exports . autoUpdateApp = autoUpdateApp ;
0 commit comments