diff --git a/desktop-app/src/app/adb-client.service.ts b/desktop-app/src/app/adb-client.service.ts index 19b6f8f..c1a97cc 100644 --- a/desktop-app/src/app/adb-client.service.ts +++ b/desktop-app/src/app/adb-client.service.ts @@ -521,94 +521,50 @@ export class AdbClientService { return Promise.reject(name + 'Apk install failed - No device connected! ' + filePath); } const showTotal = number && total ? '(' + number + '/' + total + ') ' : ''; - const updateStatus = (text: string): void => { - const newStatus = `${showTotal}${text} `; - if (task.status !== newStatus) { - task.status = newStatus; - } - }; - const checkReported: Promise = isLocal - ? this.checkIsAPKReported(updateStatus, filePath) - : Promise.resolve('DoInstall'); - return checkReported.then(installDecision => { - task.app_name = name; - if (installDecision === 'DoInstall') { - task.status = name + showTotal + 'Installing Apk... '; - return this.adbCommand( - 'install', - { serial: this.deviceSerial, path: filePath, isLocal: !!isLocal }, - status => { - task.status = - (status.percent === 1 - ? name + showTotal + 'Installing Apk... ' - : name + showTotal + 'Downloading APK... ' + Math.round(status.percent * 100) + '% ') + - ' ' + - filePath + - ''; - } - ) - .then(r => { - task.status = name + 'APK file installed ok!! ' + filePath; - if (deleteAfter) { - this.appService.fs.unlink(filePath, err => {}); - } - if (filePath.indexOf('com.weloveoculus.BMBF') > -1) { - return this.beatonService.setBeatOnPermission(this); - } - if (filePath.toLowerCase().indexOf('sidequest.legends') > -1) { - return this.setPermission('com.sidequest.legends', 'android.permission.RECORD_AUDIO'); - } - if (filePath.toLowerCase().indexOf('pavlov') > -1) { - return this.setPermission('com.vankrupt.pavlov', 'android.permission.RECORD_AUDIO') - .then(() => - this.setPermission('com.vankrupt.pavlov', 'android.permission.READ_EXTERNAL_STORAGE') - ) - .then(() => - this.setPermission('com.vankrupt.pavlov', 'android.permission.WRITE_EXTERNAL_STORAGE') - ) - .then(() => - this.adbCommand('shell', { - serial: this.deviceSerial, - command: 'echo null > /sdcard/pavlov.name.txt', - }) - ); - } - }) - .catch(e => { - if (deleteAfter) { - this.appService.fs.unlink(filePath, err => {}); - } - return Promise.reject(e.message ? e.message : e.code ? e.code : e.toString() + ' ' + filePath); - }); - } else { + task.app_name = name; + task.status = name + showTotal + 'Installing Apk... '; + return this.adbCommand('install', { serial: this.deviceSerial, path: filePath, isLocal: !!isLocal }, status => { + task.status = + (status.percent === 1 + ? name + showTotal + 'Installing Apk... ' + : name + showTotal + 'Downloading APK... ' + Math.round(status.percent * 100) + '% ') + + ' ' + + filePath + + ''; + }) + .then(r => { + task.status = name + 'APK file installed ok!! ' + filePath; if (deleteAfter) { this.appService.fs.unlink(filePath, err => {}); } - updateStatus('Canceled Install.'); - return Promise.resolve(); - } - }); + if (filePath.indexOf('com.weloveoculus.BMBF') > -1) { + return this.beatonService.setBeatOnPermission(this); + } + if (filePath.toLowerCase().indexOf('sidequest.legends') > -1) { + return this.setPermission('com.sidequest.legends', 'android.permission.RECORD_AUDIO'); + } + if (filePath.toLowerCase().indexOf('pavlov') > -1) { + return this.setPermission('com.vankrupt.pavlov', 'android.permission.RECORD_AUDIO') + .then(() => this.setPermission('com.vankrupt.pavlov', 'android.permission.READ_EXTERNAL_STORAGE')) + .then(() => this.setPermission('com.vankrupt.pavlov', 'android.permission.WRITE_EXTERNAL_STORAGE')) + .then(() => + this.adbCommand('shell', { + serial: this.deviceSerial, + command: 'echo null > /sdcard/pavlov.name.txt', + }) + ); + } + }) + .catch(e => { + if (deleteAfter) { + this.appService.fs.unlink(filePath, err => {}); + } + return Promise.reject(e.message ? e.message : e.code ? e.code : e.toString() + ' ' + filePath); + }); }, name ); } - async checkIsAPKReported(updateStatus: (string) => void, filePath: string): Promise { - let isReported: boolean; - try { - isReported = await this.safeSideService.checkAPK(updateStatus, filePath); - } catch { - isReported = false; - } - if (isReported) { - updateStatus('Confirming you want to install APK...'); - this.appService.headerComponent.safeModal.openModal(); - return new Promise(resolve => { - this.appService.headerComponent.safeResolve = resolve; - }); - } else { - return 'DoInstall'; - } - } uninstallAPK(pkg) { return this.processService.addItem('apk_uninstall', task => { task.status = 'Uninstalling ' + pkg + '...'; diff --git a/desktop-app/src/app/safe-side.service.ts b/desktop-app/src/app/safe-side.service.ts index c481084..09b5b2f 100644 --- a/desktop-app/src/app/safe-side.service.ts +++ b/desktop-app/src/app/safe-side.service.ts @@ -1,9 +1,4 @@ import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; -import { AppService } from './app.service'; -import { environment } from './../environments/environment'; -import { ElectronService } from './electron.service'; -import { AdbClientService } from './adb-client.service'; interface CheckSubmissionResponse { found: boolean; @@ -13,16 +8,14 @@ interface CheckSubmissionResponse { providedIn: 'root', }) export class SafeSideService { - constructor(private appService: AppService, private adbService: AdbClientService) {} // private http: HttpClient - - async checkAPK(updateStatus: (string) => void, filePath: string): Promise { - return this.adbService.adbCommand('hashCheck', { path: filePath }, updateStatus); - // const hash = await this.computeFileHash(updateStatus, filePath); - // const url = `${environment.safeSideApiUrl}/check-app-hash/${hash}`; - // updateStatus('Checking APK against blacklist...'); - // const response = await this.http.get(url).toPromise(); - // return response.found; - } + // constructor(private appService: AppService, private adbService: AdbClientService) {} // private http: HttpClient + // async checkAPK(updateStatus: (string) => void, filePath: string): Promise { + // const hash = await this.computeFileHash(updateStatus, filePath); + // const url = `${environment.safeSideApiUrl}/check-app-hash/${hash}`; + // updateStatus('Checking APK against blacklist...'); + // const response = await this.http.get(url).toPromise(); + // return response.found; + // } // async computeFileHash(updateStatus: (string) => void, filePath: string): Promise { // const fileSize = await this.computeFileSize(filePath); // return new Promise((resolve, reject) => { diff --git a/electron/adbkit.ts b/electron/adbkit.ts deleted file mode 100644 index 98fe2f4..0000000 --- a/electron/adbkit.ts +++ /dev/null @@ -1,351 +0,0 @@ -import { environment } from '../desktop-app/src/environments/environment'; - -const adb = require('adbkit'); -const fs = require('fs'); -const crypto = require('crypto'); -const request = require('request'); -const progress = require('request-progress'); -const Readable = require('stream').Readable; -import { SetPropertiesCommand } from './setproperties'; - -export class ADB { - client; - _logcat; - setupAdb(adbPath, cb, ecb) { - if (this.client) return; - this.client = adb.createClient({ - bin: adbPath, - }); - cb(); - } - async checkAPK(updateStatus: (string) => void, filePath: string): Promise { - const hash = await this.computeFileHash(updateStatus, filePath); - const url = `https://sdq.st/check-app-hash/${hash}`; - updateStatus('Checking APK against blacklist...'); - return new Promise((resolve, reject) => { - let options = { - url, - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Origin: 'https://sidequestvr.com', - }, - rejectUnauthorized: process.env.NODE_ENV !== 'dev', - }; - request(options, (error, response, body) => { - if (error) { - reject(error); - } else { - try { - resolve(JSON.parse(body).found); - } catch (e) { - reject(e); - } - } - }); - }); - // const response = await this.http.get(url).toPromise(); - // return response.found; - } - async computeFileHash(updateStatus: (string) => void, filePath: string): Promise { - const fileSize = await this.computeFileSize(filePath); - return new Promise((resolve, reject) => { - let bytesRead: number = 0; - const fd = fs.createReadStream(filePath); - const hash = crypto.createHash('md5'); - hash.setEncoding('hex'); - fd.on('data', chunk => { - bytesRead += chunk.length; - const percentage = this.formattedPercentageComplete(bytesRead, fileSize); - updateStatus(`Computing APK hash (${percentage})...`); - }); - fd.on('end', () => { - updateStatus(`Computing APK hash (100%)...`); - hash.end(); - resolve(hash.read()); - }); - fd.on('error', error => { - reject(error); - }); - fd.pipe(hash); - }); - } - async computeFileSize(filePath: string): Promise { - return new Promise((resolve, reject) => { - fs.stat(filePath, (err, stats) => { - if (err) { - reject(err); - } else { - resolve(stats.size); - } - }); - }); - } - formattedPercentageComplete(amount: number, total: number): string { - const percentage = Math.round(Math.min(amount / total, 1) * 100); - return `${percentage}%`; - } - hashCheckFile(path, cb, scb, ecb) { - return this.checkAPK(scb, path) - .then(() => cb()) - .catch(e => ecb(e)); - } - installFromToken(token, cb, ecb) { - let options = { - url: 'https://api.sidequestvr.com/install-from-key', - method: 'POST', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Origin: 'https://sidequestvr.com', - }, - rejectUnauthorized: process.env.NODE_ENV !== 'dev', - json: { token: token }, - }; - request(options, (error, response, body) => { - if (!error && body.data && body.data.apps && body.data.apps.length) { - let tasks = []; - for (let i = 0; i < body.data.apps.length; i++) { - let app = body.data.apps[i]; - if (Number(app.app_categories_id) === 1) { - let urls = app.urls.filter(l => l && ~['Github Release', 'APK', 'OBB', 'Mod'].indexOf(l.provider)); - for (let i = 0; i < urls.length; i++) { - if (urls[i].provider === 'Mod') { - tasks.push({ type: 'Mod', url: urls[i].link_url, name: app.name }); - } else { - const etx = urls[i].link_url - .split('?')[0] - .split('.') - .pop() - .toLowerCase(); - switch (etx) { - case 'obb': - tasks.push({ type: 'OBB', url: urls[i].link_url, name: app.name }); - break; - default: - tasks.push({ type: 'APK', url: urls[i].link_url, name: app.name }); - break; - } - } - } - } - } - cb(tasks); - } else { - ecb(error || 'Nothing to install.'); - } - }); - } - endLogcat() { - if (this._logcat) { - this._logcat.end(); - this._logcat = null; - } - } - 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)); - } - installRemote(serial, path, cb, ecb) { - if (!this.client) return ecb('Not connected.'); - this.client - .installRemote(serial, path) - .then(cb) - .catch(e => ecb(e)); - } - install(serial, path, isLocal, cb, scb, ecb) { - if (!this.client) return ecb('Not connected.'); - let stream; - try { - stream = isLocal - ? fs.createReadStream(path) - : new Readable().wrap( - progress(request(path), { - throttle: 60, - }) - .on('progress', state => { - scb(state); - }) - .on('end', () => { - scb({ - percent: 1, - }); - }) - ); - } catch (e) { - const isInvalidURI = e && typeof e.message === 'string' && e.message.startsWith('Invalid URI "'); - if (isInvalidURI) { - return ecb("Can't download file. Invalid URL:"); - } else { - throw e; - } - } - this.client - .install(serial, stream) - .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)); - } - clear(serial, packageName, cb, ecb) { - if (!this.client) return ecb('Not connected.'); - this.client - .clear(serial, packageName) - .then(cb) - .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)); - } - connect(deviceIp, cb, ecb) { - if (!this.client) return ecb('Not connected.'); - this.client - .connect(deviceIp + ':5555') - .then(cb) - .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); - }); - } - usb(serial, cb, ecb) { - if (!this.client) return ecb('Not connected.'); - this.client - .usb(serial) - .then(cb) - .catch(e => ecb(e)); - } - listDevices(cb, ecb) { - if (!this.client) return ecb('Not connected.'); - this.client - .listDevices() - .then(cb) - .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)); - } - getPackages(serial, cb, ecb) { - if (!this.client) return ecb('Not connected.'); - this.client - .getPackages(serial) - .then(res => cb(res)) - .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)); - } - 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)); - } - 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(() => { - clearInterval(interval); - cb(); - }, 90000); - }); - transfer.on('end', () => { - clearTimeout(autocancel); - clearInterval(interval); - cb(); - }); - transfer.on('error', 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 => { - ecb(e); - }); - transfer.pipe(fs.createWriteStream(savePath)); - }) - .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)); - } -} diff --git a/electron/app.ts b/electron/app.ts index 4a7170b..94362ed 100644 --- a/electron/app.ts +++ b/electron/app.ts @@ -1,5 +1,4 @@ import { app, protocol, ipcMain, Menu, MenuItemConstructorOptions, BrowserWindow } from 'electron'; -import { ADB } from './adbkit'; import { StateStorage, EnvironmentConfig } from './state-storage'; import { AppWindow } from './window'; const path = require('path'); @@ -7,6 +6,360 @@ const { autoUpdater } = require('electron-updater'); const download = require('./download'); const extract = require('extract-zip'); +const adb = require('adbkit'); +const fs = require('fs'); +const crypto = require('crypto'); +const request = require('request'); +const progress = require('request-progress'); +const Readable = require('stream').Readable; +import { SetPropertiesCommand } from './setproperties'; + +class ADB { + client; + _logcat; + setupAdb(adbPath, cb, ecb) { + if (this.client) return; + this.client = adb.createClient({ + bin: adbPath, + }); + cb(); + } + async checkAPK(updateStatus: (string) => void, filePath: string): Promise { + const hash = await this.computeFileHash(updateStatus, filePath); + const url = `https://sdq.st/check-app-hash/${hash}`; + updateStatus('Checking APK against blacklist...'); + return new Promise((resolve, reject) => { + let options = { + url, + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Origin: 'https://sidequestvr.com', + }, + rejectUnauthorized: process.env.NODE_ENV !== 'dev', + }; + request(options, (error, response, body) => { + if (error) { + reject(error); + } else { + try { + resolve(JSON.parse(body).found); + } catch (e) { + reject(e); + } + } + }); + }); + } + async computeFileHash(updateStatus: (string) => void, filePath: string): Promise { + const fileSize = await this.computeFileSize(filePath); + return new Promise((resolve, reject) => { + let bytesRead: number = 0; + const fd = fs.createReadStream(filePath); + const hash = crypto.createHash('md5'); + hash.setEncoding('hex'); + fd.on('data', chunk => { + bytesRead += chunk.length; + const percentage = this.formattedPercentageComplete(bytesRead, fileSize); + updateStatus(`Computing APK hash (${percentage})...`); + }); + fd.on('end', () => { + updateStatus(`Computing APK hash (100%)...`); + hash.end(); + resolve(hash.read()); + }); + fd.on('error', error => { + reject(error); + }); + fd.pipe(hash); + }); + } + async computeFileSize(filePath: string): Promise { + return new Promise((resolve, reject) => { + fs.stat(filePath, (err, stats) => { + if (err) { + reject(err); + } else { + resolve(stats.size); + } + }); + }); + } + formattedPercentageComplete(amount: number, total: number): string { + const percentage = Math.round(Math.min(amount / total, 1) * 100); + return `${percentage}%`; + } + installFromToken(token, cb, ecb) { + let options = { + url: 'https://api.sidequestvr.com/install-from-key', + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Origin: 'https://sidequestvr.com', + }, + rejectUnauthorized: process.env.NODE_ENV !== 'dev', + json: { token: token }, + }; + request(options, (error, response, body) => { + if (!error && body.data && body.data.apps && body.data.apps.length) { + let tasks = []; + for (let i = 0; i < body.data.apps.length; i++) { + let app = body.data.apps[i]; + if (Number(app.app_categories_id) === 1) { + let urls = app.urls.filter(l => l && ~['Github Release', 'APK', 'OBB', 'Mod'].indexOf(l.provider)); + for (let i = 0; i < urls.length; i++) { + if (urls[i].provider === 'Mod') { + tasks.push({ type: 'Mod', url: urls[i].link_url, name: app.name }); + } else { + const etx = urls[i].link_url + .split('?')[0] + .split('.') + .pop() + .toLowerCase(); + switch (etx) { + case 'obb': + tasks.push({ type: 'OBB', url: urls[i].link_url, name: app.name }); + break; + default: + tasks.push({ type: 'APK', url: urls[i].link_url, name: app.name }); + break; + } + } + } + } + } + cb(tasks); + } else { + ecb(error || 'Nothing to install.'); + } + }); + } + endLogcat() { + if (this._logcat) { + this._logcat.end(); + this._logcat = null; + } + } + 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)); + } + installRemote(serial, path, cb, ecb) { + if (!this.client) return ecb('Not connected.'); + this.client + .installRemote(serial, path) + .then(cb) + .catch(e => ecb(e)); + } + async install(serial, path, isLocal, cb, scb, ecb) { + if (!this.client) return ecb('Not connected.'); + let stream; + if (isLocal) { + let found; + try { + found = await this.checkAPK(scb, path); + } catch (e) { + return ecb(e); + } + if (found) { + return ecb('SAFESIDE'); + } + } + try { + stream = isLocal + ? fs.createReadStream(path) + : new Readable().wrap( + progress(request(path), { + throttle: 60, + }) + .on('progress', state => { + scb(state); + }) + .on('end', () => { + scb({ + percent: 1, + }); + }) + ); + } catch (e) { + const isInvalidURI = e && typeof e.message === 'string' && e.message.startsWith('Invalid URI "'); + if (isInvalidURI) { + return ecb("Can't download file. Invalid URL:"); + } else { + throw e; + } + } + this.client + .install(serial, stream) + .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)); + } + clear(serial, packageName, cb, ecb) { + if (!this.client) return ecb('Not connected.'); + this.client + .clear(serial, packageName) + .then(cb) + .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)); + } + connect(deviceIp, cb, ecb) { + if (!this.client) return ecb('Not connected.'); + this.client + .connect(deviceIp + ':5555') + .then(cb) + .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); + }); + } + usb(serial, cb, ecb) { + if (!this.client) return ecb('Not connected.'); + this.client + .usb(serial) + .then(cb) + .catch(e => ecb(e)); + } + listDevices(cb, ecb) { + if (!this.client) return ecb('Not connected.'); + this.client + .listDevices() + .then(cb) + .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)); + } + getPackages(serial, cb, ecb) { + if (!this.client) return ecb('Not connected.'); + this.client + .getPackages(serial) + .then(res => cb(res)) + .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)); + } + 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)); + } + 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(() => { + clearInterval(interval); + cb(); + }, 90000); + }); + transfer.on('end', () => { + clearTimeout(autocancel); + clearInterval(interval); + cb(); + }); + transfer.on('error', 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 => { + ecb(e); + }); + transfer.pipe(fs.createWriteStream(savePath)); + }) + .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)); + } +} + let config: StateStorage; let appWindow: AppWindow; let mainWindow: BrowserWindow; @@ -297,9 +650,6 @@ function setupApp() { case 'installFromToken': adb.installFromToken(arg.settings.token, success, reject); break; - case 'hashCheck': - adb.hashCheckFile(arg.settings.path, success, status, reject); - break; case 'setupAdb': adb.setupAdb(arg.settings.adbPath, success, reject); break; diff --git a/electron/boot.ts b/electron/boot.ts new file mode 100644 index 0000000..2124737 --- /dev/null +++ b/electron/boot.ts @@ -0,0 +1,13 @@ +'use strict'; + +const bytenode = require('bytenode'); +const fs = require('fs'); +const v8 = require('v8'); + +v8.setFlagsFromString('--no-lazy'); + +if (!fs.existsSync(__dirname + '/app.jsc') || process.env.NODE_ENV === 'dev') { + bytenode.compileFile(__dirname + '/app.js', __dirname + '/app.jsc'); +} + +require('./app.jsc'); diff --git a/electron/download.ts b/electron/download.ts index b61e641..c4aaaaa 100644 --- a/electron/download.ts +++ b/electron/download.ts @@ -1,6 +1,5 @@ const https = require('https'); const http = require('http'); -const fs = require('fs'); const { basename } = require('path'); const Url = require('url'); diff --git a/package.json b/package.json index c100d48..5449192 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "repository": "https://github.com/SideQuestVR/SideQuest.git", "license": "MIT", "author": "Shane Harris", - "main": "build-electron/app.js", + "main": "build-electron/boot.js", "scripts": { "concurrently": "concurrently", "start": "concurrently \"yarn electron-build && wait-on http-get://localhost:4205/ && cross-env NODE_ENV=dev electron .\" \"cd desktop-app && ng serve --port 4205\"", @@ -52,7 +52,12 @@ "build/**/*", "node_modules/**/*", "package.json", - "build-electron/**/*" + "build-electron/boot.js", + "build-electron/app.jsc", + "build-electron/download.js", + "build-electron/setproperties.js", + "build-electron/state-storage.js", + "build-electron/window.js" ], "asarUnpack": [ "build/**/*" @@ -78,6 +83,7 @@ "dependencies": { "adbkit": "^2.11.1", "adm-zip": "^0.4.14", + "bytenode": "^1.1.6", "concurrently": "^4.1.0", "cross-env": "^5.2.0", "crypto": "^1.0.1", diff --git a/yarn.lock b/yarn.lock index 903b695..ea52b1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -491,6 +491,11 @@ builtins@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88" +bytenode@^1.1.6: + version "1.1.6" + resolved "https://registry.yarnpkg.com/bytenode/-/bytenode-1.1.6.tgz#bf8defd83e752a817205d23fa0cb10fa717080c6" + integrity sha512-hhJqv1GMtTa2q4wlfCWEnC5zWFflbJhh1qaYgaqbs8ta6mQUri2eTD76jER8XlAYPtc7IEw2lc36B3H1GTQRpQ== + bytes@3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"