Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
reisxd committed Aug 5, 2022
2 parents 32ffe9b + 56a1412 commit 4f2bfa5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
41 changes: 22 additions & 19 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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
Expand Down Expand Up @@ -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!");
Expand All @@ -103,12 +103,12 @@ function setAppVersion () {
}
}

function getAppVersions (isRooted) {
function getAppVersions(isRooted) {
document.getElementsByTagName('header')[0].innerHTML = `
<h1>Select the version you want to download</h1>
${
isRooted
? "<span>You are building rooted ReVanced, you'll need to download the version matching with your YouTube version.<br>(You'll also need YouTube installed)<span>"
? "<span><strong>You are building rooted ReVanced</strong>, you'll need to download the version matching with your YouTube version.<br>(You'll also need YouTube installed)<br>If you didn't intend on doing a rooted build, include all \"Root required to exclude\" patches<span>"
: ''
}
`;
Expand All @@ -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');
}

Expand Down Expand Up @@ -241,13 +241,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 = `
<h1>Use already downloaded APK?</h1>
<span>The APK already exists in the revanced folder.<br>Do you want to use it?${
message.isRooted
? '<br>(Saying no is recommended for rooted building)'
: ''
}</span>`;
<span>The APK already exists in the revanced folder.${
message.isRooted ? ' ' : '<br>'
}Do you want to use it?${
message.isRooted
? '<br>(Saying no is recommended for rooted building)<br>If you didn\'t intend on doing a rooted build, include all "Root required to exclude" patches'
: ''
}</span>`;

const continueButtonn = document.getElementById('continue');
const backButton = document.getElementById('back');
Expand Down
27 changes: 26 additions & 1 deletion wsEvents/GetAppVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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': {
Expand All @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion wsEvents/GetPatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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;

Expand Down

0 comments on commit 4f2bfa5

Please sign in to comment.