fixed the popup when you unplug the cable

This commit is contained in:
Shane Harris
2022-08-02 18:59:29 +01:00
parent 0d440c2d8d
commit ba0fc5d54b
7 changed files with 73 additions and 128 deletions
+15 -10
View File
@@ -169,7 +169,7 @@ export class AdbClientService {
let extention = this.appService.path.extname(filepath); let extention = this.appService.path.extname(filepath);
switch (extention) { switch (extention) {
case '.apk': case '.apk':
return this.installAPK(filepath, true, false, 0, 0, false, this.appService.path.basename(filepath)); return this.installAPK(filepath, true, false, 0, 0, false, this.appService.path.basename(filepath) + ': ');
case '.obb': case '.obb':
return this.processService.addItem('file_install', async task => { return this.processService.addItem('file_install', async task => {
task.status = 'Transferring OBB file...'; task.status = 'Transferring OBB file...';
@@ -605,12 +605,12 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
return this.processService.addItem( return this.processService.addItem(
'apk_install', 'apk_install',
task => { task => {
name = name ? name + ': ' : '';
if (this.deviceStatus !== ConnectionStatus.CONNECTED) { if (this.deviceStatus !== ConnectionStatus.CONNECTED) {
return Promise.reject(name + 'Apk install failed - No device connected!'); return Promise.reject(name + 'Apk install failed - No device connected!');
} }
const showTotal = number && total ? '(' + number + '/' + total + ') ' : ''; const showTotal = number && total ? '(' + number + '/' + total + ') ' : '';
task.app_name = name; task.show_total = showTotal;
task.app_name = name || '';
task.status = name + showTotal + 'Installing Apk... '; task.status = name + showTotal + 'Installing Apk... ';
return this.adbCommand('install', { serial: this.deviceSerial, path: filePath, isLocal: !!isLocal }, status => { return this.adbCommand('install', { serial: this.deviceSerial, path: filePath, isLocal: !!isLocal }, status => {
if (status.percent && status.size && status.time) { if (status.percent && status.size && status.time) {
@@ -619,10 +619,11 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
? name + showTotal + 'Installing Apk...' ? name + showTotal + 'Installing Apk...'
: name + showTotal + 'Downloading APK... ' + Math.round(status.percent * 100) + '% '; : name + showTotal + 'Downloading APK... ' + Math.round(status.percent * 100) + '% ';
} else { } else {
task.status = if (status === 'Checking APK against blacklist...') {
status === 'Checking APK against blacklist...' task.status = name + showTotal + status;
? name + showTotal + status } else {
: name + showTotal + 'Installing Apk...'; task.status = name + showTotal + 'Installing Apk...';
}
} }
}) })
.then(r => { .then(r => {
@@ -638,7 +639,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
if (deleteAfter) { if (deleteAfter) {
this.appService.fs.unlink(filePath, err => {}); this.appService.fs.unlink(filePath, err => {});
} }
let er = e.message ? e.message : e.code ? e.code : e.reason ? e.reason : JSON.stringify(e); let er = e.message ? e.message : e.code ? e.code : e.reason ? e.reason : e.toString();
if ( if (
er.indexOf('INSTALL_FAILED_UPDATE_INCOMPATIBLE') > -1 && er.indexOf('INSTALL_FAILED_UPDATE_INCOMPATIBLE') > -1 &&
er.indexOf('com.oculus.environment.prod.') > -1 er.indexOf('com.oculus.environment.prod.') > -1
@@ -648,9 +649,13 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
this.installAPK(filePath, isLocal, shouldUninstall, number, total, deleteAfter, name); this.installAPK(filePath, isLocal, shouldUninstall, number, total, deleteAfter, name);
return Promise.reject('Install failed, uninstalling and trying again...'); return Promise.reject('Install failed, uninstalling and trying again...');
} }
if (er === 'SAFESIDE') { if (er.includes('SAFESIDE')) {
this.appService.headerComponent.safeModal.openModal(); this.appService.headerComponent.safeModal.openModal();
} }
console.log('app failed', er);
task.status =
(task.app_name ? task.app_name + ': ' : '') +
(e.message ? e.message : e.code ? e.code : e.reason ? e.reason : e.toString());
return Promise.reject(er); return Promise.reject(er);
}); });
}, },
@@ -1031,7 +1036,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
async installLocalZip(filepath, dontCatchError, cb, task?, deleteAfter?) { async installLocalZip(filepath, dontCatchError, cb, task?, deleteAfter?) {
const typeBasedActions = { const typeBasedActions = {
'.apk': filepath => { '.apk': filepath => {
this.installAPK(filepath, true, false, 0, 0, deleteAfter); this.installAPK(filepath, true, false, 0, 0, deleteAfter, this.appService.path.basename(filepath));
}, },
'.obb': filepath => { '.obb': filepath => {
if (this.appService.path.basename(filepath).match(this.obbRegex)) { if (this.appService.path.basename(filepath).match(this.obbRegex)) {
+5
View File
@@ -99,29 +99,34 @@ export class AppService {
} }
this.versionName = 'v' + this.remote.app.getVersion(); this.versionName = 'v' + this.remote.app.getVersion();
this.electron.ipcRenderer.on('extract-file', (event, data) => { this.electron.ipcRenderer.on('extract-file', (event, data) => {
console.log('download-url-progress');
if (!!this.extractResolves[data.token]) { if (!!this.extractResolves[data.token]) {
this.extractResolves[data.token].resolve(); this.extractResolves[data.token].resolve();
delete this.extractResolves[data.token]; delete this.extractResolves[data.token];
} }
}); });
this.electron.ipcRenderer.on('extract-progress', (event, data) => { this.electron.ipcRenderer.on('extract-progress', (event, data) => {
console.log('download-url-progress');
if (!!this.extractResolves[data.token]) { if (!!this.extractResolves[data.token]) {
this.extractResolves[data.token].scb(data.stats); this.extractResolves[data.token].scb(data.stats);
} }
}); });
this.electron.ipcRenderer.on('download-url-fail', (event, data) => { this.electron.ipcRenderer.on('download-url-fail', (event, data) => {
console.log('download-url-progress');
if (!!this.downloadResolves[data.token]) { if (!!this.downloadResolves[data.token]) {
this.downloadResolves[data.token].reject(data.e); this.downloadResolves[data.token].reject(data.e);
delete this.downloadResolves[data.token]; delete this.downloadResolves[data.token];
} }
}); });
this.electron.ipcRenderer.on('download-url', (event, data) => { this.electron.ipcRenderer.on('download-url', (event, data) => {
console.log('download-url-progress');
if (!!this.downloadResolves[data.token]) { if (!!this.downloadResolves[data.token]) {
this.downloadResolves[data.token].resolve(); this.downloadResolves[data.token].resolve();
delete this.downloadResolves[data.token]; delete this.downloadResolves[data.token];
} }
}); });
this.electron.ipcRenderer.on('download-progress', (event, data) => { this.electron.ipcRenderer.on('download-progress', (event, data) => {
console.log('download-url-progress');
if (!!this.downloadResolves[data.token]) { if (!!this.downloadResolves[data.token]) {
this.downloadResolves[data.token].scb(data.stats); this.downloadResolves[data.token].scb(data.stats);
} }
+2 -3
View File
@@ -65,14 +65,13 @@ export class ElectronService {
async installFromToken(token) { async installFromToken(token) {
let res = await this.adbService.adbCommand('installFromToken', { token }); let res = await this.adbService.adbCommand('installFromToken', { token });
console.log(res);
res.forEach((l, i) => { res.forEach((l, i) => {
switch (l.type) { switch (l.type) {
case 'Mod': case 'Mod':
this.beatonService.downloadSong(l.url, this.adbService); this.beatonService.downloadSong(l.url, this.adbService);
break; break;
case 'APK': case 'APK':
this.adbService.installAPK(l.url, false, false, i + 1, res.length, false, l.name); this.adbService.installAPK(l.url, false, false, i + 1, res.length, false, l.name + ': ');
break; break;
case 'OBB': case 'OBB':
this.adbService.installObb(l.url, i + 1, res.length, l.name); this.adbService.installObb(l.url, i + 1, res.length, l.name);
@@ -95,7 +94,7 @@ export class ElectronService {
this.adbService.installObb(data.url, 0, 0, data.name); this.adbService.installObb(data.url, 0, 0, data.name);
break; break;
case '.apk': case '.apk':
this.adbService.installAPK(data.url, false, false, 0, 0, true, data.name); this.adbService.installAPK(data.url, false, false, 0, 0, true, data.name + ': ');
break; break;
} }
}); });
@@ -290,23 +290,6 @@ export class HeaderComponent implements OnInit {
} }
); );
} }
closeApp() {
this.appService.remote.getCurrentWindow().close();
}
pingHeadset() {
this.isAlive = true;
}
minimizeApp() {
this.appService.remote.getCurrentWindow().minimize();
}
maximizeApp() {
const win = this.appService.remote.getCurrentWindow();
if (win.isMaximized()) {
win.unmaximize();
} else {
win.maximize();
}
}
async selectAppToInstall() { async selectAppToInstall() {
let files = await this.appService.remote.dialog.showOpenDialog({ let files = await this.appService.remote.dialog.showOpenDialog({
properties: ['openFile', 'multiSelections'], properties: ['openFile', 'multiSelections'],
@@ -322,20 +305,4 @@ export class HeaderComponent implements OnInit {
} }
}); });
} }
confirmRestore() {
this.spinnerService.showLoader();
this.spinnerService.setMessage('Restoring BMBF<br>Please Wait...');
this.beatonService.confirmRestore(this.adbService).then(r => {
this.spinnerService.hideLoader();
this.statusService.showStatus('BMBF Restored Successfully!!');
this.beatOnModal.openModal();
this.beatonService.checkHasRestore(this.adbService);
});
}
installAPK(name: string) {
return this.adbService.installAPK(this.appService.path.join(this.appService.appData, name), true, true);
}
removeText(text) {
this.replaceText = this.replaceText.filter(d => d !== text);
}
} }
+11 -6
View File
@@ -5,13 +5,14 @@ export class ProcessTask {
key: string; key: string;
name: string; name: string;
app_name?: string; app_name?: string;
show_total?: string;
icon: string; icon: string;
private _status?; private _status?;
get status(): string { get status(): string {
return this._status; return this._status;
} }
set status(d) { set status(d) {
this.statusService.showStatus(d, false, true); this.statusService.showStatus(d.replace(/:\s+/g, ': '), false, true);
this._status = d; this._status = d;
} }
running?: boolean; running?: boolean;
@@ -87,7 +88,7 @@ export class ProcessBucketService {
async processBucket() { async processBucket() {
const objects = this.tasks.filter(t => !t.failed && !t.running && !t.cancelled && !t.succeeded); const objects = this.tasks.filter(t => !t.failed && !t.running && !t.cancelled && !t.succeeded);
const timeout = new Promise(resolve => setTimeout(() => resolve(), 1000)); const timeout = () => new Promise(resolve => setTimeout(() => resolve(), 500));
this.left_length = objects.length; this.left_length = objects.length;
if (objects.length) { if (objects.length) {
this.is_running = true; this.is_running = true;
@@ -101,18 +102,22 @@ export class ProcessBucketService {
task.succeeded = true; task.succeeded = true;
this.currentTask = null; this.currentTask = null;
if (!task.cancelled) { if (!task.cancelled) {
return timeout.then(() => this.processBucket()); return timeout().then(() => this.processBucket());
} }
}) })
.catch(e => { .catch(e => {
task.running = false; task.running = false;
task.status = task.status =
(task.app_name ? task.app_name + ': ' : '') + (e.message ? e.message : e.code ? e.code : e.toString()); (task.app_name || '') + (e.message ? e.message : e.code ? e.code : e.reason ? e.reason : e.toString());
task.failed = true; task.failed = true;
this.currentTask = null; this.currentTask = null;
this.statusService.showStatus(task.status, true); this.statusService.showStatus(task.status, true);
if (!task.cancelled) { if (!task.cancelled) {
return timeout.then(() => this.processBucket()); console.log('h1');
return timeout().then(async () => {
console.log('h2');
await this.processBucket();
});
} }
}); });
this.tasks = this.tasks.filter(t => t !== task); this.tasks = this.tasks.filter(t => t !== task);
@@ -132,7 +137,7 @@ export class ProcessBucketService {
); );
} }
this.is_running = false; this.is_running = false;
await timeout.then(() => this.processBucket()); await timeout().then(() => this.processBucket());
} }
} }
@@ -12,7 +12,6 @@ export class StatusBarService {
this.status = status; this.status = status;
} }
showStatus(message: string, isError?: boolean, isInfo?: boolean) { showStatus(message: string, isError?: boolean, isInfo?: boolean) {
console.warn('here');
this.status.showStatus(message, isError, isInfo); this.status.showStatus(message, isError, isInfo);
} }
hideStatus() { hideStatus() {
+40 -75
View File
@@ -22,8 +22,20 @@ app.allowRendererProcessReuse = false;
// const Readable = require('stream').Readable; // const Readable = require('stream').Readable;
import { SetPropertiesCommand } from './setproperties'; import { SetPropertiesCommand } from './setproperties';
import { OPEN_IN_SYSTEM_BROWSER_DOMAINS } from './external-urls'; import { OPEN_IN_SYSTEM_BROWSER_DOMAINS } from './external-urls';
let has_port = process.argv.indexOf('--port'); let has_port = process.argv.indexOf('--port');
let valid_port = has_port > -1 && process.argv[has_port + 1] && Number.isInteger(Number(process.argv[has_port + 1])); let valid_port = has_port > -1 && process.argv[has_port + 1] && Number.isInteger(Number(process.argv[has_port + 1]));
let installErrorCallback;
process.on('uncaughtException', function(error) {
if (error.toString().includes('Error: This socket has been ended by the other party') && installErrorCallback) {
installErrorCallback("Couldn't communicate with the headset, try another USB port or cable...");
installErrorCallback = null;
console.log(error);
}
});
class ADB { class ADB {
client; client;
_logcat; _logcat;
@@ -178,6 +190,13 @@ class ADB {
.catch(e => ecb(e)); .catch(e => ecb(e));
} }
async install(serial, apkpath, isLocal, cb, scb, ecb) { async install(serial, apkpath, isLocal, cb, scb, ecb) {
console.log('installapk');
let stopUpdate;
installErrorCallback = e => {
stopUpdate = true;
ecb(e);
console.log(e, stopUpdate);
};
if (!this.client) return ecb('Not connected.'); if (!this.client) return ecb('Not connected.');
if (isLocal) { if (isLocal) {
let found; let found;
@@ -193,21 +212,27 @@ class ADB {
scb('Transferring APK to device...'); scb('Transferring APK to device...');
let stream; let stream;
try { try {
stream = isLocal if (isLocal) {
? fs.createReadStream(apkpath) stream = fs.createReadStream(apkpath);
: new Readable().wrap( } else {
progress(request(apkpath), { stream = new Readable().wrap(
throttle: 60, progress(request(apkpath), {
}) throttle: 60,
.on('progress', state => { })
scb(state); .on('progress', state => {
}) if (!stopUpdate) {
.on('end', () => { scb(state);
scb({ }
percent: 1, })
}); .on('end', () => {
}) if (!stopUpdate) {
); scb({
percent: 1,
});
}
})
);
}
} catch (e) { } catch (e) {
const isInvalidURI = e && typeof e.message === 'string' && e.message.startsWith('Invalid URI "'); const isInvalidURI = e && typeof e.message === 'string' && e.message.startsWith('Invalid URI "');
if (isInvalidURI) { if (isInvalidURI) {
@@ -220,66 +245,6 @@ class ADB {
.install(serial, stream) .install(serial, stream)
.then(cb) .then(cb)
.catch(e => ecb(e)); .catch(e => ecb(e));
// let outpath = isLocal ? apkpath : path.join(app.getPath('appData'), 'SideQuest', new Date().getTime() + '.apk');
// let promise;
// if (isLocal) {
// let found;
// try {
// found = await this.checkAPK(scb, apkpath);
// } catch (e) {
// return ecb(e);
// }
// if (found) {
// return ecb('SAFESIDE');
// }
// }
// promise = isLocal
// ? Promise.resolve()
// : new Promise(resolve => {
// progress(request(apkpath), {
// throttle: 60,
// })
// .on('progress', state => {
// scb(state);
// })
// .on('end', () => {
// scb({
// percent: 1,
// size: 1,
// time: 1,
// });
// resolve();
// })
// .on('error', () => {
// ecb('Download error! Please try again!');
// })
// .pipe(fs.createWriteStream(outpath));
// });
// promise
// .then(
// () =>
// new Promise((resolve, reject) => {
// console.log('"' + this.adbPath + '" -s ' + serial + ' install -r -d "' + outpath + '"');
// exec(
// '"' + this.adbPath + '" -s ' + serial + ' install -r -d "' + outpath + '"',
// {},
// (error, stdout, stderr) => {
// if (error) {
// reject(error.message ? error.message : error.toString());
// } else {
// resolve();
// }
// }
// );
// })
// )
// .then(() => (isLocal ? null : fs.unlinkSync(outpath)))
// .then(cb)
// .catch(e => {
// if (!isLocal) fs.unlinkSync(outpath);
// ecb(e);
// });
} }
uninstall(serial, packageName, cb, ecb) { uninstall(serial, packageName, cb, ecb) {
if (!this.client) return ecb('Not connected.'); if (!this.client) return ecb('Not connected.');