From afcc6e58f8f3e92d771c565ed216007d0b349f23 Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Sat, 11 Apr 2020 17:44:14 +0100 Subject: [PATCH] moving to private repo --- desktop-app/src/app/adb-client.service.ts | 206 ++++++++++-------- desktop-app/src/app/app.component.css | 2 +- desktop-app/src/app/app.component.html | 3 +- desktop-app/src/app/app.component.ts | 1 + desktop-app/src/app/app.service.ts | 13 +- desktop-app/src/app/beat-on.service.ts | 1 - .../current-task-item.component.html | 2 +- desktop-app/src/app/electron.service.ts | 57 ++++- .../src/app/header/header.component.html | 5 + desktop-app/src/app/process-bucket.service.ts | 18 +- desktop-app/src/app/webview.service.ts | 1 + .../src/app/webview/webview.component.ts | 1 - electron/app.ts | 7 +- electron/download.ts | 6 +- electron/window.ts | 1 + package.json | 4 +- 16 files changed, 211 insertions(+), 117 deletions(-) diff --git a/desktop-app/src/app/adb-client.service.ts b/desktop-app/src/app/adb-client.service.ts index fe6bad3..19b6f8f 100644 --- a/desktop-app/src/app/adb-client.service.ts +++ b/desktop-app/src/app/adb-client.service.ts @@ -510,76 +510,87 @@ export class AdbClientService { shouldUninstall?: boolean, number?: number, total?: number, - deleteAfter?: boolean + deleteAfter?: boolean, + name?: string ) { - return this.processService.addItem('apk_install', task => { - if (this.deviceStatus !== ConnectionStatus.CONNECTED) { - return Promise.reject('Apk install failed: No device connected! ' + filePath); - } - const showTotal = number && total ? '(' + number + '/' + total + ') ' : ''; - const updateStatus = (text: string): void => { - const newStatus = `${showTotal}${text} `; - if (task.status !== newStatus) { - task.status = newStatus; + return this.processService.addItem( + 'apk_install', + task => { + name = name ? name + ': ' : ''; + if (this.deviceStatus !== ConnectionStatus.CONNECTED) { + return Promise.reject(name + 'Apk install failed - No device connected! ' + filePath); } - }; - const checkReported: Promise = isLocal - ? this.checkIsAPKReported(updateStatus, filePath) - : Promise.resolve('DoInstall'); - return checkReported.then(installDecision => { - if (installDecision === 'DoInstall') { - task.status = showTotal + 'Installing Apk... '; - return this.adbCommand('install', { serial: this.deviceSerial, path: filePath, isLocal: !!isLocal }, status => { - task.status = - (status.percent === 1 - ? showTotal + 'Installing Apk... ' - : showTotal + 'Downloading APK... ' + Math.round(status.percent * 100) + '% ') + - ' ' + - filePath + - ''; - }) - .then(r => { - task.status = 'APK file installed ok!! ' + filePath; - if (deleteAfter) { - this.appService.fs.unlink(filePath, err => {}); - } - if (filePath.indexOf('com.weloveoculus.BMBF') > -1) { - return this.beatonService.setBeatOnPermission(this); - } - if (filePath.toLowerCase().indexOf('sidequest.legends') > -1) { - return this.setPermission('com.sidequest.legends', 'android.permission.RECORD_AUDIO'); - } - if (filePath.toLowerCase().indexOf('pavlov') > -1) { - return this.setPermission('com.vankrupt.pavlov', 'android.permission.RECORD_AUDIO') - .then(() => - this.setPermission('com.vankrupt.pavlov', 'android.permission.READ_EXTERNAL_STORAGE') - ) - .then(() => - this.setPermission('com.vankrupt.pavlov', 'android.permission.WRITE_EXTERNAL_STORAGE') - ) - .then(() => - this.adbCommand('shell', { - serial: this.deviceSerial, - command: 'echo null > /sdcard/pavlov.name.txt', - }) - ); - } - }) - .catch(e => { - if (deleteAfter) { - this.appService.fs.unlink(filePath, err => {}); - } - return Promise.reject(e.message ? e.message : e.code ? e.code : e.toString() + ' ' + filePath); - }); - } else { - if (deleteAfter) { - this.appService.fs.unlink(filePath, err => {}); + const showTotal = number && total ? '(' + number + '/' + total + ') ' : ''; + const updateStatus = (text: string): void => { + const newStatus = `${showTotal}${text} `; + if (task.status !== newStatus) { + task.status = newStatus; } - updateStatus('Canceled Install.'); - return Promise.resolve(); - } - }); - }); + }; + const checkReported: Promise = isLocal + ? this.checkIsAPKReported(updateStatus, filePath) + : Promise.resolve('DoInstall'); + return checkReported.then(installDecision => { + task.app_name = name; + if (installDecision === 'DoInstall') { + task.status = name + showTotal + 'Installing Apk... '; + return this.adbCommand( + 'install', + { serial: this.deviceSerial, path: filePath, isLocal: !!isLocal }, + status => { + task.status = + (status.percent === 1 + ? name + showTotal + 'Installing Apk... ' + : name + showTotal + 'Downloading APK... ' + Math.round(status.percent * 100) + '% ') + + ' ' + + filePath + + ''; + } + ) + .then(r => { + task.status = name + 'APK file installed ok!! ' + filePath; + if (deleteAfter) { + this.appService.fs.unlink(filePath, err => {}); + } + if (filePath.indexOf('com.weloveoculus.BMBF') > -1) { + return this.beatonService.setBeatOnPermission(this); + } + if (filePath.toLowerCase().indexOf('sidequest.legends') > -1) { + return this.setPermission('com.sidequest.legends', 'android.permission.RECORD_AUDIO'); + } + if (filePath.toLowerCase().indexOf('pavlov') > -1) { + return this.setPermission('com.vankrupt.pavlov', 'android.permission.RECORD_AUDIO') + .then(() => + this.setPermission('com.vankrupt.pavlov', 'android.permission.READ_EXTERNAL_STORAGE') + ) + .then(() => + this.setPermission('com.vankrupt.pavlov', 'android.permission.WRITE_EXTERNAL_STORAGE') + ) + .then(() => + this.adbCommand('shell', { + serial: this.deviceSerial, + command: 'echo null > /sdcard/pavlov.name.txt', + }) + ); + } + }) + .catch(e => { + if (deleteAfter) { + this.appService.fs.unlink(filePath, err => {}); + } + return Promise.reject(e.message ? e.message : e.code ? e.code : e.toString() + ' ' + filePath); + }); + } else { + if (deleteAfter) { + this.appService.fs.unlink(filePath, err => {}); + } + updateStatus('Canceled Install.'); + return Promise.resolve(); + } + }); + }, + name + ); } async checkIsAPKReported(updateStatus: (string) => void, filePath: string): Promise { let isReported: boolean; @@ -904,33 +915,38 @@ export class AdbClientService { }); }); } - installObb(url, number?: number, total?: number) { - return this.processService.addItem('file_install', async task => { - task.status = 'Downloading OBB file...'; - return this.appService - .downloadFile( - url, - url, - url, - downloadUrl => { - return this.appService.path.join( - this.appService.appData, - downloadUrl - .split('/') - .pop() - .split('?') - .shift() - ); - }, - task - ) - .then((_path: string) => { - task.status = 'Installing OBB file...'; - return this.installLocalObb(_path, false, null, number, total, task); - }); - }); + installObb(url, number?: number, total?: number, name?: string) { + return this.processService.addItem( + 'file_install', + async task => { + task.app_name = name; + task.status = (name ? name + ': ' : '') + 'Downloading OBB file...'; + return this.appService + .downloadFile( + url, + url, + url, + downloadUrl => { + return this.appService.path.join( + this.appService.appData, + downloadUrl + .split('/') + .pop() + .split('?') + .shift() + ); + }, + task + ) + .then((_path: string) => { + task.status = name + 'Installing OBB file...'; + return this.installLocalObb(_path, false, null, number, total, task, name); + }); + }, + name + ); } - installLocalObb(filepath: string, dontCatchError = false, cb = null, number?: number, total?: number, task?) { + installLocalObb(filepath: string, dontCatchError = false, cb = null, number?: number, total?: number, task?, name?: string) { let filename = this.appService.path.basename(filepath); let packageId = filename.match(/main.[0-9]{1,}.([a-z]{1,}.[A-z]{1,}.[A-z]{1,}).obb/)[1]; const showTotal = number && total ? '(' + number + '/' + total + ') ' : ''; @@ -941,7 +957,7 @@ export class AdbClientService { } p = p.then(() => { if (task) { - task.status = 'File transferred successfully! ' + filepath; + task.status = name + 'File transferred successfully! ' + filepath; } else { this.statusService.showStatus('File transferred successfully!'); } @@ -950,7 +966,7 @@ export class AdbClientService { p = p.catch(e => { if (task) { task.failed = true; - task.status = 'Failed to transfer file!! - ' + filepath; + task.status = name + 'Failed to transfer file!! - ' + filepath; } else { this.spinnerService.hideLoader(); this.statusService.showStatus(e.toString(), true); diff --git a/desktop-app/src/app/app.component.css b/desktop-app/src/app/app.component.css index 50a1761..e590ccd 100644 --- a/desktop-app/src/app/app.component.css +++ b/desktop-app/src/app/app.component.css @@ -25,7 +25,7 @@ border-top-left-radius: 40px; z-index: 9; } -#beatView{ +#mainWebView{ width: 100%; height: calc(100% - 35px); top: 35px; diff --git a/desktop-app/src/app/app.component.html b/desktop-app/src/app/app.component.html index 079d6ed..f9caf03 100644 --- a/desktop-app/src/app/app.component.html +++ b/desktop-app/src/app/app.component.html @@ -6,7 +6,8 @@ - diff --git a/desktop-app/src/app/app.component.ts b/desktop-app/src/app/app.component.ts index 9a0741b..b34fed5 100644 --- a/desktop-app/src/app/app.component.ts +++ b/desktop-app/src/app/app.component.ts @@ -47,6 +47,7 @@ export class AppComponent { ngAfterViewInit() { this.spinnerService.setSpinner(this.spinner); this.statusService.setStatus(this.status); + console.log(this.webview); this.webService.setWebView(this.webview.nativeElement); } } diff --git a/desktop-app/src/app/app.service.ts b/desktop-app/src/app/app.service.ts index 1a7c737..c895eb7 100644 --- a/desktop-app/src/app/app.service.ts +++ b/desktop-app/src/app/app.service.ts @@ -104,6 +104,12 @@ export class AppService { this.extractResolves[data.token].scb(data.stats); } }); + this.electron.ipcRenderer.on('download-url-fail', (event, data) => { + if (!!this.downloadResolves[data.token]) { + this.downloadResolves[data.token].reject(data.e); + delete this.downloadResolves[data.token]; + } + }); this.electron.ipcRenderer.on('download-url', (event, data) => { if (!!this.downloadResolves[data.token]) { this.downloadResolves[data.token].resolve(); @@ -125,7 +131,7 @@ export class AppService { this.extractResolves[token] = { scb: stats => { if (task) { - task.status = 'Extracting... ' + stats; + task.status = (task.app_name ? task.app_name + ': ' : '') + 'Extracting... ' + stats; } }, resolve, @@ -267,15 +273,16 @@ export class AppService { } downloadFileAPI(url, directory, filename, task?) { // Send request to application thread to download a file. Store the callback for the response. - return new Promise(resolve => { + return new Promise((resolve, reject) => { let token = this.uuidv4(); this.downloadResolves[token] = { scb: stats => { if (task) { - task.status = 'Downloading... ' + stats + '%'; + task.status = (task.app_name ? task.app_name + ': ' : '') + 'Downloading... ' + stats + '%'; } }, resolve, + reject, }; this.electron.ipcRenderer.send('download-url', { token, url, directory, filename }); }); diff --git a/desktop-app/src/app/beat-on.service.ts b/desktop-app/src/app/beat-on.service.ts index 22a4242..e88de2a 100644 --- a/desktop-app/src/app/beat-on.service.ts +++ b/desktop-app/src/app/beat-on.service.ts @@ -211,7 +211,6 @@ export class BeatOnService { return this.processService.addItem('song_download', async task => { let parts = downloadUrl.split('/'); let zipPath = this.appService.path.join(this.appService.appData, this.appService.uuidv4() + '.zip'); - //let name = parts[parts.length - 1].split('.')[0]; const requestOptions = { timeout: 30000, 'User-Agent': this.appService.getUserAgent(), diff --git a/desktop-app/src/app/current-task-item/current-task-item.component.html b/desktop-app/src/app/current-task-item/current-task-item.component.html index 4e15004..4d967b5 100644 --- a/desktop-app/src/app/current-task-item/current-task-item.component.html +++ b/desktop-app/src/app/current-task-item/current-task-item.component.html @@ -6,5 +6,5 @@
- close + close
diff --git a/desktop-app/src/app/electron.service.ts b/desktop-app/src/app/electron.service.ts index 9d1c035..a849b65 100644 --- a/desktop-app/src/app/electron.service.ts +++ b/desktop-app/src/app/electron.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, isDevMode } from '@angular/core'; import { AppService } from './app.service'; import { RepoService } from './repo.service'; import { StatusBarService } from './status-bar.service'; @@ -65,6 +65,55 @@ export class ElectronService { } } + installFromToken(token) { + let options = { + url: 'https://api.sidequestvr.com/install-from-key', + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Origin: 'https://sidequestvr.com', + }, + rejectUnauthorized: !isDevMode(), + json: { token: token }, + }; + console.log(options); + this.appService.request(options, async (error, response, body) => { + console.log(error, body); + if (!error && body.data && body.data.apps && body.data.apps.length) { + for (let i = 0; i < body.data.apps.length; i++) { + let app = body.data.apps[i]; + if (Number(app.app_categories_id) === 1) { + let urls = app.urls.filter(l => l && ~['Github Release', 'APK', 'OBB'].indexOf(l.provider)); + for (let i = 0; i < urls.length; i++) { + const etx = urls[i].link_url + .split('?')[0] + .split('.') + .pop() + .toLowerCase(); + switch (etx) { + case 'obb': + await this.adbService.installObb(urls[i].link_url, i + 1, urls.length, app.name); + break; + default: + await this.adbService.installAPK( + urls[i].link_url, + false, + false, + i + 1, + urls.length, + false, + app.name + ); + break; + } + } + } + } + } + }); + } + setupIPC() { this.appService.electron.ipcRenderer.on('pre-open-url', (event, data) => { this.spinnerService.showLoader(); @@ -104,10 +153,14 @@ export class ElectronService { console.log(data.status); } }); - this.appService.electron.ipcRenderer.on('open-url', (event, data) => { + this.appService.electron.ipcRenderer.on('open-url', async (event, data) => { if (data) { let url = data.split('#'); switch (url[0]) { + case 'sidequest://i/': + console.log(data); + this.installFromToken(url[1]); + break; case 'sidequest://unload/': this.adbService.uninstallAPK(url[1]); break; diff --git a/desktop-app/src/app/header/header.component.html b/desktop-app/src/app/header/header.component.html index fb19cdc..02cda53 100644 --- a/desktop-app/src/app/header/header.component.html +++ b/desktop-app/src/app/header/header.component.html @@ -259,6 +259,11 @@ Clear Failed    +
+ Clear All +
+   
diff --git a/desktop-app/src/app/process-bucket.service.ts b/desktop-app/src/app/process-bucket.service.ts index 55cd163..a432735 100644 --- a/desktop-app/src/app/process-bucket.service.ts +++ b/desktop-app/src/app/process-bucket.service.ts @@ -3,6 +3,7 @@ import { StatusBarService } from './status-bar.service'; export interface ProcessTask { key: string; name: string; + app_name?: string; icon: string; status?: string; running?: boolean; @@ -26,9 +27,9 @@ export class ProcessBucketService { this.processBucket(); } - addItem(name, resolve) { + addItem(name, resolve, app_name?) { const key = (window).require('uuid/v4')(); - const status = 'Waiting...'; + const status = (app_name ? app_name + ': ' : '') + 'Waiting...'; let icon = 'list'; let _name = 'app install'; switch (name) { @@ -67,15 +68,16 @@ export class ProcessBucketService { this.tasks.push({ key, name, + app_name, icon, status, resolve, }); - this.left_length = this.tasks.filter(t => t.status === 'Waiting...').length; + this.left_length = this.tasks.filter(t => !t.failed && !t.running && !t.cancelled && !t.succeeded).length; } async processBucket() { - const objects = this.tasks.filter(t => t.status === 'Waiting...'); + const objects = this.tasks.filter(t => !t.failed && !t.running && !t.cancelled && !t.succeeded); const timeout = new Promise(resolve => setTimeout(() => resolve(), 1000)); this.left_length = objects.length; if (objects.length) { @@ -85,6 +87,7 @@ export class ProcessBucketService { await task .resolve(task) .then(() => { + task.running = false; task.succeeded = true; if (!task.cancelled) { return timeout.then(() => this.processBucket()); @@ -92,7 +95,8 @@ export class ProcessBucketService { }) .catch(e => { task.running = false; - task.status = e.message ? e.message : e.code ? e.code : e.toString(); + task.status = + (task.app_name ? task.app_name + ': ' : '') + (e.message ? e.message : e.code ? e.code : e.toString()); task.failed = true; this.statusService.showStatus(task.status, true); if (!task.cancelled) { @@ -144,4 +148,8 @@ export class ProcessBucketService { clearFailed() { this.tasks = this.tasks.filter(t => !t.failed); } + clearAll() { + igin; + this.tasks = []; + } } diff --git a/desktop-app/src/app/webview.service.ts b/desktop-app/src/app/webview.service.ts index 9873a2b..5654aea 100644 --- a/desktop-app/src/app/webview.service.ts +++ b/desktop-app/src/app/webview.service.ts @@ -14,6 +14,7 @@ export class WebviewService { appService.setWebviewService(this); } setWebView(webView) { + console.log({ webView }); this.webView = webView; this.setupWebview(); } diff --git a/desktop-app/src/app/webview/webview.component.ts b/desktop-app/src/app/webview/webview.component.ts index b7cbf67..665b2c3 100644 --- a/desktop-app/src/app/webview/webview.component.ts +++ b/desktop-app/src/app/webview/webview.component.ts @@ -14,7 +14,6 @@ export class WebviewComponent implements OnInit { appService.resetTop(); webService.isWebviewOpen = true; appService.showBrowserBar = true; - appService.setTitle(''); } ngOnInit() {} diff --git a/electron/app.ts b/electron/app.ts index 529030e..cc32425 100644 --- a/electron/app.ts +++ b/electron/app.ts @@ -248,10 +248,11 @@ function setupApp() { const adb = new ADB(); ipcMain.on('download-url', async (event, { url, token, directory, filename }) => { - await download(url, path.join(directory, filename), stats => { + download(url, path.join(directory, filename), stats => { return event.sender.send('download-progress', { stats, token }); - }).catch(e => console.log(e)); - event.sender.send('download-url', { token }); + }) + .then(() => event.sender.send('download-url', { token })) + .catch(e => event.sender.send('download-url-fail', { e, token })); }); ipcMain.on('extract-file', async (event, { token, directory, filename }) => { extract( diff --git a/electron/download.ts b/electron/download.ts index 1dca5fd..b61e641 100644 --- a/electron/download.ts +++ b/electron/download.ts @@ -21,7 +21,9 @@ module.exports = function(url, path, progress) { callback(null, response); } }); - + request.on('error', function(err) { + callback(err); + }); request.setTimeout(TIMEOUT, function() { request.abort(); callback(new Error(`request timeout after ${TIMEOUT / 1000.0}s`)); @@ -31,7 +33,7 @@ module.exports = function(url, path, progress) { return new Promise(function(resolve, reject) { get(uri.href, (err, res) => { if (err) { - return console.log(err); + return reject(err); } const len = parseInt(res.headers['content-length'], 10); let downloaded = 0; diff --git a/electron/window.ts b/electron/window.ts index 241be25..3a089b8 100644 --- a/electron/window.ts +++ b/electron/window.ts @@ -59,6 +59,7 @@ export class AppWindow { show: !showAfterSetup, frame: false, webPreferences: { + webviewTag: true, nodeIntegration: true, }, }; diff --git a/package.json b/package.json index 02eeddb..366570b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "SideQuest", - "version": "0.10.3", + "version": "0.10.2", "description": "A open app store for mobile android based VR devices such as the Levovo Mirage, Oculus Go, Oculus Quest, Vive Focus.", "repository": "https://github.com/the-expanse/SideQuest.git", "license": "MIT", @@ -97,7 +97,7 @@ }, "devDependencies": { "@angular/cli": "^8.0.3", - "electron": "^8.2.0", + "electron": "^4.1.4", "electron-builder": "^22.4.0", "electron-notarize": "^0.1.1", "husky": "^2.3.0",