@@ -39,11 +39,7 @@ async function run_caddy(platform) {
39
39
}
40
40
41
41
async function run_frontend ( name , command , args , env ) {
42
- if ( platform == 'linux' ) {
43
- const cmd = new shell . Command ( 'chmod' , [ 'u+x' , command ] , { cwd : await path . appDataDir ( ) , env : formatEnv ( env ) } )
44
- await cmd . spawn ( ) ;
45
- }
46
- const cmd = new shell . Command ( command , args , { cwd : await path . appDataDir ( ) , env : formatEnv ( env ) } )
42
+ const cmd = new shell . Command ( command , args , { cwd : await path . join ( await path . appDataDir ( ) , name ) , env : formatEnv ( env ) } )
47
43
cmd . on ( 'error' , error => {
48
44
console . error ( `command error: "${ error } "` )
49
45
return 'downloaded'
@@ -54,24 +50,34 @@ async function run_frontend(name, command, args, env) {
54
50
}
55
51
56
52
async function download_frontend ( name ) {
57
- const response = await http . fetch ( `https://github.com/libredirect/frontends_binaries/raw/main/${ name } /${ name } _${ platform } _x86_64` , {
58
- method : 'GET' ,
59
- timeout : 30 ,
60
- responseType : http . ResponseType . Binary
61
- } ) ;
62
- await fs . writeBinaryFile ( `${ name } _${ platform } _x86_64` , new Uint8Array ( response . data ) , { dir : fs . BaseDirectory . AppData } ) ;
53
+ let filename
54
+ if ( platform == 'linux' ) {
55
+ filename = `${ name } _linux_x86_64.tar.gz`
56
+ } else if ( platform == 'windows' ) {
57
+ filename = `${ name } _windows_x86_64.zip`
58
+ }
59
+ const response = await http . fetch (
60
+ `https://github.com/libredirect/frontends_binaries/raw/main/binaries/${ filename } ` ,
61
+ { method : 'GET' , responseType : http . ResponseType . Binary }
62
+ ) ;
63
+ await fs . writeBinaryFile ( filename , new Uint8Array ( response . data ) , { dir : fs . BaseDirectory . AppData } ) ;
64
+ if ( platform == 'linux' ) {
65
+ const extract_cmd = new shell . Command ( 'tar' , [ '-xzf' , filename ] , { cwd : await path . appDataDir ( ) } )
66
+ await extract_cmd . spawn ( ) ;
67
+ extract_cmd . on ( 'close' , async ( ) => await fs . removeFile ( filename , { dir : fs . BaseDirectory . AppData } ) ) ;
68
+ }
63
69
return 'downloaded'
64
70
}
65
71
66
72
async function check_downloaded ( name ) {
67
- if ( await fs . exists ( `${ name } _ ${ platform } _x86_64 ` , { dir : fs . BaseDirectory . AppData } ) ) {
73
+ if ( await fs . exists ( `${ name } ` , { dir : fs . BaseDirectory . AppData } ) ) {
68
74
return 'downloaded'
69
75
} else {
70
76
return 'not_downloaded'
71
77
}
72
78
}
73
79
async function remove_frontend ( name ) {
74
- await fs . removeFile ( ` ${ name } _ ${ platform } _x86_64` , { dir : fs . BaseDirectory . AppData } )
80
+ await fs . removeDir ( name , { dir : fs . BaseDirectory . AppData , recursive : true } )
75
81
return 'not_downloaded'
76
82
}
77
83
0 commit comments