Skip to content

Commit

Permalink
Many more fixes...
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanaelA committed Apr 11, 2024
1 parent 48a675b commit f925115
Show file tree
Hide file tree
Showing 16 changed files with 1,203 additions and 257 deletions.
5 changes: 4 additions & 1 deletion desktop-app/src/app/adb-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ') ' : '';
Expand Down
33 changes: 25 additions & 8 deletions desktop-app/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export class AppService {
remote: any;
electron: any;
os: any;
request: any;
progress: any;
Readable: any;
opn: any;
spawn: any;
Expand All @@ -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');
Expand Down Expand Up @@ -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();
Expand All @@ -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()}`;
Expand Down
59 changes: 21 additions & 38 deletions desktop-app/src/app/audica.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


});
});
}
Expand Down
74 changes: 14 additions & 60 deletions desktop-app/src/app/beat-on.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions desktop-app/src/app/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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]) {
Expand All @@ -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
Expand Down
25 changes: 7 additions & 18 deletions desktop-app/src/app/header-banner/header-banner.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
25 changes: 12 additions & 13 deletions desktop-app/src/app/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
39 changes: 19 additions & 20 deletions desktop-app/src/app/packages/package.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { AppService } from '../app.service';
import { environment } from '../../environments/environment';

@Injectable({
providedIn: 'root',
Expand All @@ -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;
}
}
Loading

0 comments on commit f925115

Please sign in to comment.