From 7e438b63c8ff7641647b1710e7fe792c2a4def2d Mon Sep 17 00:00:00 2001 From: Shane Harris Date: Sat, 30 Jul 2022 10:07:26 +0100 Subject: [PATCH] revamp of most screens complete, status bar still needs to be completed --- desktop-app/src/app/adb-client.service.ts | 36 +- desktop-app/src/app/app.component.html | 1 + desktop-app/src/app/app.component.scss | 57 +-- desktop-app/src/app/app.module.ts | 8 +- desktop-app/src/app/app.routes.ts | 6 +- desktop-app/src/app/app.service.ts | 64 ++- .../connection-status.component.html | 27 +- .../connection-status.component.scss | 21 +- .../src/app/content/content.component.html | 3 - .../src/app/content/content.component.scss | 29 -- .../src/app/content/content.component.spec.ts | 25 -- .../src/app/content/content.component.ts | 13 - .../current-task-item.component.html | 7 +- .../current-tasks.component.html | 35 +- .../current-tasks/current-tasks.component.ts | 2 +- .../src/app/files/files.component.html | 19 +- .../src/app/files/files.component.scss | 6 + desktop-app/src/app/files/files.component.ts | 2 +- .../header-banner.component.html | 33 ++ .../header-banner.component.scss | 70 +++ .../header-banner.component.spec.ts | 24 ++ .../header-banner/header-banner.component.ts | 184 ++++++++ .../src/app/header/header.component.html | 370 +++++++--------- .../src/app/header/header.component.scss | 36 +- .../src/app/header/header.component.ts | 1 + .../headset-settings.component.html | 400 +++++++++--------- .../headset-settings.component.ts | 2 +- .../package-item/package-item.component.html | 2 +- .../package-item/package-item.component.scss | 14 +- .../src/app/packages/packages.component.html | 114 +++-- .../src/app/packages/packages.component.scss | 3 + .../src/app/packages/packages.component.ts | 28 +- .../setup-guide/setup-guide.component.html | 68 ++- .../setup-guide/setup-guide.component.scss | 47 +- .../app/setup-guide/setup-guide.component.ts | 44 +- .../stream-options.component.html | 111 +++++ .../stream-options.component.scss | 0 .../stream-options.component.spec.ts | 24 ++ .../stream-options.component.ts | 36 ++ .../wireless-connection.component.html | 25 ++ .../wireless-connection.component.scss | 0 .../wireless-connection.component.spec.ts | 24 ++ .../wireless-connection.component.ts | 39 ++ desktop-app/src/assets/images/in-vr-logo.png | Bin 0 -> 59061 bytes desktop-app/src/styles.scss | 62 ++- electron/window.ts | 4 +- package.json | 3 +- yarn.lock | 5 + 48 files changed, 1471 insertions(+), 663 deletions(-) delete mode 100644 desktop-app/src/app/content/content.component.html delete mode 100644 desktop-app/src/app/content/content.component.scss delete mode 100644 desktop-app/src/app/content/content.component.spec.ts delete mode 100644 desktop-app/src/app/content/content.component.ts create mode 100644 desktop-app/src/app/header-banner/header-banner.component.html create mode 100644 desktop-app/src/app/header-banner/header-banner.component.scss create mode 100644 desktop-app/src/app/header-banner/header-banner.component.spec.ts create mode 100644 desktop-app/src/app/header-banner/header-banner.component.ts create mode 100644 desktop-app/src/app/stream-options/stream-options.component.html create mode 100644 desktop-app/src/app/stream-options/stream-options.component.scss create mode 100644 desktop-app/src/app/stream-options/stream-options.component.spec.ts create mode 100644 desktop-app/src/app/stream-options/stream-options.component.ts create mode 100644 desktop-app/src/app/wireless-connection/wireless-connection.component.html create mode 100644 desktop-app/src/app/wireless-connection/wireless-connection.component.scss create mode 100644 desktop-app/src/app/wireless-connection/wireless-connection.component.spec.ts create mode 100644 desktop-app/src/app/wireless-connection/wireless-connection.component.ts create mode 100644 desktop-app/src/assets/images/in-vr-logo.png diff --git a/desktop-app/src/app/adb-client.service.ts b/desktop-app/src/app/adb-client.service.ts index 7608c18..102bfe3 100644 --- a/desktop-app/src/app/adb-client.service.ts +++ b/desktop-app/src/app/adb-client.service.ts @@ -25,6 +25,10 @@ interface ADBDevice { providedIn: 'root', }) export class AdbClientService { + VR_APP_PACKAGE = 'quest.side.vr'; + notInstalled: boolean; + appVersion: string | null = null; + appVersionCode: string | null = null; ADB: any; adbPath: string; devicePackages: string[] = []; @@ -41,7 +45,9 @@ export class AdbClientService { localFiles: any; hasSynthRiderz: any; deviceIp: string; - wifiEnabled: boolean; + get wifiEnabled(): boolean { + return this.deviceSerial && this.deviceSerial.includes(':5555') && this.isReady; + } wifiHost: string; isBatteryCharging: boolean; batteryLevel: number; @@ -398,11 +404,18 @@ export class AdbClientService { } this.devices = devices; }) - .then(status => { + .then(async status => { this.updateConnectedStatus(); + if (this.isReady) { + try { + this.appVersion = await this.getAppVersion(false); + this.appVersionCode = await this.getAppVersion(true); + } catch {} + } requestAnimationFrame(this.connectedStatus.bind(this)); }) .catch(err => { + console.warn(err); alert( this.appService.os.platform() === 'win32' ? `It looks like there is something wrong with your install. @@ -419,6 +432,23 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u this.appService.electron.ipcRenderer.send('adb-command', { command, settings, uuid }); }); } + + copyToClipboard(value: string) { + const { clipboard } = (window as any).require('electron'); + clipboard.writeText(value); + } + async getAppVersion(isCode: boolean): Promise { + const versionInfo = await this.runAdbCommand('shell dumpsys package ' + this.VR_APP_PACKAGE); + this.notInstalled = versionInfo.includes('Unable to find package'); + const versionParts = versionInfo + .split('\n') + .map(x => x.trim()) + .filter(d => d.includes(isCode ? 'versionCode' : 'versionName')); + if (versionParts.length) { + return versionParts[0].split('=')[1].split(' minSdk')[0]; + } + return null; + } async setupAdb() { try { if (!this.isAdbDownloaded()) { @@ -1135,7 +1165,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u batteyInfo.split('\n ').forEach(element => { let attribute = element.replace(/\s/g, '').split(':'); const matcher = /true|false|[0-9].{0,}/g; - if (attribute[1].match(matcher)) { + if (attribute.length > 1 && attribute[1].match(matcher)) { try { attribute[1] = JSON.parse(attribute[1]); Object.assign(batteryObject, { [attribute[0]]: attribute[1] }); diff --git a/desktop-app/src/app/app.component.html b/desktop-app/src/app/app.component.html index dbe9c34..639151a 100644 --- a/desktop-app/src/app/app.component.html +++ b/desktop-app/src/app/app.component.html @@ -1,4 +1,5 @@ +
diff --git a/desktop-app/src/app/app.component.scss b/desktop-app/src/app/app.component.scss index e17c067..a9626c5 100644 --- a/desktop-app/src/app/app.component.scss +++ b/desktop-app/src/app/app.component.scss @@ -1,29 +1,29 @@ - -.add-to-drag { - width: 100%; - padding: 1em; - border: 2px dashed #3f3f3f; - text-align: center; -} -.spinner, -.spinner-drag { - position: fixed; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - z-index: 10; - display: none; -} -.spinner-background { - background-color: rgba(255, 255, 255, 0.5); - position: absolute; - left: 0; - top: 0; - height: 100%; - width: 100%; - border-top-left-radius: 40px; - z-index: 9; -} +// +//.add-to-drag { +// width: 100%; +// padding: 1em; +// border: 2px dashed #3f3f3f; +// text-align: center; +//} +//.spinner, +//.spinner-drag { +// position: fixed; +// top: 50%; +// left: 50%; +// transform: translate(-50%, -50%); +// z-index: 10; +// display: none; +//} +//.spinner-background { +// background-color: rgba(255, 255, 255, 0.5); +// position: absolute; +// left: 0; +// top: 0; +// height: 100%; +// width: 100%; +// border-top-left-radius: 40px; +// z-index: 9; +//} #mainWebView{ width: 100%; height: calc(100% - 35px); @@ -33,3 +33,8 @@ z-index: 8; background:#12152d; } + + +.app-container{ + padding-top: 35px; +} diff --git a/desktop-app/src/app/app.module.ts b/desktop-app/src/app/app.module.ts index 1f3abb3..92b8268 100644 --- a/desktop-app/src/app/app.module.ts +++ b/desktop-app/src/app/app.module.ts @@ -1,7 +1,6 @@ import { BrowserModule } from '@angular/platform-browser'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { AppComponent } from './app.component'; -import { ContentComponent } from './content/content.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MzButtonModule, MzCheckboxModule, MzModalModule, MzTooltipModule } from 'ngx-materialize'; @@ -29,10 +28,12 @@ import { VirtualScrollerModule } from 'ngx-virtual-scroller'; import { HeadsetSettingsComponent } from './headset-settings/headset-settings.component'; import { SetupGuideComponent } from './setup-guide/setup-guide.component'; import { ConnectionStatusComponent } from './connection-status/connection-status.component'; +import { HeaderBannerComponent } from './header-banner/header-banner.component'; +import { WirelessConnectionComponent } from './wireless-connection/wireless-connection.component'; +import { StreamOptionsComponent } from './stream-options/stream-options.component'; @NgModule({ declarations: [ AppComponent, - ContentComponent, HeaderComponent, StatusBarComponent, LoadingSpinnerComponent, @@ -50,6 +51,9 @@ import { ConnectionStatusComponent } from './connection-status/connection-status HeadsetSettingsComponent, SetupGuideComponent, ConnectionStatusComponent, + HeaderBannerComponent, + WirelessConnectionComponent, + StreamOptionsComponent, ], imports: [ BrowserModule, diff --git a/desktop-app/src/app/app.routes.ts b/desktop-app/src/app/app.routes.ts index 9cdc214..9730005 100644 --- a/desktop-app/src/app/app.routes.ts +++ b/desktop-app/src/app/app.routes.ts @@ -1,4 +1,3 @@ -import { SetupComponent } from './setup/setup.component'; import { Routes } from '@angular/router'; import { PackagesComponent } from './packages/packages.component'; import { WebviewComponent } from './webview/webview.component'; @@ -6,15 +5,18 @@ import { FilesComponent } from './files/files.component'; import { CurrentTasksComponent } from './current-tasks/current-tasks.component'; import { HeadsetSettingsComponent } from './headset-settings/headset-settings.component'; import { SetupGuideComponent } from './setup-guide/setup-guide.component'; +import { WirelessConnectionComponent } from './wireless-connection/wireless-connection.component'; +import { StreamOptionsComponent } from './stream-options/stream-options.component'; export const AppRoutes: Routes = [ - // { path: 'setup', component: SetupComponent }, { path: 'tasks', component: CurrentTasksComponent }, { path: 'packages', component: PackagesComponent }, { path: 'packages/:packageName', component: PackagesComponent }, { path: 'tools', component: HeadsetSettingsComponent }, { path: 'setup', component: SetupGuideComponent }, { path: 'webview', component: WebviewComponent }, + { path: 'wireless', component: WirelessConnectionComponent }, + { path: 'streaming', component: StreamOptionsComponent }, { path: 'device-files', component: FilesComponent }, { path: '**', component: WebviewComponent }, ]; diff --git a/desktop-app/src/app/app.service.ts b/desktop-app/src/app/app.service.ts index 8983eb7..8bd8ae9 100644 --- a/desktop-app/src/app/app.service.ts +++ b/desktop-app/src/app/app.service.ts @@ -3,6 +3,7 @@ import { LoadingSpinnerService } from './loading-spinner.service'; import { WebviewService } from './webview.service'; import { FilesComponent } from './files/files.component'; import { HeaderComponent } from './header/header.component'; +import { Router } from '@angular/router'; declare let __dirname, process; export enum FolderType { MAIN, @@ -26,14 +27,15 @@ export class AppService { showTaskActions: boolean; updateAvailable: boolean; showRepo: boolean; - isSetupOpen: boolean; - isFilesOpen: boolean; - isPackagesOpen: boolean; - isSettingsOpen: boolean; - isTasksOpen: boolean; + // isSetupOpen: boolean; + // isFilesOpen: boolean; + // isPackagesOpen: boolean; + // isSettingsOpen: boolean; + // isTasksOpen: boolean; hideNSFW: boolean; filesComponent: FilesComponent; appData: string; + apkPath: string; fs: any; path: any; nativeApp: any; @@ -62,7 +64,7 @@ export class AppService { downloadResolves: any = {}; extractResolves: any = {}; headerComponent: HeaderComponent; - constructor(private spinnerService: LoadingSpinnerService) { + constructor(private spinnerService: LoadingSpinnerService, private router: Router) { this.path = (window).require('path'); this.fs = (window).require('fs'); this.request = (window).require('request'); @@ -78,6 +80,8 @@ export class AppService { this.remote = (window).require('@electron/remote'); this.nativeApp = this.remote.app; this.appData = this.path.join(this.nativeApp.getPath('appData'), 'SideQuest'); + + this.apkPath = this.path.join(this.appData, 'experimental.apk'); this.exec = (window).require('child_process').exec; this.execSync = (window).require('child_process').execSync; this.uuidv4 = (window).require('uuid/v4'); @@ -123,6 +127,50 @@ export class AppService { } }); } + + isPageOpen(page: string) { + return this.router.url.includes(page); + } + + get pageTitle() { + if (this.isSettingsOpen) { + return 'Headset Settings'; + } else if (this.isFilesOpen) { + return 'File Manager'; + } else if (this.isPackagesOpen) { + return 'App Manager'; + } else if (this.isTasksOpen) { + return 'Task Manager'; + } else if (this.isSetupOpen) { + return 'Setup & Support'; + } else if (this.isWirelessOpen) { + return 'Wireless Connection'; + } else if (this.isStreamingOpen) { + return 'Streaming Options'; + } + } + get isSetupOpen() { + return this.isPageOpen('/setup'); + } + get isFilesOpen() { + return this.isPageOpen('/device-files'); + } + get isPackagesOpen() { + return this.isPageOpen('/packages'); + } + get isSettingsOpen() { + return this.isPageOpen('/tools'); + } + get isTasksOpen() { + return this.isPageOpen('/tasks'); + } + get isWirelessOpen() { + return this.isPageOpen('/wireless'); + } + get isStreamingOpen() { + return this.isPageOpen('/streaming'); + } + extract(path, options, callback, task?) { return this.extractFileAPI(options.dir, path, task).then(callback); } @@ -155,10 +203,6 @@ export class AppService { this.showCustomActions = false; this.showTaskActions = false; this.showRepo = false; - this.isFilesOpen = false; - this.isPackagesOpen = false; - this.isSettingsOpen = false; - this.isTasksOpen = false; } doesFileExist(path) { try { diff --git a/desktop-app/src/app/connection-status/connection-status.component.html b/desktop-app/src/app/connection-status/connection-status.component.html index 5075532..4a3614b 100644 --- a/desktop-app/src/app/connection-status/connection-status.component.html +++ b/desktop-app/src/app/connection-status/connection-status.component.html @@ -1,5 +1,5 @@ -
+

Connection Status

@@ -18,37 +18,22 @@ {{adb.devices.length && adb.deviceStatus === ConnectionStatus.UNAUTHORIZED?'Not Authorized.':'Device Authorized'}}

- - - - - - - - - - - - - - - - -
Fix It For Me
- -
-

+

{{(adb.diagnostics.usb && adb.diagnostics.usb.result_status=='diag-good' && adb.devices.length && adb.deviceStatus !== ConnectionStatus.UNAUTHORIZED)?'You\'re all set!':'So how do I fix it?'}}

Here are some solutions we have come across related to this problem.
Please try the recommendations here before following tutorials online, this information is always the most up to date.
+
{{(adb.diagnostics.usb && adb.diagnostics.usb.result_status=='diag-good' && adb.devices.length && adb.deviceStatus !== ConnectionStatus.UNAUTHORIZED) ? "Check for a popup to accept inside the headset.":adb.diagnostics.usb ? adb.diagnostics.usb.recommendation : ''}}
+
+
Close
+
diff --git a/desktop-app/src/app/connection-status/connection-status.component.scss b/desktop-app/src/app/connection-status/connection-status.component.scss index fda622c..f570a05 100644 --- a/desktop-app/src/app/connection-status/connection-status.component.scss +++ b/desktop-app/src/app/connection-status/connection-status.component.scss @@ -13,7 +13,7 @@ z-index: 200; top: 0px; left: 0px; - right: 270px; + right: 0px; bottom: 0px; background: #111124; box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px; @@ -22,7 +22,7 @@ .right-side-diagnostics{ position: absolute; - width: 245px; + width: 545px; top: 56px; right: 20px; } @@ -51,3 +51,20 @@ margin-left: 5px; vertical-align: middle; } + +@media only screen and (max-width: 1448px){ + + + .right-side-diagnostics{ + width: 445px; + } +} + + +@media only screen and (max-width: 1279px){ + + + .right-side-diagnostics{ + width: 345px; + } +} diff --git a/desktop-app/src/app/content/content.component.html b/desktop-app/src/app/content/content.component.html deleted file mode 100644 index f0ce951..0000000 --- a/desktop-app/src/app/content/content.component.html +++ /dev/null @@ -1,3 +0,0 @@ -
- -
diff --git a/desktop-app/src/app/content/content.component.scss b/desktop-app/src/app/content/content.component.scss deleted file mode 100644 index ba49a00..0000000 --- a/desktop-app/src/app/content/content.component.scss +++ /dev/null @@ -1,29 +0,0 @@ -.body-content { - height: calc(100% - 200px); - width: 100%; - position: relative; - overflow: auto; -} - -.content { - padding-top: 1em; - border-bottom-right-radius: 5px; - border-bottom-left-radius: 5px; - transition: background-color 350ms ease-out; -} -/*.content-dark-theme{*/ - /*background-color:#211c23;*/ -/*}*/ -/*.content-light-theme{*/ - /*background-color:#f0f0f0;*/ -/*}*/ -.loader-initial { - border: 16px solid #f3f3f3; /* Light grey */ - border-top: 16px solid #0094ca; /* Blue */ - border-radius: 50%; - width: 120px; - height: 120px; - animation: spin 2s linear infinite; - display: inline-block; - margin-bottom: 20px; -} diff --git a/desktop-app/src/app/content/content.component.spec.ts b/desktop-app/src/app/content/content.component.spec.ts deleted file mode 100644 index 7ad6c91..0000000 --- a/desktop-app/src/app/content/content.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ContentComponent } from './content.component'; - -describe('ContentComponent', () => { - let component: ContentComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ ContentComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(ContentComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/desktop-app/src/app/content/content.component.ts b/desktop-app/src/app/content/content.component.ts deleted file mode 100644 index a9fefa4..0000000 --- a/desktop-app/src/app/content/content.component.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import { AppService } from '../app.service'; - -@Component({ - selector: 'app-content', - templateUrl: './content.component.html', - styleUrls: ['./content.component.scss'], -}) -export class ContentComponent implements OnInit { - constructor(public appService: AppService) {} - - ngOnInit() {} -} 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 4d967b5..77b6392 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 @@ -5,6 +5,9 @@ position="bottom" [innerHTML]="'' + task.icon + '' + task.status">
-
- close +
+ close +
+
+
diff --git a/desktop-app/src/app/current-tasks/current-tasks.component.html b/desktop-app/src/app/current-tasks/current-tasks.component.html index 72471b9..760d3b4 100644 --- a/desktop-app/src/app/current-tasks/current-tasks.component.html +++ b/desktop-app/src/app/current-tasks/current-tasks.component.html @@ -1,15 +1,30 @@ - - - -
-
- -
No tasks running. -

-
Back Home
+
+
Manage tasks for downloading, transferring and installing to your headset.
+
+
+ Clear Done +
+
+ Retry Failed +
+
+ Clear Failed +
+
+ Clear All +
+
+
+
+ No tasks running... +
-
+
diff --git a/desktop-app/src/app/current-tasks/current-tasks.component.ts b/desktop-app/src/app/current-tasks/current-tasks.component.ts index 632b149..04e080e 100644 --- a/desktop-app/src/app/current-tasks/current-tasks.component.ts +++ b/desktop-app/src/app/current-tasks/current-tasks.component.ts @@ -13,7 +13,7 @@ export class CurrentTasksComponent implements OnInit { this.appService.resetTop(); appService.webService.isWebviewOpen = false; this.appService.showTaskActions = true; - appService.isTasksOpen = true; + // appService.isTasksOpen = true; } ngOnInit() { diff --git a/desktop-app/src/app/files/files.component.html b/desktop-app/src/app/files/files.component.html index 953ecf6..30e4e0e 100644 --- a/desktop-app/src/app/files/files.component.html +++ b/desktop-app/src/app/files/files.component.html @@ -1,6 +1,6 @@ -
+

You are not currently connected.

@@ -21,6 +21,18 @@
{{this.currentPath}}
+ +
+ + + + +
+ +
+
diff --git a/desktop-app/src/app/header-banner/header-banner.component.scss b/desktop-app/src/app/header-banner/header-banner.component.scss new file mode 100644 index 0000000..941a85b --- /dev/null +++ b/desktop-app/src/app/header-banner/header-banner.component.scss @@ -0,0 +1,70 @@ +.banner-container{ + background: linear-gradient(89.97deg, #1A1D3C 0.02%, #2A3067 99.96%); + //background-size: cover; + height: 170px; + width: 100%; + position: relative; + top: 35px; + padding-right: 46px; +} +.back-button{ + position: absolute; + height: 21px; + left: 46px; + top: 32px; + font-style: normal; + font-weight: 400; + font-size: 18px; + line-height: 21px; + align-items: center; + text-align: center; + color: #B9BBD2; + i{ + vertical-align: text-bottom; + } +} +.title{ + position: absolute; + height: 35px; + left: 46px; + top: 77px; + font-style: normal; + font-weight: 500; + font-size: 30px; + line-height: 35px; + display: flex; + align-items: center; + + color: #FFFFFF; +} +.in-vr-title, .in-vr-installed{ + color: white; + font-style: normal; + font-weight: 500; + font-size: 20px; + line-height: 23px; + margin-top: 24px; + margin-bottom: 10px; +} +.in-vr-installed{ + margin-top: 10px; +} +.in-vr-description{ + font-style: normal; + font-weight: 400; + font-size: 14px; + max-width: 300px; + line-height: 16px; + margin-bottom: 10px; +} +.in-vr-installed, .in-vr-description{ + color: #B9BBD2; +} +.in-vr-installer img{ + margin-top: 10px; + margin-right: 19px; +} +.done-icon{ + vertical-align: text-bottom; + font-size: 1.5em; +} diff --git a/desktop-app/src/app/header-banner/header-banner.component.spec.ts b/desktop-app/src/app/header-banner/header-banner.component.spec.ts new file mode 100644 index 0000000..724f92a --- /dev/null +++ b/desktop-app/src/app/header-banner/header-banner.component.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HeaderBannerComponent } from './header-banner.component'; + +describe('HeaderBannerComponent', () => { + let component: HeaderBannerComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [HeaderBannerComponent], + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(HeaderBannerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/desktop-app/src/app/header-banner/header-banner.component.ts b/desktop-app/src/app/header-banner/header-banner.component.ts new file mode 100644 index 0000000..9fa72e4 --- /dev/null +++ b/desktop-app/src/app/header-banner/header-banner.component.ts @@ -0,0 +1,184 @@ +import { Component, OnInit } from '@angular/core'; +import { AppService } from '../app.service'; +import { AdbClientService } from '../adb-client.service'; + +const ADBErrors = { + INSTALL_FAILED_INSUFFICIENT_STORAGE: `Your headset does not have enough storage to install this app. Try removing some apps and trying again.`, + INSTALL_FAILED_USER_RESTRICTED: `The install was cancelled, please try again.`, + INSTALL_FAILED_NO_MATCHING_ABIS: `The install failed because the app is not compatible with this device, is this a supported VR headset?`, + INSTALL_FAILED_VERSION_DOWNGRADE: `The installed failed because the app is already installed and the installed version is newer than this version.`, + INSTALL_FAILED_VERIFICATION_FAILURE: `The installed failed because the app is possibly corrupt. Try restarting your headset just in-case.`, + INSTALL_FAILED_UPDATE_INCOMPATIBLE: `The installed failed because the new version is signed differently. Try uninstalling first.`, + INSTALL_FAILED_OLDER_SDK: `The installed failed because the app is intended for a newer version of Android than is on the headset.`, + INSTALL_FAILED_TEST_ONLY: `The installed failed because I'm a teapot.`, + INSTALL_FAILED_CONFLICTING_PROVIDER: `The installed failed for an unknown reason: CONFLICTING_PROVIDER`, +}; +@Component({ + selector: 'app-header-banner', + templateUrl: './header-banner.component.html', + styleUrls: ['./header-banner.component.scss'], +}) +export class HeaderBannerComponent implements OnInit { + apkDownloadPath: string; + isLoading: boolean; + isOutOfDate: boolean; + // the latest available version of the in-headset app + private latestAppVersion: string | null = null; + constructor(private appService: AppService, public adb: AdbClientService) {} + + ngOnInit() { + setInterval(() => { + this.getLatestApk(); + }, 120000); + this.getLatestApk(); + } + + setOutOfDate() { + // any time we don't know the currently installed app version or we don't know the latest available version, treat it as up to date + if (this.latestAppVersion !== null && this.adb.appVersionCode !== null && this.adb.appVersionCode !== undefined) { + if (Number(this.adb.appVersionCode) < Number(this.latestAppVersion)) { + this.isOutOfDate = true; + return; + } + } + this.isOutOfDate = false; + } + + async getLatestApk() { + const { apk, version } = await this.getExperimentalAPK(); + if (apk.length) { + this.latestAppVersion = version; + this.setOutOfDate(); + this.apkDownloadPath = apk[0].browser_download_url; + } + } + + async getExperimentalAPK() { + const json = await fetch('https://api.github.com/repos/SideQuestVR/Lite/releases/latest'); + const r = await json.json(); + r.assets.reverse(); + const apk = r.assets.filter(a => a.name.split('.').pop() === 'apk'); + const versionFile = r.assets.filter(a => a.name.split('.').pop() === 'versionCode'); + let version; + if (versionFile.length > 0) { + version = versionFile[0].name.split('.')[0]; + } + return { apk, version }; + } + + async downloadExperimentalAPK() { + if (!this.apkDownloadPath) { + return Promise.reject('Could not download latest apk, please try again!'); + } + console.log('downloadExperimentalAPK', this.apkDownloadPath); + return new Promise((resolve, reject) => { + const requestOptions = { + timeout: 30000, + 'User-Agent': this.appService.getUserAgent(), + }; + this.appService + .request(this.apkDownloadPath, requestOptions) + .on('error', error => { + console.log(`Request Error ${error}`); + reject(error); + }) + .on('progress', state => {}) + .on('end', () => { + return resolve(); + }) + .pipe(this.appService.fs.createWriteStream(this.appService.path.join(this.appService.appData, 'experimental.apk'))); + }); + } + + useBundledAPK() { + const sourcesPath = this.appService.getPlatformToolsSeedPath().replace('platform-tools', 'experimental.apk'); + console.log(sourcesPath); + if (sourcesPath == null) { + console.error('Unable to locate experimental apk! Try reinstalling sidequest.'); + throw new Error(`Unable to locate experimental apk! Try reinstalling sidequest.`); + } + this.appService.fs.copyFileSync( + this.appService.path.join(sourcesPath), + this.appService.path.join(this.appService.appData, 'experimental.apk') + ); + } + + async install() { + try { + const oldVersion = this.adb.appVersionCode || null; + let telemEvent; + if (this.isOutOfDate) { + telemEvent = 'upgrade'; + } else if (this.adb.notInstalled) { + telemEvent = 'new'; + } else { + telemEvent = 'reinstall'; + } + // this.telemetry.telemetry({ event: 'install-sidequest-apk', installType: telemEvent, oldVersion }); + this.isLoading = true; + try { + await this.getLatestApk(); + await this.downloadExperimentalAPK(); + } catch (e) { + // this.toast.show('Failed to download updated SQ apk, falling back to bundled apk. Are you online?', true); + console.warn(e); + this.useBundledAPK(); + } + await this.adb.runAdbCommand('push "' + this.appService.apkPath + '" /data/local/tmp/sq.apk'); + await this.adb.runAdbCommand('shell pm install -r /data/local/tmp/sq.apk'); + // this.toast.show('SideQuest installed to headset!'); + // this.showConfetti = true; + this.adb.appVersionCode = await this.adb.getAppVersion(true); + // this.telemetry.telemetry({ event: 'install-sidequest-apk-success', + // installType: telemEvent, oldVersion, newVersion: this.adb.appVersionCode || null}); + // setTimeout(() => { + // this.showConfetti = false; + // }, 8000); + } catch (e) { + console.log(e); + await this.handleInstallError(e); + } finally { + this.isLoading = false; + } + } + + async handleInstallError(e) { + let err; + for (const error of Object.keys(ADBErrors)) { + if (e.toString().includes(error)) { + err = error; + } + } + if (err) { + if (err === 'INSTALL_FAILED_VERSION_DOWNGRADE') { + await this.uninstall(); + await this.install(); + } else if (err === 'INSTALL_FAILED_UPDATE_INCOMPATIBLE') { + // TODO need to show a better error here and confirm with the user to uninstall first. + await this.uninstall(); + await this.install(); + } else { + // this.telemetry.telemetry({event: 'install-error-adb', errorMessage: ADBErrors[err]}); + // this.toast.show(ADBErrors[err], true); + } + } else { + // this.telemetry.telemetry({event: 'install-error-unhandled', errorMessage: e.toString()}); + // this.toast.show(e, true); + } + } + + async uninstall() { + await this.adb.runAdbCommand('uninstall ' + this.adb.VR_APP_PACKAGE); + } + + async userUninstall() { + try { + // await this.telemetry.telemetry({event: 'user-uninstall'}); + await this.uninstall(); + // await this.telemetry.telemetry({event: 'user-uninstall-success'}); + } catch (e) { + // await this.telemetry.telemetry({event: 'user-uninstall-failed', error: e.toString()}); + // this.toast.show(e, true); + } + } +} diff --git a/desktop-app/src/app/header/header.component.html b/desktop-app/src/app/header/header.component.html index 873092e..ec17f86 100644 --- a/desktop-app/src/app/header/header.component.html +++ b/desktop-app/src/app/header/header.component.html @@ -45,28 +45,13 @@ routerLink="/webview">publicGo to url

editManage

-
addAdd Current

+ >editManage Favs

{{favourite.name}}

-
- - - - - - - - - - -
arrow_forward - live_tv - @@ -128,6 +113,12 @@ tooltip="Device settings & tools"> build + + contact_support + + @@ -156,11 +147,11 @@
- + + + + +
@@ -174,42 +165,6 @@ (click)="webService.loadUrl('https://synthriderz.com/beatmaps/recent')">    
-
- - - - - - add - - -
-
-
- Clear Done -
-    -
- Retry Failed -
-    -
- Clear Failed -
-    -
- Clear All -
-    - -