@@ -5,10 +5,10 @@ import path from 'path'
55import fs from 'fs'
66
77import {
8+ buildUnzipCommand ,
89 execAsync ,
910 getLogLevel ,
1011 getPlatformADB ,
11- getPlatformTar ,
1212 log ,
1313 LogLevel
1414} from './utils.js'
@@ -21,10 +21,15 @@ export async function getAdbExecutable() {
2121
2222 if ( res && platform ( ) !== 'darwin' ) return 'adb'
2323
24- const { downloadURL, executable } = getPlatformADB ( )
24+ const adbInfo = getPlatformADB ( )
25+ if ( ! adbInfo ) {
26+ log ( 'Failed to find adb for platform' , 'adb' , LogLevel . ERROR )
27+ throw new Error ( 'adb_platform_not_found' )
28+ }
29+ const { url, cmd } = adbInfo
2530 const userDataPath = app . getPath ( 'userData' )
2631 const platformToolsPath = path . join ( userDataPath , 'platform-tools' )
27- const adbPath = path . join ( platformToolsPath , executable )
32+ const adbPath = path . join ( platformToolsPath , cmd )
2833
2934 if ( fs . existsSync ( adbPath ) ) return `"${ adbPath } "`
3035
@@ -37,7 +42,7 @@ export async function getAdbExecutable() {
3742
3843 if ( fs . existsSync ( downloadPath ) ) fs . unlinkSync ( downloadPath )
3944
40- const download = await axios . get ( downloadURL , {
45+ const download = await axios . get ( url , {
4146 responseType : 'stream' ,
4247 validateStatus : ( ) => true
4348 } )
@@ -51,16 +56,20 @@ export async function getAdbExecutable() {
5156
5257 download . data . pipe ( writer )
5358
54- await new Promise ( ( resolve , reject ) => {
59+ await new Promise < void > ( ( resolve , reject ) => {
5560 writer . on ( 'finish' , resolve )
5661 writer . on ( 'error' , reject )
5762 } )
5863
5964 log ( 'Downloaded ADB!' , 'adb' )
6065
61- const extract = await execAsync (
62- `${ getPlatformTar ( ) } -xf ${ downloadPath } -C "${ userDataPath } "`
63- )
66+ const unzipCommand = buildUnzipCommand ( downloadPath , userDataPath )
67+ if ( ! unzipCommand ) {
68+ log ( 'Failed to find unzip command for platform' , 'adb' , LogLevel . ERROR )
69+ throw new Error ( 'adb_platform_not_found' )
70+ }
71+
72+ const extract = await execAsync ( unzipCommand )
6473
6574 if ( extract === null ) {
6675 log ( 'Failed to extract adb' , 'adb' )
0 commit comments