Skip to content

Commit 0a22cb7

Browse files
committed
Thread Fix?
1 parent 4657725 commit 0a22cb7

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
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.2",
3+
"version": "0.3.3",
44
"description": "Launcher for SimpleClient",
55
"main": "src/main.js",
66
"scripts": {

src/launch.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const { resolve, join } = require('path')
2-
const { Worker, workerData } = require('worker_threads')
3-
const { isMainThread, parentPort } = require('worker_threads')
2+
const { Worker } = require('worker_threads')
3+
const { isMainThread, workerData } = require('worker_threads')
44

5-
if (!isMainThread) require('./minecraft').launch(workerData.version, workerData.account, status => parentPort.postMessage(status))
5+
//if (!isMainThread) require('./minecraft').launch(workerData.version, workerData.account, status => parentPort.postMessage(status))
66

77
const launch = async (version, account, statusCallback) => {
8-
new Worker(resolve(join(__dirname, 'launch.js')), {
8+
/*new Worker(__filename, {
99
workerData: {
1010
version: version,
1111
account: account
12-
}
13-
}).on('message', statusCallback)
12+
},
13+
}).on('message', statusCallback)*/
14+
setTimeout(() => require('./minecraft').launch(version, account, statusCallback))
1415
}
1516

1617
module.exports = {launch}

src/updater.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const checkForUpdates = async () => {
3535
return remoteVersion.length > 0
3636
}
3737

38-
if (!isMainThread) {
38+
/*if (!isMainThread) {
3939
fetch(`https://api.github.com/repos/${repository}/releases/latest`).then(async response => {
4040
if (response && response.ok) {
4141
const json = await response.json()
@@ -51,8 +51,22 @@ if (!isMainThread) {
5151
}
5252
}
5353
})
54-
}
54+
}*/
5555

56-
const update = async () => new Worker(resolve(join(__dirname, 'updater.js')))
56+
const update = async () => setTimeout(() => fetch(`https://api.github.com/repos/${repository}/releases/latest`).then(async response => {
57+
if (response && response.ok) {
58+
const json = await response.json()
59+
const dir = join(getDirectory(), 'updates')
60+
if (!existsSync(dir)) mkdirSync(dir, {recursive: true})
61+
if (platform() == 'win32') {
62+
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)
68+
}
69+
}
70+
}))//new Worker(__filename)
5771

5872
module.exports = {checkForUpdates, update}

0 commit comments

Comments
 (0)