Skip to content

Commit 4455f7d

Browse files
committed
Improved Updating
1 parent 0a22cb7 commit 4455f7d

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simplelauncher",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "Launcher for SimpleClient",
55
"main": "src/main.js",
66
"scripts": {

src/updater.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const { platform } = require("os")
2-
const { join, resolve } = require("path")
2+
const { join } = require("path")
33
const { getDirectory } = require("./util")
4-
const { execFile, spawnSync } = require("child_process")
4+
const { execFile, spawn } = require("child_process")
55
const { existsSync, mkdirSync, readFileSync } = require("fs")
66
const { path } = require("app-root-path")
7-
const { isMainThread } = require("worker_threads")
7+
const { exit } = require("process")
88

99
const repository = 'FabiPunktExe/SimpleLauncher'
1010

@@ -35,38 +35,21 @@ const checkForUpdates = async () => {
3535
return remoteVersion.length > 0
3636
}
3737

38-
/*if (!isMainThread) {
39-
fetch(`https://api.github.com/repos/${repository}/releases/latest`).then(async response => {
40-
if (response && response.ok) {
41-
const json = await response.json()
42-
const dir = join(getDirectory(), 'updates')
43-
if (!existsSync(dir)) mkdirSync(dir, {recursive: true})
44-
if (platform() == 'win32') {
45-
log('Downloading update...')
46-
spawnSync('curl', ['-L', json.assets[0].browser_download_url, '-o', join(dir, json.assets[0].name)])
47-
log('Successfully downloaded update')
48-
log('Installing update...')
49-
execFile(join(dir, json.assets[0].name), {shell: true}).unref()
50-
exit(0)
51-
}
52-
}
53-
})
54-
}*/
55-
5638
const update = async () => setTimeout(() => fetch(`https://api.github.com/repos/${repository}/releases/latest`).then(async response => {
5739
if (response && response.ok) {
5840
const json = await response.json()
5941
const dir = join(getDirectory(), 'updates')
6042
if (!existsSync(dir)) mkdirSync(dir, {recursive: true})
6143
if (platform() == 'win32') {
6244
log('Downloading update...')
63-
spawnSync('curl', ['-L', json.assets[0].browser_download_url, '-o', join(dir, json.assets[0].name)])
64-
log('Successfully downloaded update')
65-
log('Installing update...')
66-
execFile(join(dir, json.assets[0].name), {shell: true}).unref()
67-
exit(0)
45+
spawn('curl', ['-L', json.assets[0].browser_download_url, '-o', join(dir, json.assets[0].name)]).on('exit', () => {
46+
log('Successfully downloaded update')
47+
log('Installing update...')
48+
execFile(join(dir, json.assets[0].name), {shell: true}).unref()
49+
exit(0)
50+
})
6851
}
6952
}
70-
}))//new Worker(__filename)
53+
}))
7154

7255
module.exports = {checkForUpdates, update}

0 commit comments

Comments
 (0)