This repository has been archived by the owner on Feb 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
main.html
133 lines (100 loc) · 3.81 KB
/
main.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="./node_modules/element-ui/lib/theme-default/index.css" />
<style type="text/css">
body {
width: 100%;
height: 100%;
margin: 0;
}
#buttons {
margin: 8px;
}
#progress {
margin: 8px;
}
</style>
<script type="text/javascript" src="./node_modules/vue/dist/vue.js"></script>
<script type="text/javascript" src="./node_modules/element-ui/lib/index.js"></script>
</head>
<body>
<div id="root">
<div id="buttons">
<el-button :loading="checking" @click="checkForUpdates">Check for updates</el-button>
</div>
<div id="progress" v-if="downloading">
<el-progress :text-inside="true" :stroke-width="18" :percentage="progress"></el-progress>
</div>
</div>
<script type="text/javascript">
const { NsisCompatUpdater } = require('nsis-compat-updater');
document.title = `${ nw.App.manifest.name } - ${ nw.App.manifest.version }`;
const app = new Vue({
el: '#root',
data: function() {
return {
checking: false,
downloading: false,
progress: 0,
};
},
methods: {
checkForUpdates() {
const updater = new NsisCompatUpdater('http://127.0.0.1:8080/versions.nsis.json', nw.App.manifest.version, 'x86');
this.checking = true;
updater.checkForUpdates()
.then((version) => {
this.checking = false;
if(version) {
return this.$confirm(`New version of ${ version.version } is available, download now?`)
.then((confirm) => {
if(confirm) {
this.downloading = true;
this.progress = 0;
const handleDownloadProgress = (state) => {
this.progress = state.percentage || 0;
};
updater.onDownloadProgress.subscribe(handleDownloadProgress);
return updater.downloadUpdate(version.version)
.then((path) => {
updater.onDownloadProgress.unsubscribe(handleDownloadProgress);
this.downloading = false;
this.progress = 0;
return this.$confirm(`New version of ${ version.version } is downloaded, install now?`)
.then((confirm) => {
if(confirm) {
return updater.quitAndInstall(path);
}
else {
this.$message(`Installing cancelled.`);
}
});
})
.catch((err) => {
updater.onDownloadProgress.unsubscribe(handleDownloadProgress);
this.downloading = false;
this.progress = 0;
throw err;
});
}
else {
this.$message(`Downloading cancelled.`);
}
});
}
else {
return this.$alert(`No new version available, the current version is ${ nw.App.manifest.version }.`);
}
})
.catch((err) => {
this.checking = false;
this.$message.error(err.toString());
});
},
},
});
</script>
</body>
</html>