updater plugin (exe version only)
Massimo Melina committed
Mar 10, 2022 at 18:51 UTC
21a533848919b822c9d825a1ee2e279546530b26
1 file changed
+42
plugins/updater-disabled/plugin.js
new
+42
@@ -0,0 +1,42 @@
1
+/*
2
+this plugin is currently working only with exe version.
3
+Its capability is to offer automatic restart when an update is available in the form of hfs.exe-new file.
4
+ */
5
+const NEW = 'hfs.exe-new'
6
+const BATCH_NAME = 'run-updater.bat'
7
+const BATCH = `@echo off
8
+:loop
9
+setlocal
10
+SET hfs_updater=1
11
+hfs
12
+endlocal
13
+if exist hfs.exe-new (
14
+ move /y hfs.exe hfs.exe-old
15
+ move /y ${NEW} hfs.exe
16
+ goto loop
17
+)
18
+`
19
+
20
+const LOG_PREFIX = "UPDATER:"
21
+
22
+exports.init = async api => {
23
+ const fs = api.require('fs')
24
+ fs.writeFile(BATCH_NAME, BATCH, err =>
25
+ err && console.error(LOG_PREFIX, "could'nt write", BATCH_NAME))
26
+ if (!process.env.hfs_updater)
27
+ return console.log(LOG_PREFIX, "run", BATCH_NAME, "to have restart-on-update")
28
+
29
+ console.log(LOG_PREFIX, "ready")
30
+ const timer = setInterval(() => {
31
+ fs.access(NEW, err => {
32
+ if (err) return
33
+ console.log(LOG_PREFIX, "exiting for update")
34
+ process.exit(0)
35
+ })
36
+ }, 5000)
37
+ return {
38
+ unload() {
39
+ clearInterval(timer)
40
+ }
41
+ }
42
+}