From cfcf2f08903cf9de6acfbd3e327266d123dc4f5d Mon Sep 17 00:00:00 2001 From: Max Myers Date: Tue, 19 Oct 2021 14:26:19 -0400 Subject: [PATCH] Add test/local environment configurations and fix #147 --- desktop-app/angular.json | 69 +++++++++++++++++++ desktop-app/package.json | 8 ++- desktop-app/src/app/app.component.html | 4 +- desktop-app/src/app/app.component.ts | 4 ++ .../src/app/header/header.component.html | 8 +-- .../src/app/header/header.component.ts | 21 +++++- desktop-app/src/app/webview.service.ts | 3 +- .../src/environments/environment.local.ts | 10 +++ .../src/environments/environment.prod.ts | 8 ++- .../src/environments/environment.test.ts | 10 +++ .../src/environments/environment.test2.ts | 10 +++ desktop-app/src/environments/environment.ts | 8 ++- electron/app.ts | 10 +-- electron/env-config.ts | 36 ++++++++++ package.json | 10 +++ 15 files changed, 203 insertions(+), 16 deletions(-) create mode 100644 desktop-app/src/environments/environment.local.ts create mode 100644 desktop-app/src/environments/environment.test.ts create mode 100644 desktop-app/src/environments/environment.test2.ts create mode 100644 electron/env-config.ts diff --git a/desktop-app/angular.json b/desktop-app/angular.json index 351ab23..acaf4cc 100644 --- a/desktop-app/angular.json +++ b/desktop-app/angular.json @@ -49,6 +49,57 @@ "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true + }, + "test": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.test.ts" + } + ], + "optimization": false, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": false, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": false + }, + "test2": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.test2.ts" + } + ], + "optimization": false, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": false, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": false + }, + "local": { + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.local.ts" + } + ], + "optimization": false, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": false, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": false } } }, @@ -60,6 +111,15 @@ "configurations": { "production": { "browserTarget": "desktop-app:build:production" + }, + "test": { + "browserTarget": "desktop-app:build:test" + }, + "test2": { + "browserTarget": "desktop-app:build:test2" + }, + "local": { + "browserTarget": "desktop-app:build:local" } } }, @@ -113,6 +173,15 @@ "configurations": { "production": { "devServerTarget": "desktop-app:serve:production" + }, + "test": { + "devServerTarget": "desktop-app:serve:test" + }, + "test2": { + "devServerTarget": "desktop-app:serve:test2" + }, + "local": { + "devServerTarget": "desktop-app:serve:local" } } }, diff --git a/desktop-app/package.json b/desktop-app/package.json index d2ab95b..6e2e2fd 100644 --- a/desktop-app/package.json +++ b/desktop-app/package.json @@ -4,10 +4,16 @@ "scripts": { "ng": "ng", "start": "ng serve", + "start:test": "ng serve -c test", + "start:test2": "ng serve -c test2", + "start:local": "ng serve -c local", "build": "ng build", "test": "ng test", "lint": "ng lint", - "e2e": "ng e2e" + "e2e": "ng e2e", + "e2e:test": "ng e2e -c test", + "e2e:local": "ng e2e -c test2", + "e2e:test2": "ng e2e -c local" }, "private": true, "dependencies": { diff --git a/desktop-app/src/app/app.component.html b/desktop-app/src/app/app.component.html index fc1899e..2886e7b 100644 --- a/desktop-app/src/app/app.component.html +++ b/desktop-app/src/app/app.component.html @@ -5,7 +5,7 @@ - + @@ -21,7 +21,7 @@

Copy To Clipboard


-
Open Service Desk


+
Open Service Desk


diff --git a/desktop-app/src/app/app.component.ts b/desktop-app/src/app/app.component.ts index 87ab539..4eb8093 100644 --- a/desktop-app/src/app/app.component.ts +++ b/desktop-app/src/app/app.component.ts @@ -6,6 +6,8 @@ import { WebviewService } from './webview.service'; import { DragAndDropService } from './drag-and-drop.service'; import { ElectronService } from './electron.service'; import { AdbClientService } from './adb-client.service'; +import { environment } from '../environments/environment'; + @Component({ selector: 'app-root', templateUrl: './app.component.html', @@ -18,6 +20,8 @@ export class AppComponent implements OnInit, AfterViewInit { helpStatus: string; extraHelpStatus: string; devMode: boolean; + webUrl = environment.configuration.web_url; + shortenerUrl = environment.configuration.shortenerUrl; constructor( private spinnerService: LoadingSpinnerService, public statusService: StatusBarService, diff --git a/desktop-app/src/app/header/header.component.html b/desktop-app/src/app/header/header.component.html index 83cf54b..2320368 100644 --- a/desktop-app/src/app/header/header.component.html +++ b/desktop-app/src/app/header/header.component.html @@ -79,7 +79,7 @@
homeHome

homeHome

arrow_drop_down - arrow_back @@ -312,7 +312,7 @@ - + diff --git a/desktop-app/src/app/header/header.component.ts b/desktop-app/src/app/header/header.component.ts index 9e3ceac..c5e9801 100644 --- a/desktop-app/src/app/header/header.component.ts +++ b/desktop-app/src/app/header/header.component.ts @@ -10,6 +10,8 @@ import { DragAndDropService } from '../drag-and-drop.service'; import { Router } from '@angular/router'; import { ProcessBucketService } from '../process-bucket.service'; import { Subscription } from 'rxjs/Subscription'; +import { environment } from '../../environments/environment'; + interface ReplaceText { key: string; value: string; @@ -45,6 +47,7 @@ export class HeaderComponent implements OnInit { adbCommandToRun: string; osPlatform: string; saveLogcatPath: string; + webUrl = environment.configuration.web_url; favourites: { browserFavourites: FavouriteItem[]; fileFavourites: FavouriteItem[]; @@ -98,7 +101,8 @@ export class HeaderComponent implements OnInit { public statusService: StatusBarService, public beatonService: BeatOnService, public dragAndDropService: DragAndDropService, - public processService: ProcessBucketService + public processService: ProcessBucketService, + private router: Router ) { this.osPlatform = this.appService.os.platform(); console.log('Platform: ' + this.osPlatform); @@ -107,6 +111,19 @@ export class HeaderComponent implements OnInit { this.resetFavourites('commandFavourites'); this.appService.headerComponent = this; } + doBack() { + if ( + this.appService.isTasksOpen || + this.appService.isFilesOpen || + this.appService.isPackagesOpen || + this.appService.isSettingsOpen + ) { + this.router.navigateByUrl('/webview'); + return; + } else { + this.webService.back(); + } + } resetFavourites(type: string) { let defaultFavs; switch (type) { @@ -182,7 +199,7 @@ export class HeaderComponent implements OnInit { } updateAvailable() { - this.appService.opn('https://sidequestvr.com/download'); + this.appService.opn(`${environment.configuration.web_url || 'https://sidequestvr.com'}/download`); } startLogcat() { diff --git a/desktop-app/src/app/webview.service.ts b/desktop-app/src/app/webview.service.ts index dbbacc1..5837d39 100644 --- a/desktop-app/src/app/webview.service.ts +++ b/desktop-app/src/app/webview.service.ts @@ -1,5 +1,6 @@ import { Injectable, isDevMode } from '@angular/core'; import { AppService } from './app.service'; +import { environment } from '../environments/environment'; @Injectable({ providedIn: 'root', @@ -7,7 +8,7 @@ import { AppService } from './app.service'; export class WebviewService { webView: any; isWebviewOpen: boolean; - currentAddress: string = 'https://sidequestvr.com'; + currentAddress: string = environment.configuration.web_url || 'https://sidequestvr.com'; isWebviewLoading: boolean = false; isLoaded = () => {}; constructor(private appService: AppService) { diff --git a/desktop-app/src/environments/environment.local.ts b/desktop-app/src/environments/environment.local.ts new file mode 100644 index 0000000..f0af48a --- /dev/null +++ b/desktop-app/src/environments/environment.local.ts @@ -0,0 +1,10 @@ +export const environment = { + production: false, + configuration: { + web_url: 'https://sidequestvr.local', + ws_url: 'wss://ws.sidetestvr.local', + http_url: 'https://api.sidetestvr.local', + cdnUrl: 'https://cdn.sidetestvr.local', + shortenerUrl: 'https://links.sidetestvr.local', + }, +}; diff --git a/desktop-app/src/environments/environment.prod.ts b/desktop-app/src/environments/environment.prod.ts index d121e4b..d6028b8 100644 --- a/desktop-app/src/environments/environment.prod.ts +++ b/desktop-app/src/environments/environment.prod.ts @@ -1,4 +1,10 @@ export const environment = { production: true, - safeSideApiUrl: 'https://sdq.st', + configuration: { + web_url: 'https://sidequestvr.com', + ws_url: 'wss://ws.sidequestvr.com', + http_url: 'https://api.sidequestvr.com', + cdnUrl: 'https://cdn.sidequestvr.com', + shortenerUrl: 'https://sdq.st', + }, }; diff --git a/desktop-app/src/environments/environment.test.ts b/desktop-app/src/environments/environment.test.ts new file mode 100644 index 0000000..592067f --- /dev/null +++ b/desktop-app/src/environments/environment.test.ts @@ -0,0 +1,10 @@ +export const environment = { + production: false, + configuration: { + web_url: 'https://sidetestvr.com', + ws_url: 'wss://ws.sidetestvr.com', + http_url: 'https://api.sidetestvr.com', + cdnUrl: 'https://cdn.sidetestvr.com', + shortenerUrl: 'https://links.sidetestvr.com', + }, +}; diff --git a/desktop-app/src/environments/environment.test2.ts b/desktop-app/src/environments/environment.test2.ts new file mode 100644 index 0000000..7579214 --- /dev/null +++ b/desktop-app/src/environments/environment.test2.ts @@ -0,0 +1,10 @@ +export const environment = { + production: false, + configuration: { + web_url: 'https://test.side.quest', + ws_url: 'wss://testws.side.quest', + http_url: 'https://api.sidequestvr.com', + cdnUrl: 'https://cdn.sidequestvr.com', + shortenerUrl: 'https://sdq.st', + }, +}; diff --git a/desktop-app/src/environments/environment.ts b/desktop-app/src/environments/environment.ts index 40f4f17..e2654d7 100644 --- a/desktop-app/src/environments/environment.ts +++ b/desktop-app/src/environments/environment.ts @@ -4,7 +4,13 @@ export const environment = { production: false, - safeSideApiUrl: 'https://sdq.st', + configuration: { + web_url: 'https://sidequestvr.com', + ws_url: 'wss://ws.sidequestvr.com', + http_url: 'https://api.sidequestvr.com', + cdnUrl: 'https://cdn.sidequestvr.com', + shortenerUrl: 'https://sdq.st', + }, }; /* diff --git a/electron/app.ts b/electron/app.ts index 808cf58..46606b5 100644 --- a/electron/app.ts +++ b/electron/app.ts @@ -1,6 +1,8 @@ import { app, protocol, ipcMain, Menu, MenuItemConstructorOptions, BrowserWindow, shell } from 'electron'; import { StateStorage, EnvironmentConfig } from './state-storage'; import { AppWindow } from './window'; +import { getEnvCfg } from './env-config'; + const path = require('path'); const { autoUpdater } = require('electron-updater'); const download = require('./download'); @@ -32,7 +34,7 @@ class ADB { } async checkAPK(updateStatus: (string) => void, filePath: string): Promise { const hash = await this.computeFileHash(updateStatus, filePath); - const url = `https://sdq.st/check-app-hash/${hash}`; + const url = `${getEnvCfg().shortenerUrl || 'https://sdq.st'}/check-app-hash/${hash}`; updateStatus('Checking APK against blacklist...'); return new Promise((resolve, reject) => { let options = { @@ -41,7 +43,7 @@ class ADB { headers: { Accept: 'application/json', 'Content-Type': 'application/json', - Origin: 'https://sidequestvr.com', + Origin: getEnvCfg().web_url, }, rejectUnauthorized: process.env.NODE_ENV !== 'dev', }; @@ -102,12 +104,12 @@ class ADB { } installFromToken(token, cb, ecb) { let options = { - url: 'https://api.sidequestvr.com/install-from-key', + url: `${getEnvCfg().http_url || 'https://api.sidequestvr.com'}/install-from-key`, method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', - Origin: 'https://sidequestvr.com', + Origin: getEnvCfg().web_url || 'https://sidequestvr.com', }, rejectUnauthorized: process.env.NODE_ENV !== 'dev', json: { token: token }, diff --git a/electron/env-config.ts b/electron/env-config.ts new file mode 100644 index 0000000..51d72fc --- /dev/null +++ b/electron/env-config.ts @@ -0,0 +1,36 @@ +export function getEnvCfg() { + switch (process.env['SQ_ENV_CFG']) { + case 'test': + return { + web_url: 'https://sidetestvr.com', + ws_url: 'wss://ws.sidetestvr.com', + http_url: 'https://api.sidetestvr.com', + cdnUrl: 'https://cdn.sidetestvr.com', + shortenerUrl: 'https://links.sidetestvr.com', + }; + case 'test2': + return { + web_url: 'https://test.side.quest', + ws_url: 'wss://testws.side.quest', + http_url: 'https://testapi.side.quest', + cdnUrl: 'https://testcdn.sidequestvr.com', + shortenerUrl: 'https://testlinks.side.quest', + }; + case 'local': + return { + web_url: 'https://sidequestvr.local', + ws_url: 'wss://ws.sidetestvr.local', + http_url: 'https://api.sidetestvr.local', + cdnUrl: 'https://cdn.sidetestvr.local', + shortenerUrl: 'https://links.sidetestvr.local', + }; + default: + return { + web_url: 'https://sidequestvr.com', + ws_url: 'wss://ws.sidequestvr.com', + http_url: 'https://api.sidequestvr.com', + cdnUrl: 'https://cdn.sidequestvr.com', + shortenerUrl: 'https://sdq.st', + }; + } +} diff --git a/package.json b/package.json index 5d8f218..dd75b75 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,20 @@ "scripts": { "concurrently": "concurrently", "start": "concurrently \"yarn electron-build && yarn platform-tools && wait-on http-get://localhost:4205/ && cross-env NODE_ENV=dev electron .\" \"cd desktop-app && ng serve --port 4205\"", + "start:test": "concurrently \"yarn electron-build && yarn platform-tools && wait-on http-get://localhost:4205/ && cross-env NODE_ENV=dev SQ_ENV_CFG=test electron .\" \"cd desktop-app && ng serve -c test --port 4205\"", + "start:test2": "concurrently \"yarn electron-build && yarn platform-tools && wait-on http-get://localhost:4205/ && cross-env NODE_ENV=dev SQ_ENV_CFG=test2 electron .\" \"cd desktop-app && ng serve -c test2 --port 4205\"", + "start:local": "concurrently \"yarn electron-build && yarn platform-tools && wait-on http-get://localhost:4205/ && cross-env NODE_ENV=dev SQ_ENV_CFG=local electron .\" \"cd desktop-app && ng serve -c local --port 4205\"", "postinstall": "electron-builder install-app-deps && cd desktop-app && yarn install", "dist": "yarn electron-build && yarn platform-tools && yarn app-build && electron-builder", "angular": "cd desktop-app && ng serve --port 4205", + "angular:test": "cd desktop-app && ng serve -c test --port 4205", + "angular:test2": "cd desktop-app && ng serve -c test2 --port 4205", + "angular:local": "cd desktop-app && ng serve -c local --port 4205", "electron-dev": "yarn platform-tools && cross-env NODE_ENV=dev electron .", + "electron-dev:test": "yarn platform-tools && cross-env NODE_ENV=dev SQ_ENV_CFG=test electron .", + "electron-dev:test2": "yarn platform-tools && cross-env NODE_ENV=dev SQ_ENV_CFG=test2 electron .", + "electron-dev:local": "yarn platform-tools && cross-env NODE_ENV=dev SQ_ENV_CFG=local electron .", + "electron": "yarn electron-build && yarn electron-dev", "app-build": "cd desktop-app && ng build --prod --aot && cd ..", "platform-tools": "node build-electron/platform-tools.js",