Merge pull request #152 from SideQuestVR/open_new_window_links_system_browser

Electron upgrade and several other fixes
This commit is contained in:
emulamer
2021-11-19 13:02:42 -05:00
committed by GitHub
23 changed files with 2336 additions and 924 deletions
+4 -2
View File
@@ -7,10 +7,12 @@ jobs:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v2
with: with:
fetch-depth: 1 fetch-depth: 1
- uses: actions/setup-node@v1 - uses: actions/setup-node@v2
with:
node-version: '14'
- name: "Install dependencies" - name: "Install dependencies"
run: yarn run: yarn
- name: "Build application" - name: "Build application"
+69
View File
@@ -49,6 +49,57 @@
"extractLicenses": true, "extractLicenses": true,
"vendorChunk": false, "vendorChunk": false,
"buildOptimizer": true "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": { "configurations": {
"production": { "production": {
"browserTarget": "desktop-app:build: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": { "configurations": {
"production": { "production": {
"devServerTarget": "desktop-app:serve:production" "devServerTarget": "desktop-app:serve:production"
},
"test": {
"devServerTarget": "desktop-app:serve:test"
},
"test2": {
"devServerTarget": "desktop-app:serve:test2"
},
"local": {
"devServerTarget": "desktop-app:serve:local"
} }
} }
}, },
+7 -1
View File
@@ -4,10 +4,16 @@
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve",
"start:test": "ng serve -c test",
"start:test2": "ng serve -c test2",
"start:local": "ng serve -c local",
"build": "ng build", "build": "ng build",
"test": "ng test", "test": "ng test",
"lint": "ng lint", "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, "private": true,
"dependencies": { "dependencies": {
+10 -1
View File
@@ -372,11 +372,16 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
}); });
} }
isAdbDownloaded() { isAdbDownloaded() {
try {
let downloaded = true; let downloaded = true;
if (!this.doesFileExist(this.adbPath)) { if (!this.doesFileExist(this.adbPath)) {
return false; return false;
} }
let source_files = this.appService.fs.readdirSync(this.appService.path.join(process.cwd(), 'build', 'platform-tools'));
let source_files = this.appService.fs.readdirSync(this.appService.getPlatformToolsSeedPath());
if (source_files === null) {
return false;
}
let dest_files = this.appService.fs.readdirSync(this.adbPath); let dest_files = this.appService.fs.readdirSync(this.adbPath);
source_files.forEach(d => { source_files.forEach(d => {
if (dest_files.indexOf(d) === -1) { if (dest_files.indexOf(d) === -1) {
@@ -384,6 +389,10 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
} }
}); });
return downloaded; // this.doesFileExist(this.appService.path.join(this.adbPath, this.getAdbBinary())); return downloaded; // this.doesFileExist(this.appService.path.join(this.adbPath, this.getAdbBinary()));
} catch (e) {
console.error('Error checking for ADB being installed', e);
return false;
}
} }
setPermission(packageName: string, permission: string, isRevoke?: boolean) { setPermission(packageName: string, permission: string, isRevoke?: boolean) {
return this.adbCommand('shell', { return this.adbCommand('shell', {
+2 -2
View File
@@ -5,7 +5,7 @@
<app-loading-spinner #spinner></app-loading-spinner> <app-loading-spinner #spinner></app-loading-spinner>
<app-status-bar #status (getHelp)="getHelpModal.openModal(); helpStatus = $event; setExterHelp()"></app-status-bar> <app-status-bar #status (getHelp)="getHelpModal.openModal(); helpStatus = $event; setExterHelp()"></app-status-bar>
<webview id="mainWebView" #webview httpreferrer="https://sdiequestvr.com" src="https://sidequestvr.com" allowpopups [ngStyle]="{'left':webService.isWebviewOpen?'0':'-100%'}" class="bsaber-webview" ></webview> <webview id="mainWebView" #webview httpreferrer="https://sdiequestvr.com" [attr.src]="webUrl" allowpopups [ngStyle]="{'left':webService.isWebviewOpen?'0':'-100%'}" class="bsaber-webview" ></webview>
<mz-modal #getHelpModal [fixedFooter]="true"> <mz-modal #getHelpModal [fixedFooter]="true">
<mz-modal-header> <mz-modal-header>
@@ -21,7 +21,7 @@
<br><br> <br><br>
<div class="center-align"> <div class="center-align">
<div class="btn pink-button waves-effect waves-light" (click)="statusService.copyStatus();statusService.showStatus('Copied to your clipboard!')">Copy To Clipboard</div><br><br> <div class="btn pink-button waves-effect waves-light" (click)="statusService.copyStatus();statusService.showStatus('Copied to your clipboard!')">Copy To Clipboard</div><br><br>
<div class="btn btn-flat waves-effect waves-dark" (click)="appService.opn('https://sdq.st/support')">Open Service Desk</div><br><br> <div class="btn btn-flat waves-effect waves-dark" (click)="appService.opn((shortenerUrl||'https://sdq.st')+'/support')">Open Service Desk</div><br><br>
</div> </div>
</mz-modal-content> </mz-modal-content>
<mz-modal-footer> <mz-modal-footer>
+4
View File
@@ -6,6 +6,8 @@ import { WebviewService } from './webview.service';
import { DragAndDropService } from './drag-and-drop.service'; import { DragAndDropService } from './drag-and-drop.service';
import { ElectronService } from './electron.service'; import { ElectronService } from './electron.service';
import { AdbClientService } from './adb-client.service'; import { AdbClientService } from './adb-client.service';
import { environment } from '../environments/environment';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
templateUrl: './app.component.html', templateUrl: './app.component.html',
@@ -18,6 +20,8 @@ export class AppComponent implements OnInit, AfterViewInit {
helpStatus: string; helpStatus: string;
extraHelpStatus: string; extraHelpStatus: string;
devMode: boolean; devMode: boolean;
webUrl = environment.configuration.web_url;
shortenerUrl = environment.configuration.shortenerUrl;
constructor( constructor(
private spinnerService: LoadingSpinnerService, private spinnerService: LoadingSpinnerService,
public statusService: StatusBarService, public statusService: StatusBarService,
+36 -8
View File
@@ -74,8 +74,8 @@ export class AppService {
this.semver = (<any>window).require('semver'); this.semver = (<any>window).require('semver');
this.crypto = (<any>window).require('crypto'); this.crypto = (<any>window).require('crypto');
this.electron = (<any>window).require('electron'); this.electron = (<any>window).require('electron');
this.remote = this.electron.remote; this.remote = (<any>window).require('@electron/remote');
this.nativeApp = this.electron.remote.app; this.nativeApp = this.remote.app;
this.appData = this.path.join(this.nativeApp.getPath('appData'), 'SideQuest'); this.appData = this.path.join(this.nativeApp.getPath('appData'), 'SideQuest');
this.exec = (<any>window).require('child_process').exec; this.exec = (<any>window).require('child_process').exec;
this.execSync = (<any>window).require('child_process').execSync; this.execSync = (<any>window).require('child_process').execSync;
@@ -225,12 +225,37 @@ export class AppService {
break; break;
} }
} }
seedPlatformTools() {
return new Promise(async resolve => { private foundSeedToolsPath: string | null = null;
let sourcesPath = this.path.join(__dirname, '..', 'platform-tools'); getPlatformToolsSeedPath() {
if (!this.fs.existsSync(sourcesPath)) { if (this.foundSeedToolsPath !== null) {
return this.foundSeedToolsPath;
}
let ogSourcesPath = this.path.join(process.resourcesPath, 'build', 'platform-tools');
let sourcesPath = ogSourcesPath;
if (!this.doesFileExist(sourcesPath)) {
sourcesPath = sourcesPath.replace('app.asar', 'app.asar.unpacked');
}
if (!this.doesFileExist(sourcesPath)) {
sourcesPath = this.path.join(process.resourcesPath, 'app.asar.unpacked', 'build', 'platform-tools');
}
if (!this.doesFileExist(sourcesPath)) {
sourcesPath = this.path.join(process.cwd(), 'build', 'platform-tools'); sourcesPath = this.path.join(process.cwd(), 'build', 'platform-tools');
} }
if (!this.doesFileExist(sourcesPath)) {
return null;
}
this.foundSeedToolsPath = sourcesPath;
return sourcesPath;
}
seedPlatformTools() {
return new Promise<void>(async resolve => {
let sourcesPath = this.getPlatformToolsSeedPath();
if (sourcesPath == null) {
console.error('Unable to locate platform tools! Try reinstalling sidequest.');
resolve();
return;
}
await this.mkdir(this.path.join(this.appData, 'platform-tools')); await this.mkdir(this.path.join(this.appData, 'platform-tools'));
try { try {
let files = this.fs.readdirSync(sourcesPath); let files = this.fs.readdirSync(sourcesPath);
@@ -247,7 +272,10 @@ export class AppService {
} else { } else {
setTimeout(() => resolve(), 5000); setTimeout(() => resolve(), 5000);
} }
} catch (e) {} } catch (e) {
console.error('Error seeding platform tools! ', e);
resolve();
}
}); });
} }
makeFolders() { makeFolders() {
@@ -262,7 +290,7 @@ export class AppService {
}); });
} }
setExecutable(path) { setExecutable(path) {
return new Promise(resolve => { return new Promise<void>(resolve => {
const ls = this.spawn('chmod', ['+x', path]); const ls = this.spawn('chmod', ['+x', path]);
ls.stdout.on('data', res => { ls.stdout.on('data', res => {
console.log(res); console.log(res);
@@ -29,6 +29,8 @@
<div class="right"> <div class="right">
<span *ngIf="file.icon !== 'folder'">{{file.size|number:'1.2-2'}}MB | </span>{{file.time|date:'short'}} <span *ngIf="file.icon !== 'folder'">{{file.size|number:'1.2-2'}}MB | </span>{{file.time|date:'short'}}
<i class="material-icons cursor white-text drag-indicator save-icon"
title="Copy full file path to the clipboard" (click)="copyPathToClipboard(file.filePath)">content_copy</i>
<i class="material-icons cursor white-text drag-indicator save-icon" <i class="material-icons cursor white-text drag-indicator save-icon"
(click)="filesToBeSaved = [file]; filesModal.openModal();">save</i> (click)="filesToBeSaved = [file]; filesModal.openModal();">save</i>
<i class="material-icons cursor orange-text drag-indicator right delete" <i class="material-icons cursor orange-text drag-indicator right delete"
+7 -3
View File
@@ -110,6 +110,10 @@ export class FilesComponent implements OnInit {
this.selectedFiles.length = 0; this.selectedFiles.length = 0;
} }
} }
copyPathToClipboard(path = null) {
this.appService.electron.clipboard.writeText(path || this.currentPath);
this.statusService.showStatus(`Copied file path to your clipboard!`);
}
async uploadFolder(folder, files, task) { async uploadFolder(folder, files, task) {
task.status = 'Restoring Folder... ' + folder; task.status = 'Restoring Folder... ' + folder;
if (this.appService.fs.existsSync(folder)) { if (this.appService.fs.existsSync(folder)) {
@@ -184,7 +188,7 @@ export class FilesComponent implements OnInit {
} }
} }
async uploadFiles() { async uploadFiles() {
let res = await this.appService.electron.remote.dialog.showOpenDialog({ let res = await this.appService.remote.dialog.showOpenDialog({
properties: ['openFile', 'multiSelections'], properties: ['openFile', 'multiSelections'],
defaultPath: this.adbService.savePath, defaultPath: this.adbService.savePath,
}); });
@@ -277,7 +281,7 @@ export class FilesComponent implements OnInit {
}); });
} }
async pickLocation() { async pickLocation() {
let res = await this.appService.electron.remote.dialog.showOpenDialog({ let res = await this.appService.remote.dialog.showOpenDialog({
properties: ['openDirectory'], properties: ['openDirectory'],
defaultPath: this.adbService.savePath, defaultPath: this.adbService.savePath,
}); });
@@ -334,7 +338,7 @@ export class FilesComponent implements OnInit {
}); });
} }
openSaveLocation() { openSaveLocation() {
this.appService.electron.remote.shell.openItem(this.adbService.savePath); this.appService.remote.shell.openItem(this.adbService.savePath);
} }
async readdir(path: string) { async readdir(path: string) {
let dirContents: FileFolderListing[]; let dirContents: FileFolderListing[];
@@ -79,7 +79,7 @@
</div> </div>
<div class="user-menu browser-menu" #browserMenu> <div class="user-menu browser-menu" #browserMenu>
<div class="btn-flat waves-light waves-light full-width center-align white-text truncate" <div class="btn-flat waves-light waves-light full-width center-align white-text truncate"
(click)="browserMenu.style.display = 'none';browserMenuBack.style.display = 'none';webService.loadUrl('https://sidequestvr.com')" (click)="browserMenu.style.display = 'none';browserMenuBack.style.display = 'none';webService.loadUrl(webUrl || 'https://sidequestvr.com')"
routerLink="/webview"><i class="material-icons left">home</i>Home</div><br> routerLink="/webview"><i class="material-icons left">home</i>Home</div><br>
<div class="btn-flat waves-light waves-light full-width center-align white-text" <div class="btn-flat waves-light waves-light full-width center-align white-text"
@@ -99,7 +99,7 @@
</div> </div>
<div class="user-menu" #userMenu> <div class="user-menu" #userMenu>
<div class="btn-flat waves-light waves-light full-width center-align white-text" <div class="btn-flat waves-light waves-light full-width center-align white-text"
(click)="userMenu.style.display = 'none';userMenuBack.style.display = 'none';webService.loadUrl('https://sidequestvr.com')" (click)="userMenu.style.display = 'none';userMenuBack.style.display = 'none';webService.loadUrl(webUrl || 'https://sidequestvr.com')"
routerLink="/webview"><i class="material-icons left">home</i>Home</div><br> routerLink="/webview"><i class="material-icons left">home</i>Home</div><br>
<div class="btn-flat waves-light waves-light full-width center-align white-text" <div class="btn-flat waves-light waves-light full-width center-align white-text"
*ngIf="isConnected()&&osPlatform === 'win32'" *ngIf="isConnected()&&osPlatform === 'win32'"
@@ -140,7 +140,7 @@
(click)="userMenu.style.display = 'block';userMenuBack.style.display = 'block'"> (click)="userMenu.style.display = 'block';userMenuBack.style.display = 'block'">
arrow_drop_down arrow_drop_down
</i> </i>
<i mz-tooltip routerLink="/webview" (click)="webService.back()" <i mz-tooltip routerLink="/webview" (click)="doBack()"
class="material-icons white-text no-outline" position="bottom" tooltip="Back"> class="material-icons white-text no-outline" position="bottom" tooltip="Back">
arrow_back arrow_back
</i> </i>
@@ -312,7 +312,7 @@
</mz-modal-content> </mz-modal-content>
<mz-modal-footer> <mz-modal-footer>
<button mz-button [flat]="true" mz-modal-close routerLink="/webview" (click)="webService.loadUrl('https://sidequestvr.com');" >SideQuest Home</button> <button mz-button [flat]="true" mz-modal-close routerLink="/webview" (click)="webService.loadUrl(webUrl || 'https://sidequestvr.com');" >SideQuest Home</button>
<button mz-button [flat]="true" mz-modal-close>Close</button> <button mz-button [flat]="true" mz-modal-close>Close</button>
</mz-modal-footer> </mz-modal-footer>
</mz-modal> </mz-modal>
+21 -4
View File
@@ -10,6 +10,8 @@ import { DragAndDropService } from '../drag-and-drop.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ProcessBucketService } from '../process-bucket.service'; import { ProcessBucketService } from '../process-bucket.service';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { environment } from '../../environments/environment';
interface ReplaceText { interface ReplaceText {
key: string; key: string;
value: string; value: string;
@@ -45,6 +47,7 @@ export class HeaderComponent implements OnInit {
adbCommandToRun: string; adbCommandToRun: string;
osPlatform: string; osPlatform: string;
saveLogcatPath: string; saveLogcatPath: string;
webUrl = environment.configuration.web_url;
favourites: { favourites: {
browserFavourites: FavouriteItem[]; browserFavourites: FavouriteItem[];
fileFavourites: FavouriteItem[]; fileFavourites: FavouriteItem[];
@@ -98,7 +101,8 @@ export class HeaderComponent implements OnInit {
public statusService: StatusBarService, public statusService: StatusBarService,
public beatonService: BeatOnService, public beatonService: BeatOnService,
public dragAndDropService: DragAndDropService, public dragAndDropService: DragAndDropService,
public processService: ProcessBucketService public processService: ProcessBucketService,
private router: Router
) { ) {
this.osPlatform = this.appService.os.platform(); this.osPlatform = this.appService.os.platform();
console.log('Platform: ' + this.osPlatform); console.log('Platform: ' + this.osPlatform);
@@ -107,6 +111,19 @@ export class HeaderComponent implements OnInit {
this.resetFavourites('commandFavourites'); this.resetFavourites('commandFavourites');
this.appService.headerComponent = this; 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) { resetFavourites(type: string) {
let defaultFavs; let defaultFavs;
switch (type) { switch (type) {
@@ -182,7 +199,7 @@ export class HeaderComponent implements OnInit {
} }
updateAvailable() { updateAvailable() {
this.appService.opn('https://sidequestvr.com/download'); this.appService.opn(`${environment.configuration.web_url || 'https://sidequestvr.com'}/download`);
} }
startLogcat() { startLogcat() {
@@ -215,7 +232,7 @@ export class HeaderComponent implements OnInit {
this.saveLogcatPath = null; this.saveLogcatPath = null;
} }
async selectLogcatOutput() { async selectLogcatOutput() {
const res = await this.appService.electron.remote.dialog.showOpenDialog({ const res = await this.appService.remote.dialog.showOpenDialog({
properties: ['openDirectory'], properties: ['openDirectory'],
defaultPath: this.adbService.savePath, defaultPath: this.adbService.savePath,
}); });
@@ -300,7 +317,7 @@ export class HeaderComponent implements OnInit {
this.appService.remote.getCurrentWindow().toggleDevTools(); this.appService.remote.getCurrentWindow().toggleDevTools();
} }
async selectAppToInstall() { async selectAppToInstall() {
let files = await this.appService.electron.remote.dialog.showOpenDialog({ let files = await this.appService.remote.dialog.showOpenDialog({
properties: ['openFile', 'multiSelections'], properties: ['openFile', 'multiSelections'],
defaultPath: this.adbService.savePath, defaultPath: this.adbService.savePath,
}); });
@@ -80,7 +80,7 @@ export class PackagesComponent implements OnInit {
} }
async pickBackupLocation() { async pickBackupLocation() {
const res = await this.appService.electron.remote.dialog.showOpenDialog({ const res = await this.appService.remote.dialog.showOpenDialog({
properties: ['openDirectory'], properties: ['openDirectory'],
defaultPath: this.appService.backupPath, defaultPath: this.appService.backupPath,
}); });
+2 -1
View File
@@ -1,5 +1,6 @@
import { Injectable, isDevMode } from '@angular/core'; import { Injectable, isDevMode } from '@angular/core';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { environment } from '../environments/environment';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -7,7 +8,7 @@ import { AppService } from './app.service';
export class WebviewService { export class WebviewService {
webView: any; webView: any;
isWebviewOpen: boolean; isWebviewOpen: boolean;
currentAddress: string = 'https://sidequestvr.com'; currentAddress: string = environment.configuration.web_url || 'https://sidequestvr.com';
isWebviewLoading: boolean = false; isWebviewLoading: boolean = false;
isLoaded = () => {}; isLoaded = () => {};
constructor(private appService: AppService) { constructor(private appService: AppService) {
@@ -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',
},
};
@@ -1,4 +1,10 @@
export const environment = { export const environment = {
production: true, 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',
},
}; };
@@ -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',
},
};
@@ -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',
},
};
+7 -1
View File
@@ -4,7 +4,13 @@
export const environment = { export const environment = {
production: false, 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',
},
}; };
/* /*
+82 -63
View File
@@ -1,6 +1,8 @@
import { app, protocol, ipcMain, Menu, MenuItemConstructorOptions, BrowserWindow, shell } from 'electron'; import { app, protocol, ipcMain, Menu, MenuItemConstructorOptions, BrowserWindow, shell, HandlerDetails } from 'electron';
import { StateStorage, EnvironmentConfig } from './state-storage'; import { StateStorage, EnvironmentConfig } from './state-storage';
import { AppWindow } from './window'; import { AppWindow } from './window';
import { getEnvCfg } from './env-config';
const path = require('path'); const path = require('path');
const { autoUpdater } = require('electron-updater'); const { autoUpdater } = require('electron-updater');
const download = require('./download'); const download = require('./download');
@@ -13,6 +15,15 @@ const exec = require('child_process').exec;
const crypto = require('crypto'); const crypto = require('crypto');
const request = require('request'); const request = require('request');
const progress = require('request-progress'); const progress = require('request-progress');
const OPEN_IN_SYSTEM_BROWSER_DOMAINS = [
'www.oculus.com',
'oculus.com',
'facebook.com',
'www.facebook.com',
'twitter.com',
'www.twitter.com',
];
// const Readable = require('stream').Readable; // const Readable = require('stream').Readable;
import { SetPropertiesCommand } from './setproperties'; import { SetPropertiesCommand } from './setproperties';
let has_port = process.argv.indexOf('--port'); let has_port = process.argv.indexOf('--port');
@@ -32,7 +43,7 @@ class ADB {
} }
async checkAPK(updateStatus: (string) => void, filePath: string): Promise<boolean> { async checkAPK(updateStatus: (string) => void, filePath: string): Promise<boolean> {
const hash = await this.computeFileHash(updateStatus, filePath); 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...'); updateStatus('Checking APK against blacklist...');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let options = { let options = {
@@ -41,7 +52,7 @@ class ADB {
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Origin: 'https://sidequestvr.com', Origin: getEnvCfg().web_url,
}, },
rejectUnauthorized: process.env.NODE_ENV !== 'dev', rejectUnauthorized: process.env.NODE_ENV !== 'dev',
}; };
@@ -102,12 +113,12 @@ class ADB {
} }
installFromToken(token, cb, ecb) { installFromToken(token, cb, ecb) {
let options = { let options = {
url: 'https://api.sidequestvr.com/install-from-key', url: `${getEnvCfg().http_url || 'https://api.sidequestvr.com'}/install-from-key`,
method: 'POST', method: 'POST',
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Origin: 'https://sidequestvr.com', Origin: getEnvCfg().web_url || 'https://sidequestvr.com',
}, },
rejectUnauthorized: process.env.NODE_ENV !== 'dev', rejectUnauthorized: process.env.NODE_ENV !== 'dev',
json: { token: token }, json: { token: token },
@@ -451,52 +462,8 @@ function parseOpenUrl(argv: string[]) {
setTimeout(() => mainWindow.webContents.send('open-url', argv[1].toString()), 5000); setTimeout(() => mainWindow.webContents.send('open-url', argv[1].toString()), 5000);
} }
} }
function addWindowDownloadHandler(window) {
function createWindow() { window.webContents.session.on('will-download', (_evt, item, _webContents) => {
appWindow = new AppWindow(config);
mainWindow = appWindow.window;
if (process.env.NODE_ENV === 'dev') {
mainWindow.loadURL('http://localhost:4205');
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadFile('build/app/index.html');
}
mainWindow.on('closed', function() {
mainWindow = undefined;
});
setupMenu();
mainWindow.webContents.once('dom-ready', async _e => {
parseOpenUrl(process.argv);
autoUpdater.autoDownload = false;
if (process.platform !== 'linux') autoUpdater.checkForUpdates();
});
protocol.registerBufferProtocol(
'beatsaver',
(request, _callback) => {
mainWindow.webContents.send(
'open-url',
'sidequest://bsaber/#https://beatsaver.com/api/download/key/' + request.url.replace('beatsaver://', '')
);
},
error => {
if (error) console.error('Failed to register protocol');
}
);
protocol.registerStringProtocol(
'sidequest',
(request, _callback) => {
mainWindow.webContents.send('open-url', request.url);
},
error => {
if (error) console.error('Failed to register protocol');
}
);
mainWindow.webContents.on('did-fail-load', () => mainWindow.loadURL(mainWindow.webContents.getURL()));
mainWindow.webContents.session.on('will-download', (_evt, item, _webContents) => {
let url = item.getURL(); let url = item.getURL();
let urls = item.getURLChain(); let urls = item.getURLChain();
let name = item.getFilename(); let name = item.getFilename();
@@ -532,6 +499,69 @@ function createWindow() {
item.cancel(); item.cancel();
}); });
} }
function createWindow() {
appWindow = new AppWindow(config);
mainWindow = appWindow.window;
require('@electron/remote/main').enable(mainWindow.webContents);
if (process.env.NODE_ENV === 'dev') {
mainWindow.loadURL('http://localhost:4205');
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadFile('build/app/index.html');
}
mainWindow.on('closed', function() {
mainWindow = undefined;
});
setupMenu();
mainWindow.webContents.once('dom-ready', async _e => {
parseOpenUrl(process.argv);
autoUpdater.autoDownload = false;
if (process.platform !== 'linux') autoUpdater.checkForUpdates();
});
protocol.registerBufferProtocol('beatsaver', (request, _callback) => {
mainWindow.webContents.send(
'open-url',
'sidequest://bsaber/#https://beatsaver.com/api/download/key/' + request.url.replace('beatsaver://', '')
);
});
protocol.registerStringProtocol('sidequest', (request, _callback) => {
mainWindow.webContents.send('open-url', request.url);
});
mainWindow.webContents.on('did-fail-load', () => mainWindow.loadURL(mainWindow.webContents.getURL()));
addWindowDownloadHandler(mainWindow);
const handleOpenWindow: (details: HandlerDetails) => { action: 'allow' } | { action: 'deny' } = e => {
if (!e.postBody) {
try {
const extUrl = new URL(e.url).host.toLowerCase();
if (OPEN_IN_SYSTEM_BROWSER_DOMAINS.includes(extUrl)) {
shell.openExternal(e.url);
return { action: 'deny' };
}
} catch {}
}
return { action: 'allow' };
};
let handleWindow;
handleWindow = (child: BrowserWindow) => {
child.webContents.on('did-attach-webview', (z, wc) => {
wc.setWindowOpenHandler(handleOpenWindow);
wc.on('did-create-window', child => {
handleWindow(child);
});
});
child.webContents.setWindowOpenHandler(handleOpenWindow);
child.webContents.on('did-create-window', child => {
console.log('did create window fired');
handleWindow(child);
});
};
handleWindow(mainWindow);
mainWindow.webContents.session.setUserAgent(mainWindow.webContents.session.getUserAgent() + ' SQ/' + app.getVersion());
}
function setupMenu() { function setupMenu() {
const template: MenuItemConstructorOptions[] = [ const template: MenuItemConstructorOptions[] = [
@@ -596,6 +626,7 @@ function setupMenu() {
} }
function setupApp() { function setupApp() {
require('@electron/remote/main').initialize();
app.on('second-instance', (_event, commandLine, _workingDirectory) => { app.on('second-instance', (_event, commandLine, _workingDirectory) => {
parseOpenUrl(commandLine); parseOpenUrl(commandLine);
if (mainWindow) { if (mainWindow) {
@@ -631,18 +662,6 @@ function setupApp() {
event.preventDefault(); event.preventDefault();
}); });
app.on('web-contents-created', (e, contents) => {
if (contents.getType() === 'webview') {
// contents.on('new-window', (e : any, url) => {
// popupWindow = new BrowserWindow({show: false})
// popupWindow.once('ready-to-show', () => popupWindow.show())
// popupWindow.loadURL(url);
// e.newGuest = popupWindow;
// e.preventDefault();
// });
}
});
app.on('browser-window-blur', () => { app.on('browser-window-blur', () => {
if (appWindow) { if (appWindow) {
appWindow.saveWindowState(); appWindow.saveWindowState();
+36
View File
@@ -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',
};
}
}
+1
View File
@@ -61,6 +61,7 @@ export class AppWindow {
webPreferences: { webPreferences: {
webviewTag: true, webviewTag: true,
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false,
}, },
}; };
this._window = new BrowserWindow(options); this._window = new BrowserWindow(options);
+22 -6
View File
@@ -10,10 +10,19 @@
"scripts": { "scripts": {
"concurrently": "concurrently", "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": "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", "postinstall": "electron-builder install-app-deps && cd desktop-app && yarn install",
"dist": "yarn electron-build && yarn platform-tools && yarn app-build && electron-builder", "dist": "yarn electron-build && yarn platform-tools && yarn app-build && electron-builder",
"angular": "cd desktop-app && ng serve --port 4205", "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": "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", "electron": "yarn electron-build && yarn electron-dev",
"app-build": "cd desktop-app && ng build --prod --aot && cd ..", "app-build": "cd desktop-app && ng build --prod --aot && cd ..",
"platform-tools": "node build-electron/platform-tools.js", "platform-tools": "node build-electron/platform-tools.js",
@@ -25,9 +34,13 @@
"appId": "com.sidequestvr.app", "appId": "com.sidequestvr.app",
"mac": { "mac": {
"category": "public.app-category.utilities", "category": "public.app-category.utilities",
"target": [ "target": {
"dmg" "target": "dmg",
"arch": [
"arm64",
"x64"
] ]
}
}, },
"win": { "win": {
"artifactName": "${productName}-${version}-${arch}-${os}.${ext}", "artifactName": "${productName}-${version}-${arch}-${os}.${ext}",
@@ -54,7 +67,8 @@
"build-electron/download.js", "build-electron/download.js",
"build-electron/setproperties.js", "build-electron/setproperties.js",
"build-electron/state-storage.js", "build-electron/state-storage.js",
"build-electron/window.js" "build-electron/window.js",
"build-electron/env-config.js"
], ],
"asarUnpack": [ "asarUnpack": [
"build/**/*" "build/**/*"
@@ -78,13 +92,15 @@
"trailingComma": "es5" "trailingComma": "es5"
}, },
"dependencies": { "dependencies": {
"@electron/remote": "^2.0.1",
"@types/electron": "^1.6.10",
"adbkit": "^2.11.1", "adbkit": "^2.11.1",
"adm-zip": "^0.4.14", "adm-zip": "^0.4.14",
"bytenode": "^1.1.6", "bytenode": "^1.1.6",
"concurrently": "^4.1.0", "concurrently": "^4.1.0",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
"crypto": "^1.0.1", "crypto": "^1.0.1",
"electron-updater": "^4.1.2", "electron-updater": "^4.3.7",
"express": "^4.17.1", "express": "^4.17.1",
"extract-zip": "^1.6.7", "extract-zip": "^1.6.7",
"md5": "^2.2.1", "md5": "^2.2.1",
@@ -101,8 +117,8 @@
}, },
"devDependencies": { "devDependencies": {
"@angular/cli": "^8.0.3", "@angular/cli": "^8.0.3",
"electron": "7.2.4", "electron": "13.5.1",
"electron-builder": "^22.4.0", "electron-builder": "22.10.5",
"electron-notarize": "^0.1.1", "electron-notarize": "^0.1.1",
"husky": "^2.3.0", "husky": "^2.3.0",
"prettier": "1.17.1", "prettier": "1.17.1",
+1969 -813
View File
File diff suppressed because it is too large Load Diff