11const { platform } = require ( "os" )
2- const { join, resolve } = require ( "path" )
2+ const { join } = require ( "path" )
33const { getDirectory } = require ( "./util" )
4- const { execFile, spawnSync } = require ( "child_process" )
4+ const { execFile, spawn } = require ( "child_process" )
55const { existsSync, mkdirSync, readFileSync } = require ( "fs" )
66const { path } = require ( "app-root-path" )
7- const { isMainThread } = require ( "worker_threads " )
7+ const { exit } = require ( "process " )
88
99const 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-
5638const 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
7255module . exports = { checkForUpdates, update}
0 commit comments