Fixes for Upgrade, ability to pull latest sidequest app from site, added permissions, added additional environmental support.

This commit is contained in:
Nathanael Anderson
2024-03-26 23:56:30 -06:00
parent d250bba378
commit 112546c13b
18 changed files with 556 additions and 257 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
const { notarize } = require('electron-notarize');
const { notarize } = require('@electron/notarize');
exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context;
+46
View File
@@ -121,6 +121,46 @@
"aot": false,
"extractLicenses": true,
"vendorChunk": false
},
"localhost": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.localhost.ts"
}
],
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"aot": false,
"extractLicenses": true,
"vendorChunk": false
},
"fried": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.fried.ts"
}
],
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"aot": false,
"extractLicenses": true,
"vendorChunk": false
}
},
"defaultConfiguration": ""
@@ -142,6 +182,12 @@
},
"local": {
"buildTarget": "desktop-app:build:local"
},
"fried": {
"buildTarget": "desktop-app:build:fried"
},
"localhost": {
"buildTarget": "desktop-app:build:localhost"
}
}
},
+86 -8
View File
@@ -40,6 +40,7 @@ export class AdbClientService {
pollInterval: number = 1000 * 1;
savePath: string;
isTransferring: boolean;
skipStatusUpdates: boolean = false;
adbResolves: any;
files: any;
localFiles: any;
@@ -390,16 +391,17 @@ export class AdbClientService {
}
}
boundConnectedStatus: any = null;
async connectedStatus() {
if (!this.boundConnectedStatus) { this.boundConnectedStatus = this.connectedStatus.bind(this); }
let now = performance.now();
if (now - this.lastConnectionCheck < this.pollInterval || this.isTransferring)
return requestAnimationFrame(this.connectedStatus.bind(this));
if (now - this.lastConnectionCheck < this.pollInterval || this.isTransferring || this.skipStatusUpdates) {
return requestAnimationFrame(this.boundConnectedStatus);
}
this.lastConnectionCheck = now;
return this.adbCommand('listDevices')
.then((devices: any) => {
console.log("d1", devices);
let f = devices.filter(device => device.type !== 'offline')
return f;
return devices.filter(device => device.type !== 'offline')
})
.then(async devices => {
if (devices.length > 1 && this.justChangedMPT) {
@@ -416,10 +418,10 @@ export class AdbClientService {
this.appVersionCode = await this.getAppVersion(true);
} catch {}
}
requestAnimationFrame(this.connectedStatus.bind(this));
requestAnimationFrame(this.boundConnectedStatus);
})
.catch(err => {
console.warn(err, err.stack);
console.error("Wrong Install Error:", err, err.stack);
alert(
this.appService.os.platform() === 'win32'
? `It looks like there is something wrong with your install.
@@ -429,6 +431,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
);
});
}
adbCommand(command: string, settings?, callback?) {
const uuid = this.appService.uuidv4();
return new Promise<any>((resolve, reject) => {
@@ -441,6 +444,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
const { clipboard } = (window as any).require('electron');
clipboard.writeText(value);
}
async getAppVersion(isCode: boolean): Promise<string | null> {
const versionInfo = await this.runAdbCommand('shell dumpsys package ' + this.VR_APP_PACKAGE, true);
this.notInstalled = versionInfo.includes('Unable to find package');
@@ -459,7 +463,6 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
await this.appService.seedPlatformTools();
}
this.appService.electron.ipcRenderer.on('adb-command', (event, arg: any) => {
console.log("result", arg.uuid, arg.status, arg.error, arg.resp)
if (this.adbResolves[arg.uuid]) {
if (arg.status && this.adbResolves[arg.uuid].callback) {
this.adbResolves[arg.uuid].callback(arg.status);
@@ -481,6 +484,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
this.lastErrorMessage = e.toString();
}
}
isAdbDownloaded() {
try {
let downloaded = true;
@@ -504,6 +508,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
return false;
}
}
setPermission(packageName: string, permission: string, isRevoke?: boolean) {
return this.adbCommand('shell', {
serial: this.deviceSerial,
@@ -512,6 +517,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
this.statusService.showStatus('Permission set OK!!');
});
}
doesFileExist(path) {
try {
return this.appService.fs.existsSync(path);
@@ -519,6 +525,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
return false;
}
}
getAdbBinary() {
if (this.appService.os.platform() === 'win32') {
return 'adb.exe';
@@ -526,6 +533,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
return 'adb';
}
}
getFilenameDate() {
return JSON.stringify(new Date())
.split('"')
@@ -534,6 +542,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
.join('-')
.trim();
}
getPackageLocation(packageName) {
return this.adbCommand('shell', { serial: this.deviceSerial, command: 'pm list packages -f ' + packageName }).then(res => {
let parts = res.split(':');
@@ -544,6 +553,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
}
});
}
async makeBackupFolders(packageName: string) {
let mainBackupPath = this.appService.path.join(this.appService.backupPath, packageName);
return this.appService
@@ -551,6 +561,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
.then(() => this.appService.mkdir(this.appService.path.join(mainBackupPath, 'apks')))
.then(() => this.appService.mkdir(this.appService.path.join(mainBackupPath, 'data')));
}
async getBackups(packageName: string) {
await this.makeBackupFolders(packageName);
let backupPath = this.appService.path.join(this.appService.backupPath, packageName, 'apks');
@@ -560,6 +571,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
.filter(file => !this.appService.fs.lstatSync(file).isDirectory() && this.appService.path.extname(file) === '.apk')
.reverse();
}
async getDataBackups(packageName: string) {
await this.makeBackupFolders(packageName);
let backupPath = this.appService.path.join(this.appService.backupPath, packageName, 'data');
@@ -604,6 +616,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
});
});
}
installAPK(
filePath: string,
isLocal?: boolean,
@@ -646,6 +659,9 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
if (filePath.indexOf('com.weloveoculus.BMBF') > -1) {
return this.beatonService.setBeatOnPermission(this);
}
if (filePath.indexOf('quest.side.vr') > -1) {
return this.addVRPermissions();
}
})
.catch(async e => {
if (deleteAfter) {
@@ -685,6 +701,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
name
);
}
uninstallAPK(pkg) {
return this.processService.addItem('apk_uninstall', task => {
task.status = 'Uninstalling ' + pkg + '...';
@@ -706,12 +723,14 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
.catch(e => Promise.reject(e.message ? e.message : e.code ? e.code : e.toString() + pkg));
});
}
makeFolder(files) {
if (!files.length) return null;
let f: any = files.shift();
this.spinnerService.setMessage('Making folder: <br>' + f.saveName);
return this.appService.mkdir(f.saveName).then(() => this.makeFolder(files));
}
downloadFile(files, task) {
if (!files.length) return;
let f: any = files.shift();
@@ -724,6 +743,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
'MB';
}).then(r => this.downloadFile(files, task));
}
async getFoldersRecursive(root: string) {
return this.getFolders(root).then(entries => {
entries.forEach(f => {
@@ -739,6 +759,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
return recurse();
});
}
async getLocalFoldersRecursive(root: string) : Promise<void> {
return new Promise(resolve => {
this.appService.fs.readdir(root, async (err, entries) => {
@@ -757,6 +778,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
});
});
}
async uploadFile(files, task) {
if (!files.length) return;
let f: any = files.shift();
@@ -765,6 +787,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
task.status = 'File uploading: ' + f.name + ' ' + Math.round((stats.bytesTransferred / 1024 / 1024) * 100) / 100 + 'MB';
}).then(r => this.uploadFile(files, task));
}
async launchYurOverlay() {
await this.adbCommand('shell', {
serial: this.deviceSerial,
@@ -775,6 +798,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
command: 'am startservice com.yur.fitquest/.service.YURCounterService',
});
}
async restoreDataBackup(packageName: string, folderName: string) {
return this.processService.addItem('restore_files', async task => {
task.status = 'Transferring Files...';
@@ -823,6 +847,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
return Promise.resolve();
});
}
async makeDataBackup(packageName: string) {
return this.processService.addItem('save_files', async task => {
task.status = 'Starting Backup...';
@@ -881,15 +906,18 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
});
});
}
async hasSDFolder(name: string, packageName: string) {
let folders = await this.getFolders('/sdcard/Android/' + name + '/');
return !!~folders.map(d => d.name).indexOf(packageName);
}
async getFolders(root) {
return this.adbCommand('readdir', { serial: this.deviceSerial, path: root }).catch(e =>
this.statusService.showStatus('Error: ' + e.toString() + ' while reading path ' + root, true)
);
}
installFile(url, destinationFolder: string, number?: number, total?: number) {
return this.processService.addItem('file_install', async task => {
return this.appService
@@ -905,6 +933,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
.then((_path: string) => this.installLocalFile(_path, destinationFolder, false, null, number, total, task));
});
}
installLocalFile(
filepath: string,
destinationFolder: string,
@@ -962,6 +991,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
}
return p;
}
installZip(url, number?: number, total?: number, deleteAfter?: boolean) {
return this.processService.addItem('file_install', async task => {
return this.appService
@@ -991,6 +1021,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
});
});
}
installObb(url, number?: number, total?: number, name?: string) {
return this.processService.addItem(
'file_install',
@@ -1022,6 +1053,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
name
);
}
installLocalObb(filepath: string, dontCatchError = false, cb = null, number?: number, total?: number, task?, name?: string) {
let filename = this.appService.path.basename(filepath);
let match = filename.match(this.obbRegex);
@@ -1059,6 +1091,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
}
return p;
}
async installLocalZip(filepath, dontCatchError, cb, task?, deleteAfter?) : Promise<void> {
const typeBasedActions = {
'.apk': filepath => {
@@ -1116,6 +1149,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
);
});
}
cleanUpFolder(folderPath = this.appService.path.join(this.appService.appData, 'tmp')) {
this.appService.fs.readdir(folderPath, (readErr, files) => {
files.forEach((val, index) => {
@@ -1183,6 +1217,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
return { permission, enabled };
});
}
async getFreeSpace() {
return this.adbCommand('shell', { serial: this.deviceSerial, command: 'df -h' }).then(data => {
data = data.split(' ').filter(d => d);
@@ -1191,6 +1226,7 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
this.freespace.percent = data[data.length - 2];
});
}
async getBatteryLevel() {
return this.adbCommand('shell', { serial: this.deviceSerial, command: 'dumpsys battery' }).then(data => {
let batteryObject = {};
@@ -1209,9 +1245,51 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
this.batteryLevel = batteryObject['level'];
});
}
async getDeviceModel() {
return this.adbCommand('shell', { serial: this.deviceSerial, command: 'getprop ro.product.model' }).then(
data => (this.deviceModel = data.trim())
);
}
private async addVRPermissions() {
await this.adbCommand('shell "pm grant quest.side.vr android.permission.WRITE_SECURE_SETTINGS"', { serial: this.deviceSerial });
await this.adbCommand('shell "pm grant quest.side.vr android.permission.READ_LOGS"', { serial: this.deviceSerial });
try {
const homedir = process.env.USERPROFILE || process.env.HOME;
if (this.appService.fs.existsSync(homedir + '/.android/adbkey')) {
let rawCertificate = this.appService.fs.readFileSync(homedir + '/.android/adbkey', 'utf8').toString();
rawCertificate = rawCertificate
.replace('-----BEGIN RSA PRIVATE KEY-----', '')
.replace('-----END RSA PRIVATE KEY-----', '');
rawCertificate = rawCertificate
.replace('-----BEGIN PRIVATE KEY-----', '')
.replace('-----END PRIVATE KEY-----', '');
rawCertificate = rawCertificate.replace(/\n|\r|\n\r|\r\n/g, '');
if (rawCertificate && rawCertificate.length) {
await this.adbCommand(
[
'shell',
'am',
'start',
'-a',
'android.intent.action.MAIN',
'-n',
'quest.side.vr/.SignInActivity',
'--es',
'CERTIFICATE',
rawCertificate,
].join(' '), { serial: this.deviceSerial }
);
}
}
} catch (e) {
console.error('Error sending certificate to SideQuestVR', e);
}
this.skipStatusUpdates = true;
await this.adbCommand('tcpip 5555', { serial: this.deviceSerial });
setTimeout(() => { this.skipStatusUpdates = false; }, 3000);
}
}
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from '../app.service';
import { AdbClientService } from '../adb-client.service';
import { environment } from '../../environments/environment';
declare const process;
@@ -26,6 +27,7 @@ export class HeaderBannerComponent implements OnInit {
isOutOfDate: boolean;
// the latest available version of the in-headset app
private latestAppVersion: string | null = null;
private appId: string | null = null;
constructor(public appService: AppService, public adb: AdbClientService) {}
ngOnInit() {
@@ -47,36 +49,26 @@ export class HeaderBannerComponent implements OnInit {
}
async getLatestApk() {
this.latestAppVersion = '28';
const request = (await fetch(environment.configuration.http_url + '/v2/apps/get-sidequest-apk', {
body: JSON.stringify({ package_name: 'quest.side.vr' }), method: 'POST',
headers: { "Content-Type": "application/json" }
}));
let json = await request.json();
this.appId = json.app_id;
this.latestAppVersion = json.version_code;
this.apkDownloadPath = json.url;
this.setOutOfDate();
return;
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() {
async downloadAPK() {
if (!this.apkDownloadPath) {
return Promise.reject('Could not download latest apk, please try again!');
}
console.log('downloadExperimentalAPK', this.apkDownloadPath);
console.log('downloadAPK', this.appId);
return new Promise<void>((resolve, reject) => {
const requestOptions = {
timeout: 30000,
@@ -123,9 +115,9 @@ export class HeaderBannerComponent implements OnInit {
// this.telemetry.telemetry({ event: 'install-sidequest-apk', installType: telemEvent, oldVersion });
this.isLoading = true;
try {
throw new Error('bypass_experimental');
throw new Error('bypass_sdk_download');
await this.getLatestApk();
await this.downloadExperimentalAPK();
await this.downloadAPK();
} catch (e) {
// this.toast.show('Failed to download updated SQ apk, falling back to bundled apk. Are you online?', true);
console.warn(e);
@@ -136,8 +128,8 @@ export class HeaderBannerComponent implements OnInit {
// this.toast.show('SideQuest installed to headset!');
// this.showConfetti = true;
this.adb.appVersionCode = await this.adb.getAppVersion(true);
await this.adb.runAdbCommand('shell "pm grant quest.side.vr android.permission.WRITE_SECURE_SETTINGS"');
await this.adb.runAdbCommand('shell "pm grant quest.side.vr android.permission.READ_LOGS"');
await this.adb.runAdbCommand('shell "pm grant quest.side.vr android.permission.WRITE_SECURE_SETTINGS"', true);
await this.adb.runAdbCommand('shell "pm grant quest.side.vr android.permission.READ_LOGS"', true);
try {
const homedir = process.env.USERPROFILE || process.env.HOME;
if (this.appService.fs.existsSync(homedir + '/.android/adbkey')) {
@@ -163,7 +155,7 @@ export class HeaderBannerComponent implements OnInit {
'--es',
'CERTIFICATE',
rawCertificate,
].join(' ')
].join(' '), true
);
}
}
@@ -171,7 +163,10 @@ export class HeaderBannerComponent implements OnInit {
console.error('Error sending certificate to SideQuestVR', e);
}
this.adb.skipStatusUpdates = true;
await this.adb.runAdbCommand('tcpip 5555');
setTimeout(() => { this.adb.skipStatusUpdates = false; }, 3000);
// this.telemetry.telemetry({ event: 'install-sidequest-apk-success',
// installType: telemEvent, oldVersion, newVersion: this.adb.appVersionCode || null});
// setTimeout(() => {
@@ -1,7 +1,7 @@
<div class="header">
<div id=header class="header">
<div class="top-bar">
<div class="relative">
<div class="topper"></div>
<div class="topper {{headerClass}}"></div>
<div class="user-menu-back" (click)="browserMenu.style.display = 'none';browserMenuBack.style.display = 'none'"
#browserMenuBack></div>
<div class="user-menu-back" (click)="commandMenu.style.display = 'none';commandMenuBack.style.display = 'none'"
@@ -16,6 +16,9 @@
>[{{device.id}}] {{device.deviceName}}</div><br>
</ng-container>
</div>
<div class="sideenvironment {{headerClass}}">{{headerText}}</div>
<div class="title-menu-container">
<div class="user-menu command-menu" #commandMenu>
<div class="btn-flat waves-light waves-light full-width center-align white-text truncate"
@@ -52,7 +55,8 @@
</div>
<div class="pure-material-button-contained slim update-available" *ngIf="appService.updateAvailable" (click)="updateAvailable()">Update Available</div>
<!-- <app-link *ngIf="appService.updateAvailable"-->
<!-- <app-link *ngIf="appService.updateAvailable"-->
<!-- class="waves-effect waves-light btn-flat link small-button warning" (click)="updateAvailable()"-->
<!-- text="Update"></app-link>-->
<i routerLink="/webview" (click)="doBack()"
@@ -95,7 +99,7 @@
apps
</i>
<i routerLink="tasks" class="material-icons white-text no-outline" data-position="bottom"
mTooltip [attr.data-tooltip]="'Running' + processService.left_length + 'tasks.'">
mTooltip [attr.data-tooltip]="'Running ' + processService.left_length + ' tasks.'">
playlist_add_check
</i><span routerLink="tasks" *ngIf="processService.left_length" data-position="bottom"
mTooltip data-tooltip="Running {{processService.left_length}} tasks."
@@ -140,7 +144,6 @@
</div>
</div>
<div class="top-dnd-backing">
<div class="top-banner">
<!-- <div>-->
<!-- <a href="#/" class="logo">-->
@@ -464,3 +464,26 @@ virtual-scroller{
.footer-margin-right{
margin-right: 1em!important;
}
.sidetestvr {
background-color: darkgreen;
color: white;
}
.friedquestvr {
background-color: darkred;
color: yellow;
}
.localtest {
background-color: darkblue;
color: yellow;
}
.sideenvironment {
position: absolute;
top: 5px;
right: calc(50% - 50px);
font-size: 16px;
font-weight: bold;
}
@@ -35,9 +35,9 @@ interface LogCatEntry {
styleUrls: ['./header.component.scss'],
})
export class HeaderComponent implements OnInit {
@ViewChild('header') header;
// @ViewChild('header') header;
@ViewChild('bookmarksModal') bookmarksModal;
@ViewChild('beatOnModal') beatOnModal;
// @ViewChild('beatOnModal') beatOnModal;
@ViewChild('mainLogo') mainLogo;
@ViewChild('safeModal') safeModal;
@ViewChild('manageFavs') manageFavs;
@@ -94,6 +94,8 @@ export class HeaderComponent implements OnInit {
currentLogCat: LogCatEntry[] = [];
isStarted: boolean;
showAddFavourite: boolean;
protected headerClass: string;
protected headerText: string;
constructor(
public adbService: AdbClientService,
public appService: AppService,
@@ -111,6 +113,9 @@ export class HeaderComponent implements OnInit {
this.resetFavourites('fileFavourites');
this.resetFavourites('commandFavourites');
this.appService.headerComponent = this;
this.headerClass = environment.header?.color || "";
this.headerText = environment.header?.text || "";
console.log('Header: ' + this.headerClass + ' ' + this.headerText);
}
doBack() {
if (
@@ -0,0 +1,11 @@
export const environment = {
production: true,
header: {color: "friedquestvr", text: "Fried Quest VR"},
configuration: {
web_url: 'https://friedquestvr.com',
ws_url: 'wss://ws.friedquestvr.com',
http_url: 'https://api.friedquestvr.com',
cdnUrl: 'https://cdn.friedquestvr.com',
shortenerUrl: 'https://links.friedquestvr.com'
},
};
@@ -1,5 +1,6 @@
export const environment = {
production: false,
header: {color: "localtest", text: "Local Test VR"},
configuration: {
web_url: 'https://sidequestvr.local',
ws_url: 'wss://ws.sidetestvr.local',
@@ -0,0 +1,11 @@
export const environment = {
production: false,
header: {color: "localtest", text: "LocalHost Test VR"},
configuration: {
web_url: 'http://127.0.0.1:3005',
ws_url: 'ws://127.0.0.1:3008',
http_url: 'http://127.0.0.1:3000',
cdnUrl: 'http://127.0.0.1:3001',
shortenerUrl: 'http://127.0.0.1:3004',
},
};
@@ -1,5 +1,6 @@
export const environment = {
production: true,
header: null,
configuration: {
web_url: 'https://sidequestvr.com',
ws_url: 'wss://ws.sidequestvr.com',
@@ -1,5 +1,6 @@
export const environment = {
production: false,
header: {color: "sidetestvr", text: "Side Test VR"},
configuration: {
web_url: 'https://sidetestvr.com',
ws_url: 'wss://ws.sidetestvr.com',
@@ -1,5 +1,6 @@
export const environment = {
production: false,
header: {color: "sidetestvr", text: "Side Test VR"},
configuration: {
web_url: 'https://test.side.quest',
ws_url: 'wss://testws.side.quest',
+5 -4
View File
@@ -4,11 +4,12 @@
export const environment = {
production: false,
header: null, // {color: "sidetestvr", text: "Side Test VR"},
configuration: {
web_url: 'https://sidequestvr.com',
ws_url: 'wss://ws.sidequestvr.com',
http_url: 'https://api.sidequestvr.com',
cdnUrl: 'https://cdn.sidequestvr.com',
web_url: 'https://sidetestvr.com',
ws_url: 'wss://ws.sidetestvr.com',
http_url: 'https://api.sidetestvr.com',
cdnUrl: 'https://cdn.sidetestvr.com',
shortenerUrl: 'https://sdq.st',
},
};
+305 -206
View File
@@ -9,22 +9,17 @@ const download = require('./download');
const extract = require('extract-zip');
const Readable = require('stream').Readable;
const adb = require('adbkit');
const adb = require('@devicefarmer/adbkit').Adb;
const fs = require('fs');
const exec = require('child_process').exec;
const crypto = require('crypto');
const request = require('request');
const progress = require('request-progress');
//without this, there's a bug in electron that makes facebook pages ruin everything, see https://github.com/electron/electron/issues/25469
app.commandLine.appendSwitch('disable-features', 'CrossOriginOpenerPolicy');
// const Readable = require('stream').Readable;
import { SetPropertiesCommand } from './setproperties';
import { OPEN_IN_SYSTEM_BROWSER_DOMAINS } from './external-urls';
let has_port = process.argv.indexOf('--port');
let valid_port = has_port > -1 && process.argv[has_port + 1] && Number.isInteger(Number(process.argv[has_port + 1]));
let installErrorCallback;
process.on('uncaughtException', function(error) {
@@ -35,19 +30,35 @@ process.on('uncaughtException', function(error) {
}
});
const makeDeferred = () => {
const deferred = {promise: null, resolve: () => {} , reject: () => {}};
// @ts-ignore
deferred.promise = new Promise((resolve: Function, reject: Function): void => {
// @ts-ignore
deferred.resolve = resolve;
// @ts-ignore
deferred.reject = reject;
});
return deferred;
}
class ADB {
client;
client= null;
_logcat;
adbPath;
_clientSetup = makeDeferred();
setupAdb(adbPath, cb, ecb) {
if (this.client) return;
this.adbPath = adbPath;
let port = valid_port ? Number(process.argv[has_port + 1]) : process.env.ANDROID_ADB_SERVER_PORT || 5037;
this.client = adb.createClient({
bin: adbPath,
});
this._clientSetup.resolve();
cb();
}
async checkAPK(updateStatus: (string) => void, filePath: string): Promise<boolean> {
const hash = await this.computeFileHash(updateStatus, filePath);
const url = `${getEnvCfg().shortenerUrl || 'https://sdq.st'}/check-app-hash/${hash}`;
@@ -171,26 +182,33 @@ class ADB {
}
}
logcat(serial, tag, priority, cb, scb, ecb) {
if (!this.client) return ecb('Not connected.');
if (!this._logcat) this.endLogcat();
this.client
.openLogcat(serial, { clear: true })
.then(logcat => {
this._logcat = logcat;
logcat.include(tag, priority).on('entry', entry => scb(entry));
})
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
if (!this._logcat) this.endLogcat();
this.client
.openLogcat(serial, { clear: true })
.then(logcat => {
this._logcat = logcat;
logcat.include(tag, priority).on('entry', entry => scb(entry));
})
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
installRemote(serial, path, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.installRemote(serial, path)
.then(cb)
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.installRemote(serial, path)
.then(cb)
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
async install(serial, apkpath, isLocal, cb, scb, ecb) {
await this._clientSetup.promise;
console.log('installapk');
let stopUpdate;
installErrorCallback = e => {
stopUpdate = true;
ecb(e);
@@ -245,160 +263,190 @@ class ADB {
.then(cb)
.catch(e => ecb(e));
}
uninstall(serial, packageName, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.uninstall(serial, packageName)
.then(cb)
.catch(e => ecb(e));
uninstall(serial, packageName, cb, ecb) {
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.uninstall(serial, packageName)
.then(cb)
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
clear(serial, packageName, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.clear(serial, packageName)
.then(cb)
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.clear(serial, packageName)
.then(cb)
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
disconnect(cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.disconnect()
.then(cb)
.then(() => this.client.kill())
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.disconnect()
.then(cb)
.then(() => this.client.kill())
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
connect(deviceIp, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.connect(deviceIp + ':5555')
.then(cb)
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.connect(deviceIp + ':5555')
.then(cb)
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
tcpip(serial, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.tcpip(serial, 5555)
.then(r => {
console.log(r);
cb(r);
})
.catch(e => {
console.log(serial, e);
ecb(e);
});
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.tcpip(serial, 5555)
.then(r => {
console.log(r);
cb(r);
})
.catch(e => {
console.log(serial, e);
ecb(e);
});
}).catch(e => ecb(e));
}
usb(serial, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.usb(serial)
.then(cb)
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.usb(serial)
.then(cb)
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
listDevices(cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.listDevices()
.then(d => cb(d))
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.listDevices()
.then(d => cb(d))
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
setProperties(serial, command, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.transport(serial)
.then(function(transport) {
return new SetPropertiesCommand(transport).execute(command);
})
// this.client
// .setProperties(serial, command)
.then(res => cb(res))
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.transport(serial)
.then(function(transport) {
return new SetPropertiesCommand(transport).execute(command);
})
// this.client
// .setProperties(serial, command)
.then(res => cb(res))
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
getPackages(serial, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.getPackages(serial)
.then(res => cb(res))
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.getPackages(serial)
.then(res => cb(res))
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
shell(serial, command, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.shell(serial, command)
.then(adb.util.readAll)
.then(res => cb(res.toString()))
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.shell(serial, command)
.then(adb.util.readAll)
.then(res => cb(res.toString()))
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
readdir(serial, path, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.readdir(serial, path)
.then(res =>
res
.map(r => {
r.__isFile = r.isFile();
return r;
})
.filter(r => !(r.__isFile && r.name.lastIndexOf('\\') > -1))
)
.then(res => cb(res))
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.readdir(serial, path)
.then(res =>
res
.map(r => {
r.__isFile = r.isFile();
return r;
})
.filter(r => !(r.__isFile && r.name.lastIndexOf('\\') > -1))
)
.then(res => cb(res))
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
push(serial, path, savePath, cb, scb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.push(serial, fs.createReadStream(path), savePath)
.then(transfer => {
let _stats, autocancel;
const interval = setInterval(() => {
scb(_stats);
}, 1000);
transfer.on('progress', stats => {
clearTimeout(autocancel);
_stats = stats;
autocancel = setTimeout(() => {
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.push(serial, fs.createReadStream(path), savePath)
.then(transfer => {
let _stats, autoCancel;
const interval = setInterval(() => {
scb(_stats);
}, 1000);
transfer.on('progress', stats => {
clearTimeout(autoCancel);
_stats = stats;
autoCancel = setTimeout(() => {
clearInterval(interval);
cb();
}, 90000);
});
transfer.on('end', () => {
clearTimeout(autoCancel);
clearInterval(interval);
cb();
}, 90000);
});
transfer.on('end', () => {
clearTimeout(autocancel);
clearInterval(interval);
cb();
});
transfer.on('error', e => {
});
transfer.on('error', e => {
ecb(e);
});
})
.catch(e => {
ecb(e);
});
})
.catch(e => {
ecb(e);
});
}).catch(e => ecb(e));
}
pull(serial, path, savePath, cb, scb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.pull(serial, path)
.then(transfer => {
transfer.on('progress', stats => {
scb(stats);
});
transfer.on('end', () => {
cb();
});
transfer.on('error', e => {
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.pull(serial, path)
.then(transfer => {
transfer.on('progress', stats => {
scb(stats);
});
transfer.on('end', () => {
cb();
});
transfer.on('error', e => {
ecb(e);
});
transfer.pipe(fs.createWriteStream(savePath));
})
.catch(e => {
ecb(e);
});
transfer.pipe(fs.createWriteStream(savePath));
})
.catch(e => {
ecb(e);
});
}).catch(e => ecb(e));
}
stat(serial, path, cb, ecb) {
if (!this.client) return ecb('Not connected.');
this.client
.stat(serial, path)
.then(res => cb(res))
.catch(e => ecb(e));
this._clientSetup.promise.then(() => {
if (!this.client) return ecb('Not connected.');
this.client
.stat(serial, path)
.then(res => cb(res))
.catch(e => ecb(e));
}).catch(e => ecb(e));
}
}
@@ -530,6 +578,47 @@ function createWindow() {
console.log('did create window fired');
handleWindow(child);
});
child.webContents.session.on('select-usb-device', (event, details, callback) => {
// Add events to handle devices being added or removed before the callback on
// `select-usb-device` is called.
//event.preventDefault();
if (details.deviceList && details.deviceList.length > 0) {
// Meta Quest Device
if (details.deviceList[0].vendorId === 10291) {
callback(details.deviceList[0].deviceId);
return;
}
// if (deviceToReturn) {
// callback(deviceToReturn.deviceId)
// } else {
// callback()
// }
}
callback();
});
/*
child.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
console.log("SET PERMISSION CHECK HANDLER", permission, requestingOrigin, details)
if (permission === 'usb') {
return true
}
}) */
child.webContents.session.setDevicePermissionHandler((details) => {
if (details.deviceType === 'usb') {
if (details.device.vendorId === 10291) {
// Meta Oculus
return true;
}
// TODO: Pico
console.log("SET DEVICE PERMISSION HANDLER FALSE", details)
return false;
}
});
};
handleWindow(mainWindow);
mainWindow.webContents.session.setUserAgent(mainWindow.webContents.session.getUserAgent() + ' SQ/' + app.getVersion());
@@ -697,6 +786,8 @@ function setupApp() {
mainWindow.webContents.send('info', text);
};
const adb = new ADB();
ipcMain.on('download-url', async (event, { url, token, directory, filename }) => {
@@ -731,11 +822,13 @@ function setupApp() {
});
ipcMain.on('adb-command', (event, arg) => {
const success = d => {
// console.log(" ", arg.command, "Success", d)
if (!event.sender.isDestroyed()) {
event.sender.send('adb-command', { command: arg.command, resp: d, uuid: arg.uuid });
}
};
const reject = e => {
// console.log(" ", arg.command, "reject", e)
if (!event.sender.isDestroyed()) {
event.sender.send('adb-command', { command: arg.command, error: e, uuid: arg.uuid });
}
@@ -745,68 +838,74 @@ function setupApp() {
event.sender.send('adb-command', { command: arg.command, status: d, uuid: arg.uuid });
}
};
switch (arg.command) {
case 'installFromToken':
adb.installFromToken(arg.settings.token, success, reject);
break;
case 'setupAdb':
adb.setupAdb(arg.settings.adbPath, success, reject);
break;
case 'endLogcat':
adb.endLogcat();
success('Done.');
break;
case 'logcat':
adb.logcat(arg.settings.serial, arg.settings.tag, arg.settings.priority, success, status, reject);
break;
case 'listDevices':
adb.listDevices(success, reject);
break;
case 'getPackages':
adb.getPackages(arg.settings.serial, success, reject);
break;
case 'shell':
adb.shell(arg.settings.serial, arg.settings.command, success, reject);
break;
case 'readdir':
adb.readdir(arg.settings.serial, arg.settings.path, success, reject);
break;
case 'push':
adb.push(arg.settings.serial, arg.settings.path, arg.settings.savePath, success, status, reject);
break;
case 'pull':
adb.pull(arg.settings.serial, arg.settings.path, arg.settings.savePath, success, status, reject);
break;
case 'stat':
adb.stat(arg.settings.serial, arg.settings.path, success, reject);
break;
case 'install':
adb.install(arg.settings.serial, arg.settings.path, arg.settings.isLocal, success, status, reject);
break;
case 'uninstall':
adb.uninstall(arg.settings.serial, arg.settings.packageName, success, reject);
break;
case 'installRemote':
adb.installRemote(arg.settings.serial, arg.settings.path, success, reject);
break;
case 'clear':
adb.clear(arg.settings.serial, arg.settings.packageName, success, reject);
break;
case 'connect':
adb.connect(arg.settings.deviceIp, success, reject);
break;
case 'disconnect':
adb.disconnect(success, reject);
break;
case 'usb':
adb.usb(arg.settings.serial, success, reject);
break;
case 'tcpip':
adb.tcpip(arg.settings.serial, success, reject);
break;
case 'setProperties':
adb.setProperties(arg.settings.serial, arg.settings.command, success, reject);
break;
// console.log("Running:", arg.command);
try {
switch (arg.command) {
case 'installFromToken':
adb.installFromToken(arg.settings.token, success, reject);
break;
case 'setupAdb':
adb.setupAdb(arg.settings.adbPath, success, reject);
break;
case 'endLogcat':
adb.endLogcat();
success('Done.');
break;
case 'logcat':
adb.logcat(arg.settings.serial, arg.settings.tag, arg.settings.priority, success, status, reject);
break;
case 'listDevices':
adb.listDevices(success, reject);
break;
case 'getPackages':
adb.getPackages(arg.settings.serial, success, reject);
break;
case 'shell':
adb.shell(arg.settings.serial, arg.settings.command, success, reject);
break;
case 'readdir':
adb.readdir(arg.settings.serial, arg.settings.path, success, reject);
break;
case 'push':
adb.push(arg.settings.serial, arg.settings.path, arg.settings.savePath, success, status, reject);
break;
case 'pull':
adb.pull(arg.settings.serial, arg.settings.path, arg.settings.savePath, success, status, reject);
break;
case 'stat':
adb.stat(arg.settings.serial, arg.settings.path, success, reject);
break;
case 'install':
adb.install(arg.settings.serial, arg.settings.path, arg.settings.isLocal, success, status, reject);
break;
case 'uninstall':
adb.uninstall(arg.settings.serial, arg.settings.packageName, success, reject);
break;
case 'installRemote':
adb.installRemote(arg.settings.serial, arg.settings.path, success, reject);
break;
case 'clear':
adb.clear(arg.settings.serial, arg.settings.packageName, success, reject);
break;
case 'connect':
adb.connect(arg.settings.deviceIp, success, reject);
break;
case 'disconnect':
adb.disconnect(success, reject);
break;
case 'usb':
adb.usb(arg.settings.serial, success, reject);
break;
case 'tcpip':
adb.tcpip(arg.settings.serial, success, reject);
break;
case 'setProperties':
adb.setProperties(arg.settings.serial, arg.settings.command, success, reject);
break;
}
}
catch (e) {
reject(e)
}
});
}
+18
View File
@@ -1,3 +1,4 @@
export function getEnvCfg() {
switch (process.env['SQ_ENV_CFG']) {
case 'test':
@@ -16,6 +17,23 @@ export function getEnvCfg() {
cdnUrl: 'https://testcdn.sidequestvr.com',
shortenerUrl: 'https://testlinks.side.quest',
};
case 'fried':
case 'friedquest':
return {
web_url: 'https://friedquestvr.com',
ws_url: 'wss://ws.friedquestvr.com',
http_url: 'https://api.friedquestvr.com',
cdnUrl: 'https://cdn.friedquestvr.com',
shortenerUrl: 'https://links.friedquestvr.com',
};
case 'localhost':
return {
web_url: 'http://127.0.0.1:3005',
ws_url: 'ws://127.0.0.1:3008',
http_url: 'http://127.0.0.1:3000',
cdnUrl: 'http://127.0.0.1:3001',
shortenerUrl: 'http://127.0.0.1:3004',
};
case 'local':
return {
web_url: 'https://sidequestvr.local',
+2 -2
View File
@@ -1,5 +1,5 @@
const Command = require('adbkit/lib/adb/command');
const Protocol = require('adbkit/lib/adb/protocol');
const Command = require('@devicefarmer/adbkit/dist/src/adb/command').default;
const Protocol = require('@devicefarmer/adbkit/dist/src/adb/protocol').default;
const RE_KEYVAL = /^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$/gm;
+6 -1
View File
@@ -13,11 +13,14 @@
"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\"",
"start:localhost": "concurrently \"yarn electron-build && yarn platform-tools && wait-on http-get://localhost:4205/ && cross-env NODE_ENV=dev SQ_ENV_CFG=localhost electron .\" \"cd desktop-app && ng serve -c localhost --port 4205\"",
"postinstall": "electron-builder install-app-deps && cd desktop-app && yarn install",
"dist": "yarn electron-build && yarn platform-tools && yarn app-build && env-cmd --silent electron-builder --publish onTagOrDraft",
"build:win": "yarn electron-build && yarn platform-tools && yarn app-build && cross-env NODE_ENV=production electron-builder --win",
"build:linux": "yarn electron-build && yarn platform-tools && yarn app-build && cross-env NODE_ENV=production electron-builder --linux",
"dist-test": "yarn electron-build && yarn platform-tools && yarn app-build-test && cross-env SQ_ENV_CFG=test electron-builder",
"dist-fried": "yarn electron-build && yarn platform-tools && yarn app-build-fried && cross-env SQ_ENV_CFG=fried electron-builder",
"dist-localhost": "yarn electron-build && yarn platform-tools && yarn app-build-localhost && cross-env SQ_ENV_CFG=localhost electron-builder --linux",
"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",
@@ -29,6 +32,8 @@
"electron": "yarn electron-build && yarn electron-dev",
"app-build": "cd desktop-app && ng build --prod --aot && cd ..",
"app-build-test": "cd desktop-app && ng build -c test --aot && cd ..",
"app-build-fried": "cd desktop-app && ng build -c fried --aot && cd ..",
"app-build-localhost": "cd desktop-app && ng build -c localhost --aot && cd ..",
"platform-tools": "node build-electron/platform-tools.js",
"electron-build": "tsc",
"reset": "rm -rf node_modules && rm -rf desktop-app/node_modules && yarn install && cd desktop-app && yarn install"
@@ -102,7 +107,7 @@
"dependencies": {
"@electron/remote": "^2.1.2",
"@types/electron": "^1.6.10",
"adbkit": "^2.11.1",
"@devicefarmer/adbkit": "^3.2.6",
"adm-zip": "^0.5.10",
"bytenode": "^1.5.3",
"crypto": "^1.0.1",