More cleanups for actual distributable builds set to proper environment

This commit is contained in:
Nathanael Anderson
2024-04-11 09:21:27 -06:00
parent 8e23e82ac4
commit 09a9441e6e
6 changed files with 54 additions and 39 deletions
+24 -24
View File
@@ -13,8 +13,7 @@ const Readable = require('stream').Readable;
const Adb = require('@devicefarmer/adbkit').Adb;
const fs = require('fs');
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');
@@ -94,20 +93,19 @@ class ADB {
},
rejectUnauthorized: process.env.NODE_ENV !== 'dev',
};
request(url, options, (error, response, body) => {
if (error) {
reject(error);
} else {
try {
const found = JSON.parse(body).found;
if (!found) {
updateStatus('APK is not in the blacklist. Installing...');
}
resolve(found);
} catch (e) {
reject(e);
}
fetch(url, options).then((response) => {
if (!response.ok || response.body == null) {
console.log(response.statusText, response.status, response.headers);
return reject(response.statusText);
}
response.json().then(body => {
let found = body.found;
if (!found) {
updateStatus('APK is not in the blacklist. Installing...');
}
resolve(found);
}).catch(reject);
});
});
}
@@ -150,20 +148,24 @@ class ADB {
return `${percentage}%`;
}
installFromToken(token, cb, ecb) {
let url = `${getEnvCfg().http_url || 'https://api.sidequestvr.com'}/install-from-key`;
let options = {
url: `${getEnvCfg().http_url || 'https://api.sidequestvr.com'}/install-from-key`,
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Origin: getEnvCfg().web_url || 'https://sidequestvr.com',
},
rejectUnauthorized: process.env.NODE_ENV !== 'dev',
json: { token: token },
// rejectUnauthorized: process.env.NODE_ENV !== 'dev',
body: JSON.stringify({ token: token }),
};
console.log("IFT:", options)
request(options.url, options, (error, response, body) => {
if (!error && body.data && body.data.apps && body.data.apps.length) {
console.log("IFT:", url, options)
fetch(url, options).then(response => {
if (!response.ok || response.body == null) {
console.log(response.statusText, response.status, response.headers);
return ecb('Unable to fetch package');
}
response.json().then(body => {
let tasks = [];
console.log("IFT Body", body);
for (let i = 0; i < body.data.apps.length; i++) {
@@ -192,9 +194,7 @@ class ADB {
}
}
cb(tasks);
} else {
ecb(error || 'Nothing to install.');
}
}).catch(ecb);
});
}
endLogcat() {
+2
View File
@@ -0,0 +1,2 @@
// This file is overwritten by the build process
+4 -1
View File
@@ -1,6 +1,9 @@
require('./config');
export function getEnvCfg() {
switch (process.env['SQ_ENV_CFG']) {
const cfg = process.env['SQ_ENV_CFG'] || global.SQ_ENV_CFG;
console.log('SQ_ENV_CFG:', cfg);
switch (cfg) {
case 'test':
return {
web_url: 'https://sidetestvr.com',
+9
View File
@@ -0,0 +1,9 @@
const fs = require('node:fs');
let cfg = ""
if (process.argv[2]) {
cfg = process.argv[2];
}
// Output should be in the build-electron folder
fs.writeFileSync(__dirname + "/../build-electron/config.js", `global.SQ_ENV_CFG = "${cfg}";`)