From e1c249c483e42a56bdf5da60f69fd1f7c9b7d0cb Mon Sep 17 00:00:00 2001
From: ActuallyTheSun <>
Date: Fri, 5 Aug 2022 12:16:02 +0300
Subject: [PATCH] sevreal idiotproofing changes
---
public/index.js | 51 +++++++++++++++++++++------------------
wsEvents/GetAppVersion.js | 31 +++++++++++++++++++++---
wsEvents/GetPatches.js | 10 +++++---
3 files changed, 62 insertions(+), 30 deletions(-)
diff --git a/public/index.js b/public/index.js
index 5efc1c01..fdc8289e 100644
--- a/public/index.js
+++ b/public/index.js
@@ -5,11 +5,11 @@ let alreadyAddedLog = false;
let isDownloading = false;
let hasFinished = false;
-function sendCommand (args) {
+function sendCommand(args) {
ws.send(JSON.stringify(args));
}
-function setApp () {
+function setApp() {
if (!document.querySelector('input[name="app"]:checked')) {
return alert("You didn't select an app to patch!");
}
@@ -20,27 +20,27 @@ function setApp () {
location.href = '/dependencies';
}
-function loadPatches () {
+function loadPatches() {
sendCommand({ event: 'getPatches' });
}
-function updateFiles () {
+function updateFiles() {
sendCommand({ event: 'updateFiles' });
}
-function toggle (bool) {
+function toggle(bool) {
for (const checkbox of document.getElementsByClassName('select')) {
checkbox.checked = bool;
}
}
-function goToPatches () {
+function goToPatches() {
if (hasFinished) {
location.href = '/patches';
}
}
-function setPatches () {
+function setPatches() {
// To the person whos reading:
// For some fucking reason, assigning the checked checkboxes into a constant variable would
// give me an empty array. This is why I'm doing this -reis
@@ -82,7 +82,7 @@ function setPatches () {
location.href = '/versions';
}
-function setAppVersion () {
+function setAppVersion() {
if (!isDownloading) {
if (!document.querySelector('input[name="version"]:checked')) {
return alert("You didn't select an app version!");
@@ -103,12 +103,12 @@ function setAppVersion () {
}
}
-function getAppVersions (isRooted) {
+function getAppVersions(isRooted) {
document.getElementsByTagName('header')[0].innerHTML = `
Select the version you want to download
${
isRooted
- ? "You are building rooted ReVanced, you'll need to download the version matching with your YouTube version. (You'll also need YouTube installed)"
+ ? "You are building rooted ReVanced, you'll need to download the version matching with your YouTube version. (You'll also need YouTube installed) If you didn't intend on doing a rooted build, include all \"Root required to exclude\" patches"
: ''
}
`;
@@ -121,18 +121,18 @@ function getAppVersions (isRooted) {
sendCommand({ event: 'getAppVersion' });
}
-function buildReVanced () {
+function buildReVanced() {
sendCommand({ event: 'patchApp' });
}
-function getAlreadyExists () {
+function getAlreadyExists() {
sendCommand({ event: 'checkFileAlreadyExists' });
}
-function openAbout () {
+function openAbout() {
window.open('/about', '_blank');
}
-function openGitHub () {
+function openGitHub() {
window.open('https://github.com/reisxd/revanced-builder', '_blank');
}
@@ -169,9 +169,10 @@ ws.onmessage = (msg) => {
case 'downloadingFile': {
isDownloading = true;
if (!document.getElementsByClassName('log')[0]) {
- document.getElementById('content').innerHTML = '';
+ document.getElementById('content').innerHTML =
+ '';
document.getElementsByTagName('main')[0].innerHTML +=
- '';
+ '';
}
if (!currentFile) currentFile = message.name;
if (currentFile === message.name) {
@@ -223,13 +224,16 @@ ws.onmessage = (msg) => {
}
case 'fileExists': {
+ // TODO: on a root install, if the file already exists and the user selects yes it skips checking if a device is plugged in
document.getElementsByTagName('header')[0].innerHTML = `
Use already downloaded APK?
- The APK already exists in the revanced folder. Do you want to use it?${
- message.isRooted
- ? ' (Saying no is recommended for rooted building)'
- : ''
- }`;
+ The APK already exists in the revanced folder.${
+ message.isRooted ? ' ' : ' '
+ }Do you want to use it?${
+ message.isRooted
+ ? ' (Saying no is recommended for rooted building) If you didn\'t intend on doing a rooted build, include all "Root required to exclude" patches'
+ : ''
+ }`;
const continueButtonn = document.getElementById('continue');
const backButton = document.getElementById('back');
@@ -248,9 +252,8 @@ ws.onmessage = (msg) => {
case 'buildFinished': {
document.getElementsByTagName('header')[0].innerHTML =
'
ReVanced has been built.
';
- document.getElementsByTagName(
- 'footer'
- )[0].innerHTML += '';
+ document.getElementsByTagName('footer')[0].innerHTML +=
+ '';
break;
}
diff --git a/wsEvents/GetAppVersion.js b/wsEvents/GetAppVersion.js
index 9536d3ac..037d52c9 100644
--- a/wsEvents/GetAppVersion.js
+++ b/wsEvents/GetAppVersion.js
@@ -3,8 +3,12 @@ const { load } = require('cheerio');
const os = require('os');
const getAppVersion = require('../utils/getAppVersion.js');
const downloadApp = require('../utils/downloadApp.js');
+const { exec } = require('child_process');
+const { promisify } = require('util');
-async function getPage (pageUrl) {
+const actualExec = promisify(exec);
+
+async function getPage(pageUrl) {
const pageRequest = await fetchURL(pageUrl, {
headers: {
'user-agent':
@@ -14,7 +18,7 @@ async function getPage (pageUrl) {
return await pageRequest.text();
}
-module.exports = async function (message, ws) {
+module.exports = async function (message, ws) {
let versionsList;
if (global.jarNames.isRooted && os.platform() !== 'android') {
@@ -28,6 +32,17 @@ module.exports = async function (message, ws) {
);
}
+ actualExec('adb shell su -c exit').catch(() => {
+ return ws.send(
+ JSON.stringify({
+ event: 'error',
+ error:
+ 'The plugged in device is not rooted or Shell was denied root access. \
+ If you didn\'t intend on doing a rooted build, include all "Root required to exclude" patches'
+ })
+ );
+ });
+
let pkgName;
switch (global.jarNames.selectedApp) {
case 'youtube': {
@@ -40,6 +55,16 @@ module.exports = async function (message, ws) {
}
}
const appVersion = await getAppVersion(pkgName);
+ // if youtube isn't installed the function just returns null instead of erroring. i do not want to mess with regex's so i added this instead
+ if (!appVersion) {
+ return ws.send(
+ JSON.stringify({
+ event: 'error',
+ error:
+ "The app you selected is not installed on your device. It's needed for rooted ReVanced."
+ })
+ );
+ }
return await downloadApp(appVersion, ws);
}
@@ -104,4 +129,4 @@ module.exports = async function (message, ws) {
versionList
})
);
-}
+};
diff --git a/wsEvents/GetPatches.js b/wsEvents/GetPatches.js
index c3b0a647..c574e940 100644
--- a/wsEvents/GetPatches.js
+++ b/wsEvents/GetPatches.js
@@ -3,7 +3,7 @@ const { exec } = require('child_process');
const os = require('os');
const actualExec = promisify(exec);
-module.exports = async function (message, ws) {
+module.exports = async function (message, ws) {
const patchList = [];
const getPatches = await actualExec(
`java -jar ${global.jarNames.cli} -a ${global.jarNames.integrations} -b ${global.jarNames.patchesJar} -l --with-packages`
@@ -46,7 +46,11 @@ module.exports = async function (message, ws) {
continue;
}
- const rootedPatches = ['microg-support', 'hide-cast-button'];
+ const rootedPatches = [
+ 'microg-support',
+ 'hide-cast-button',
+ 'music-microg-support'
+ ];
if (rootedPatches.includes(patch.trim())) isRooted = true;
@@ -67,4 +71,4 @@ module.exports = async function (message, ws) {
patchList
})
);
-}
+};