diff --git a/desktop-app/src/app/adb-client.service.ts b/desktop-app/src/app/adb-client.service.ts index 8e4dbe2..0110be2 100644 --- a/desktop-app/src/app/adb-client.service.ts +++ b/desktop-app/src/app/adb-client.service.ts @@ -372,18 +372,27 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u }); } isAdbDownloaded() { - let downloaded = true; - if (!this.doesFileExist(this.adbPath)) { + try { + let downloaded = true; + if (!this.doesFileExist(this.adbPath)) { + return false; + } + + let source_files = this.appService.fs.readdirSync(this.appService.getPlatformToolsSeedPath()); + if (source_files === null) { + return false; + } + let dest_files = this.appService.fs.readdirSync(this.adbPath); + source_files.forEach(d => { + if (dest_files.indexOf(d) === -1) { + downloaded = false; + } + }); + return downloaded; // this.doesFileExist(this.appService.path.join(this.adbPath, this.getAdbBinary())); + } catch (e) { + console.error('Error checking for ADB being installed', e); return false; } - let source_files = this.appService.fs.readdirSync(this.appService.path.join(process.cwd(), 'build', 'platform-tools')); - let dest_files = this.appService.fs.readdirSync(this.adbPath); - source_files.forEach(d => { - if (dest_files.indexOf(d) === -1) { - downloaded = false; - } - }); - return downloaded; // this.doesFileExist(this.appService.path.join(this.adbPath, this.getAdbBinary())); } setPermission(packageName: string, permission: string, isRevoke?: boolean) { return this.adbCommand('shell', { diff --git a/desktop-app/src/app/app.service.ts b/desktop-app/src/app/app.service.ts index e83d525..87d99f2 100644 --- a/desktop-app/src/app/app.service.ts +++ b/desktop-app/src/app/app.service.ts @@ -225,11 +225,36 @@ export class AppService { break; } } + + private foundSeedToolsPath: string | null = null; + getPlatformToolsSeedPath() { + if (this.foundSeedToolsPath !== null) { + return this.foundSeedToolsPath; + } + let ogSourcesPath = this.path.join(process.resourcesPath, 'build', 'platform-tools'); + let sourcesPath = ogSourcesPath; + if (!this.doesFileExist(sourcesPath)) { + sourcesPath = sourcesPath.replace('app.asar', 'app.asar.unpacked'); + } + if (!this.doesFileExist(sourcesPath)) { + sourcesPath = this.path.join(process.resourcesPath, 'app.asar.unpacked', 'build', 'platform-tools'); + } + if (!this.doesFileExist(sourcesPath)) { + sourcesPath = this.path.join(process.cwd(), 'build', 'platform-tools'); + } + if (!this.doesFileExist(sourcesPath)) { + return null; + } + this.foundSeedToolsPath = sourcesPath; + return sourcesPath; + } seedPlatformTools() { - return new Promise(async resolve => { - let sourcesPath = this.path.join(__dirname, '..', 'platform-tools'); - if (!this.fs.existsSync(sourcesPath)) { - sourcesPath = this.path.join(process.cwd(), 'build', 'platform-tools'); + return new Promise(async resolve => { + let sourcesPath = this.getPlatformToolsSeedPath(); + if (sourcesPath == null) { + console.error('Unable to locate platform tools! Try reinstalling sidequest.'); + resolve(); + return; } await this.mkdir(this.path.join(this.appData, 'platform-tools')); try { @@ -247,7 +272,10 @@ export class AppService { } else { setTimeout(() => resolve(), 5000); } - } catch (e) {} + } catch (e) { + console.error('Error seeding platform tools! ', e); + resolve(); + } }); } makeFolders() { @@ -262,7 +290,7 @@ export class AppService { }); } setExecutable(path) { - return new Promise(resolve => { + return new Promise(resolve => { const ls = this.spawn('chmod', ['+x', path]); ls.stdout.on('data', res => { console.log(res);