diff --git a/desktop-app/src/app/adb-client.service.ts b/desktop-app/src/app/adb-client.service.ts index 0110be2..67eeeb0 100644 --- a/desktop-app/src/app/adb-client.service.ts +++ b/desktop-app/src/app/adb-client.service.ts @@ -30,6 +30,7 @@ export class AdbClientService { lastConnectionCheck: number; deviceStatus: ConnectionStatus = ConnectionStatus.UNAUTHORIZED; deviceStatusMessage: string = 'Connecting...'; + lastErrorMessage: string = ''; pollInterval: number = 1000 * 2; savePath: string; isTransferring: boolean; @@ -353,23 +354,31 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u }); } async setupAdb() { - if (!this.isAdbDownloaded()) { - await this.appService.seedPlatformTools(); - } - this.appService.electron.ipcRenderer.on('adb-command', (event, arg: any) => { - if (this.adbResolves[arg.uuid]) { - if (arg.status && this.adbResolves[arg.uuid].callback) { - this.adbResolves[arg.uuid].callback(arg.status); - } else if (arg.error) { - this.adbResolves[arg.uuid].reject(arg.error); - } else { - this.adbResolves[arg.uuid].resolve(arg.resp); - } + try { + if (!this.isAdbDownloaded()) { + await this.appService.seedPlatformTools(); } - }); - this.adbCommand('setupAdb', { - adbPath: this.appService.path.join(this.adbPath, this.getAdbBinary()), - }); + this.appService.electron.ipcRenderer.on('adb-command', (event, arg: any) => { + if (this.adbResolves[arg.uuid]) { + if (arg.status && this.adbResolves[arg.uuid].callback) { + this.adbResolves[arg.uuid].callback(arg.status); + } else if (arg.error) { + this.adbResolves[arg.uuid].reject(arg.error); + } else { + this.adbResolves[arg.uuid].resolve(arg.resp); + } + } + }); + this.adbCommand('setupAdb', { + adbPath: this.appService.path.join(this.adbPath, this.getAdbBinary()), + }); + this.lastErrorMessage = null; + } catch (e) { + console.error(e); + this.deviceStatus = ConnectionStatus.DISCONNECTED; + this.deviceStatusMessage = 'ADB Setup Error'; + this.lastErrorMessage = e.toString(); + } } isAdbDownloaded() { try { diff --git a/desktop-app/src/app/app.service.ts b/desktop-app/src/app/app.service.ts index 87d99f2..0e28827 100644 --- a/desktop-app/src/app/app.service.ts +++ b/desktop-app/src/app/app.service.ts @@ -249,32 +249,42 @@ export class AppService { return sourcesPath; } seedPlatformTools() { - return new Promise(async resolve => { + return new Promise(async (resolve, reject) => { let sourcesPath = this.getPlatformToolsSeedPath(); if (sourcesPath == null) { console.error('Unable to locate platform tools! Try reinstalling sidequest.'); - resolve(); + reject('Unable to locate platform tools! Try reinstalling sidequest.'); return; } await this.mkdir(this.path.join(this.appData, 'platform-tools')); try { - let files = this.fs.readdirSync(sourcesPath); + let files: [] = this.fs.readdirSync(sourcesPath); + //always copy the adb executable last so this will retry in the event some copying fails + files.sort((a: string, b) => (a.endsWith('adb') || a.endsWith('adb.exe') ? 1 : -1)); for (let i = 0; i < files.length; i++) { - this.fs.copyFileSync( - this.path.join(sourcesPath, files[i]), - this.path.join(this.appData, 'platform-tools', files[i]) - ); + try { + this.fs.copyFileSync( + this.path.join(sourcesPath, files[i]), + this.path.join(this.appData, 'platform-tools', files[i]) + ); + } catch (e) { + console.error('Error copying platform tools file ' + files[i] + e); + //if the file exists and isn't writeable, don't give up, have some hope it's just in use and is fine. + if (!this.fs.existsSync(this.path.join(this.appData, 'platform-tools', files[i]))) { + throw 'Error copying platform tools file: ' + e.toString(); + } + } } if (this.os.platform() === 'darwin' || this.os.platform() === 'linux') { this.setExecutable(this.path.join(this.appData, 'platform-tools', 'adb')).then(() => - setTimeout(() => resolve(), 5000) + setTimeout(() => resolve(), 8000) ); } else { - setTimeout(() => resolve(), 5000); + setTimeout(() => resolve(), 8000); } } catch (e) { console.error('Error seeding platform tools! ', e); - resolve(); + reject('Error seeding platform tools: ' + e.toString()); } }); } diff --git a/desktop-app/src/app/header/header.component.html b/desktop-app/src/app/header/header.component.html index 2320368..8787046 100644 --- a/desktop-app/src/app/header/header.component.html +++ b/desktop-app/src/app/header/header.component.html @@ -222,7 +222,7 @@ arrow_drop_down
+ position="bottom" [ngClass]="adbService.connectionCss" [tooltip]="adbService.lastErrorMessage||'Device connection status.'">
diff --git a/electron/app.ts b/electron/app.ts index 2c51d32..207024c 100644 --- a/electron/app.ts +++ b/electron/app.ts @@ -15,6 +15,8 @@ const exec = require('child_process').exec; const crypto = require('crypto'); const request = require('request'); const progress = require('request-progress'); +//without this, there's a bug in electron that makes facebook pages ruin everything, see https://github.com/electron/electron/issues/25469 +app.commandLine.appendSwitch('disable-features', 'CrossOriginOpenerPolicy'); const OPEN_IN_SYSTEM_BROWSER_DOMAINS = [ 'www.oculus.com',