Many more fixes...

This commit is contained in:
Nathanael Anderson
2024-04-11 07:52:51 -06:00
parent 48a675b71e
commit f925115472
16 changed files with 1203 additions and 257 deletions
+4 -1
View File
@@ -653,10 +653,13 @@ This can sometimes be caused by changes to your hosts file. Don't make changes u
deleteAfter?: boolean,
name?: string
) {
console.log("Starting install of APK", filePath, isLocal, shouldUninstall, number, total, deleteAfter, name)
return this.processService.addItem(
'apk_install',
task => {
if (this.deviceStatus !== ConnectionStatus.CONNECTED) {
console.log("Task APK", filePath, isLocal, shouldUninstall, number, total, deleteAfter, name)
if (this.deviceStatus !== ConnectionStatus.CONNECTED) {
return Promise.reject(name + 'Apk install failed - No device connected!');
}
const showTotal = number && total ? '(' + number + '/' + total + ') ' : '';
+25 -8
View File
@@ -42,8 +42,6 @@ export class AppService {
remote: any;
electron: any;
os: any;
request: any;
progress: any;
Readable: any;
opn: any;
spawn: any;
@@ -67,8 +65,6 @@ export class AppService {
constructor(private spinnerService: LoadingSpinnerService, private router: Router) {
this.path = (<any>window).require('path');
this.fs = (<any>window).require('fs');
this.request = (<any>window).require('request');
this.progress = (<any>window).require('request-progress');
this.os = (<any>window).require('os');
this.Readable = (<any>window).require('stream').Readable;
this.opn = (<any>window).require('opn');
@@ -372,11 +368,13 @@ export class AppService {
break;
}
let downloadPath = getPath(downloadUrl);
return this.downloadFileAPI(downloadUrl, this.path.dirname(downloadPath), this.path.basename(downloadPath), task).then(
return this.downloadFileAPI(downloadUrl, this.path.dirname(downloadPath), this.path.basename(downloadPath), {}, task).then(
() => downloadPath
);
}
downloadFileAPI(url, directory, filename, task?) {
downloadFileAPI(url, directory, filename, options, task?): Promise<string> {
// Send request to application thread to download a file. Store the callback for the response.
return new Promise((resolve, reject) => {
let token = this.uuidv4();
@@ -389,10 +387,29 @@ export class AppService {
resolve,
reject,
};
this.electron.ipcRenderer.send('download-url', { token, url, directory, filename });
this.electron.ipcRenderer.send('download-url', { token, url, directory, filename, options });
});
}
getUserAgent() {
uploadFileAPI(url, filename, options, task?): Promise<string> {
// Send request to application thread to upload a file. Store the callback for the response.
return new Promise((resolve, reject) => {
let token = this.uuidv4();
this.downloadResolves[token] = {
scb: stats => {
if (task) {
task.status = (task.app_name ? task.app_name + ': ' : '') + 'Uploading... ' + stats + '%';
}
},
resolve,
reject,
};
this.electron.ipcRenderer.send('upload-url', { token, url, filename, options });
});
}
getUserAgent() {
const nodeString = `NodeJs/${(<any>window).process.version}`;
const packageString = 'OpenStoreVR';
const computerString = `Hostname/${this.os.hostname()} Platform/${this.os.platform()} PlatformVersion/${this.os.release()}`;
+21 -38
View File
@@ -19,51 +19,34 @@ export class AudicaService {
downloadSong(downloadUrl, adbService) {
return this.processService.addItem('song_download', async (task) : Promise<void> => {
let parts = downloadUrl.split('/');
let zipPath = this.appService.path.join(this.appService.appData, this.appService.path.basename(downloadUrl));
let ws = this.appService.fs.createWriteStream(zipPath);
const requestOptions = {
timeout: 30000,
'User-Agent': this.appService.getUserAgent(),
useContentDispositionFilename: true
};
task.status = 'Saving to Audica...';
return new Promise((resolve, reject) => {
let request = this.appService
.progress(this.appService.request(downloadUrl, requestOptions), { throttle: 50 })
.on('error', error => {
task.failed = true;
task.status = 'Failed to save item... ' + error.toString();
reject(error);
})
.on('progress', state => {
task.status = 'Saving to Audica... ' + Math.round(state.percent * 100) + '%';
})
.on('response', response => {
var regexp = /filename=\"(.*)\"/gi;
var _regResult = regexp.exec(response.headers['content-disposition']);
if (_regResult && _regResult.length) {
zipPath = this.appService.path.join(this.appService.appData, _regResult[1]);
}
request.pipe(this.appService.fs.createWriteStream(zipPath));
})
.on('end', async () => {
let ext = this.appService.path.extname(zipPath).toLowerCase();
let basename = this.appService.path.basename(zipPath);
await adbService.uploadFile(
[
{
name: zipPath,
savePath: '/sdcard/Audica/' + basename,
},
],
task
);
task.status = 'Saved! ' + basename;
this.appService.fs.unlink(zipPath, err => {
if (err) console.warn(err);
});
resolve();
});
this.appService.downloadFileAPI( downloadUrl, null, zipPath, requestOptions, task).then( async (fileName) => {
let ext = this.appService.path.extname(fileName).toLowerCase();
let basename = this.appService.path.basename(fileName);
await adbService.uploadFile([ {
name: fileName,
savePath: '/sdcard/Audica/' + basename,
}], task);
task.status = 'Saved! ' + basename;
this.appService.fs.unlink(fileName, err => {
if (err) console.warn(err);
});
resolve();
}).catch((error) => {
task.failed = true;
task.status = 'Failed to save item... ' + error.toString();
reject(error);
});
});
});
}
+14 -60
View File
@@ -213,7 +213,7 @@ export class BeatOnService {
let zipPath = this.appService.path.join(this.appService.appData, this.appService.uuidv4() + '.zip');
const requestOptions = {
timeout: 30000,
'User-Agent': this.appService.getUserAgent(),
'User-Agent': this.appService.getUserAgent()
};
task.status = 'Saving to BMBF...';
return new Promise((resolve, reject) => {
@@ -223,65 +223,19 @@ export class BeatOnService {
this.beatOnPID &&
this.beatOnStatus.CurrentStatus === 'ModInstalled'
) {
this.appService
.progress(this.appService.request(downloadUrl, requestOptions), { throttle: 50 })
.on('error', error => {
task.failed = true;
task.status = 'Failed to save song... ' + error.toString();
reject(error);
})
.on('progress', state => {
task.status = 'Saving to BMBF... ' + Math.round(state.percent * 100) + '%';
})
.on('end', () => {
let formData = {
file: {
value: this.appService.fs.createReadStream(zipPath),
options: {
filename: parts[parts.length - 1],
contentType: 'application/zip',
},
},
};
let options = {
url: 'http://' + adbService.deviceIp + ':50000/host/beatsaber/upload',
method: 'POST',
formData: formData,
};
let timeoutCheck = setTimeout(() => {
if (task.fail_once) {
task.fail_once = false;
task.failed = true;
task.status = 'Failed to save song... Timeout';
reject(task.status);
} else {
task.fail_once = true;
task.running = false;
task.status = 'Waiting...';
resolve();
}
}, 30000);
this.appService
.progress(this.appService.request(options), { throttle: 50 })
.on('error', error => {
clearTimeout(timeoutCheck);
task.failed = true;
task.status = 'Failed to save song... ' + error.toString();
reject(error);
})
.on('progress', state => {
clearTimeout(timeoutCheck);
task.status = 'Uploading To Beat On... ' + Math.round(state.percent * 100) + '%';
})
.on('end', () => {
clearTimeout(timeoutCheck);
this.appService.fs.unlink(zipPath, err => {
task.status = 'Saved! ' + downloadUrl;
resolve(parts[parts.length - 1].split('.')[0]);
});
});
})
.pipe(this.appService.fs.createWriteStream(zipPath));
this.appService.downloadFileAPI( downloadUrl, null, zipPath, requestOptions, task).then( async (fileName) => {
let url = 'http://' + adbService.deviceIp + ':50000/host/beatsaber/upload';
return this.appService.uploadFileAPI( url, zipPath, {contentType: 'application/zip', fileName: parts[parts.length -1], method: "post"}, task).then( async () => {
this.appService.fs.unlink(zipPath, err => {
task.status = 'Saved! ' + downloadUrl;
resolve(parts[parts.length - 1].split('.')[0]);
});
});
}).catch((error) => {
task.failed = true;
task.status = 'Failed to save song... ' + error.toString();
reject(error);
});
} else {
reject(
new Error(
+4
View File
@@ -64,7 +64,9 @@ export class ElectronService {
}
async installFromToken(token) {
console.log("Install from token", token)
let res = await this.adbService.adbCommand('installFromToken', { token });
console.log("IT: res", res)
res.forEach((l, i) => {
switch (l.type) {
case 'Mod':
@@ -121,6 +123,7 @@ export class ElectronService {
}
});
this.appService.electron.ipcRenderer.on('open-url', async (event, data) => {
console.log("Open URL", data);
if (data) {
let url = data.split('#');
switch (url[0]) {
@@ -143,6 +146,7 @@ export class ElectronService {
this.adbService.uninstallAPK(url[1]);
break;
case 'sidequest://sideload-multi/':
console.log("SQM", data)
try {
let urls = JSON.parse(
data
@@ -50,10 +50,10 @@ export class HeaderBannerComponent implements OnInit {
async getLatestApk() {
const request = (await fetch(environment.configuration.http_url + '/v2/apps/get-sidequest-apk', {
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;
@@ -69,23 +69,12 @@ export class HeaderBannerComponent implements OnInit {
}
console.log('downloadAPK', this.appId);
return new Promise<void>((resolve, reject) => {
const requestOptions = {
timeout: 30000,
const requestOptions = {
timeout: 60000,
'User-Agent': this.appService.getUserAgent(),
};
this.appService
.request(this.apkDownloadPath, requestOptions)
.on('error', error => {
console.log(`Request Error ${error}`);
reject(error);
})
.on('progress', state => {})
.on('end', () => {
return resolve();
})
.pipe(this.appService.fs.createWriteStream(this.appService.path.join(this.appService.appData, 'experimental.apk')));
});
};
const fileName = this.appService.path.join(this.appService.appData, 'experimental.apk');
return this.appService.downloadFileAPI(this.apkDownloadPath, null, fileName, requestOptions, null);
}
useBundledAPK() {
+12 -13
View File
@@ -283,23 +283,22 @@ export class HeaderComponent implements OnInit {
this.bookmarksModal.closeModal();
}
}
addCurrentFavourite() {
this.appService.request(
'https://i.olsh.me/allicons.json?url=' + this.webService.currentAddress,
(error, response, body) => {
let json: any = {};
try {
json = JSON.parse(response.body);
} catch (e) {}
this.favourites.browserFavourites.unshift({
async addCurrentFavourite() {
const request = await fetch( 'https://i.olsh.me/allicons.json?url=' + this.webService.currentAddress, {
method: 'GET',
headers: { "Content-Type": "application/json" }
});
let json = await request.json();
this.favourites.browserFavourites.unshift({
name: this.webService.getTitle(),
uri: this.webService.currentAddress,
icon: json && json.icons && json.icons.length ? json.icons[0].url : '',
});
this.saveFavourites('browserFavourites');
}
);
});
this.saveFavourites('browserFavourites');
}
async selectAppToInstall() {
let files = await this.appService.remote.dialog.showOpenDialog({
properties: ['openFile', 'multiSelections'],
+19 -20
View File
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { AppService } from '../app.service';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root',
@@ -10,25 +11,23 @@ export class PackageService {
constructor(private appService: AppService) {
this.getAppIndex();
}
getAppIndex() {
this.appService.request(this.indexUrl);
return new Promise((resolve, reject) => {
this.appService.request(this.indexUrl + 'app-index.json', (error, response, body) => {
if (error) {
return reject(error);
} else {
try {
let body = JSON.parse(response.body);
Object.keys(body).forEach(packageName => {
this.allApps[packageName] = body[packageName];
this.allApps[packageName].icon = this.indexUrl + this.allApps[packageName].icon;
});
resolve(true);
} catch (e) {
return reject('JSON parse Error');
}
}
});
});
async getAppIndex() {
const request = await fetch(this.indexUrl, {
method: 'GET',
headers: { "Content-Type": "application/json" }
});
let json = await request.json();
const request2 = await fetch(this.indexUrl + 'app-index.json', {
method: 'GET',
headers: { "Content-Type": "application/json" }
});
let body = await request2.json();
Object.keys(body).forEach(packageName => {
this.allApps[packageName] = body[packageName];
this.allApps[packageName].icon = this.indexUrl + this.allApps[packageName].icon;
});
return true;
}
}
+4 -12
View File
@@ -56,20 +56,13 @@ export class SongBeaterService {
let name = parts[parts.length - 1].split('.')[0];
const requestOptions = {
timeout: 30000,
'User-Agent': this.appService.getUserAgent(),
'User-Agent': this.appService.getUserAgent()
};
return this.processService.addItem('song_download', async (task) : Promise<void> => {
return new Promise((resolve, reject) => {
this.appService
.progress(this.appService.request(downloadUrl, requestOptions), { throttle: 300 })
.on('error', error => {
reject(error);
})
.on('progress', state => {
this.spinnerService.setMessage('Saving to SongBeater... ' + Math.round(state.percent * 100) + '%');
})
.on('end', () => {
let dir = this.appService.path.join(this.appService.appData, 'temp', name);
this.spinnerService.setMessage('Saving to SongBeater... ');
this.appService.downloadFileAPI( downloadUrl, null, zipPath, requestOptions, task).then( async (fileName) => {
let dir = this.appService.path.join(this.appService.appData, 'temp', name);
this.appService.fs.mkdir(dir, () => {
this.appService.extract(zipPath, { dir: dir }, error => {
this.appService.fs.unlink(zipPath, err => {
@@ -88,7 +81,6 @@ export class SongBeaterService {
});
});
})
.pipe(this.appService.fs.createWriteStream(zipPath));
});
});
}
+7 -22
View File
@@ -19,35 +19,16 @@ export class SynthriderService {
downloadSong(downloadUrl, adbService) {
return this.processService.addItem('song_download', async (task) : Promise<void> => {
let parts = downloadUrl.split('/');
let zipPath = this.appService.path.join(this.appService.appData, this.appService.path.basename(downloadUrl));
let ws = this.appService.fs.createWriteStream(zipPath);
//let name = parts[parts.length - 1].split('.')[0];
const requestOptions = {
timeout: 30000,
'User-Agent': this.appService.getUserAgent(),
useContentDispositionFilename: true,
};
task.status = 'Saving to SynthRiders...';
return new Promise((resolve, reject) => {
let request = this.appService
.progress(this.appService.request(downloadUrl, requestOptions), { throttle: 50 })
.on('error', error => {
task.failed = true;
task.status = 'Failed to save item... ' + error.toString();
reject(error);
})
.on('progress', state => {
task.status = 'Saving to SynthRiders... ' + Math.round(state.percent * 100) + '%';
})
.on('response', response => {
var regexp = /filename=\"(.*)\"/gi;
var _regResult = regexp.exec(response.headers['content-disposition']);
if (_regResult && _regResult.length) {
zipPath = this.appService.path.join(this.appService.appData, decodeURIComponent(_regResult[1]));
}
request.pipe(this.appService.fs.createWriteStream(zipPath));
})
.on('end', async () => {
this.appService.downloadFileAPI( downloadUrl, null, zipPath, requestOptions, task).then( async (fileName) => {
let zipPath = fileName;
let ext = this.appService.path.extname(zipPath).toLowerCase();
let basename = this.appService.path.basename(zipPath);
await adbService.uploadFile(
@@ -73,6 +54,10 @@ export class SynthriderService {
if (err) console.warn(err);
});
resolve();
}).catch((error) => {
task.failed = true;
task.status = 'Failed to save item... ' + error.toString();
reject(error);
});
});
});