Skip to content

Commit

Permalink
feat: add support for ARSCLib inotia00/ReVanced_Extended#2191
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Jul 5, 2024
1 parent 03d0bd7 commit 13f874a
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 5 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {
installReVanced,
patchApp,
patchAppWithRipLibs,
patchAppArscLib,
selectApp,
selectAppVersion,
selectPatches,
Expand Down Expand Up @@ -200,6 +201,9 @@ wsServer.on('connection', (ws) => {
case 'patchAppWithRipLibs':
await patchAppWithRipLibs(ws);
break;
case 'patchAppArscLib':
await patchAppArscLib(ws);
break;
case 'selectApp':
selectApp(message);
break;
Expand Down
30 changes: 27 additions & 3 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function setAppVersion(arch, version) {
if (arch == null && versionChecked === null)
return alert("You didn't select an app version!");

if (versionChecked !== null) {
if (versionChecked !== null && !localStorage.getItem('arsclib')) {
if (
versionChecked.hasAttribute('data-recommended') &&
versionChecked.getAttribute('data-recommended') !== '1'
Expand Down Expand Up @@ -179,7 +179,9 @@ function getAppVersions(isRooted, page = 1) {
}

function buildReVanced() {
if (localStorage.getItem('rip-libs')) {
if (localStorage.getItem('arsclib')) {
sendCommand({ event: 'patchAppArscLib' });
} else if (localStorage.getItem('rip-libs')) {
sendCommand({ event: 'patchAppWithRipLibs' });
} else {
sendCommand({ event: 'patchApp' });
Expand Down Expand Up @@ -306,6 +308,12 @@ function setSources() {
});
}

function disableARSCLib() {
if (localStorage.getItem('arsclib')) {
document.getElementById('ARSCLibBtn').click();
}
}

function setSourcesRVX() {
document.getElementById('cli-org').value = 'inotia00';
document.getElementById('cli-src').value = 'revanced-cli';
Expand All @@ -319,6 +327,7 @@ function setSourcesRVX() {
document.getElementById('microg-org').value = 'ReVanced';
document.getElementById('microg-src').value = 'GmsCore';

disableARSCLib();
setSources();
}

Expand All @@ -332,6 +341,7 @@ function setSourcesReX() {
document.getElementById('integrations-org').value = 'YT-Advanced';
document.getElementById('integrations-src').value = 'ReX-integrations';

disableARSCLib();
setSources();
}

Expand All @@ -345,6 +355,20 @@ function setSourcesRVX_anddea() {
document.getElementById('integrations-org').value = 'anddea';
document.getElementById('integrations-src').value = 'revanced-integrations';

disableARSCLib();
setSources();
}

function setSourcesRVX_ARSCLib() {
document.getElementById('cli-org').value = 'inotia00';
document.getElementById('cli-src').value = 'revanced-cli-arsclib';

document.getElementById('patch-org').value = 'inotia00';
document.getElementById('patch-src').value = 'revanced-patches-arsclib';

document.getElementById('integrations-org').value = 'inotia00';
document.getElementById('integrations-src').value = 'revanced-integrations';

setSources();
}

Expand Down Expand Up @@ -459,7 +483,7 @@ ws.onmessage = (msg) => {

versionsElement.innerHTML += `
${
message.page == 1 && i == 0
message.page == 1 && i == 0 && !localStorage.getItem('arsclib')
? `<li><input type="radio" name="version" id="app-${len}" value="${
autoSelect
}" data-beta="0" data-recommended="1"/>
Expand Down
14 changes: 13 additions & 1 deletion public/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ if (localStorage.getItem('pre-releases')) {
if (localStorage.getItem('rip-libs')) {
document.getElementById('ripLibsBtn').checked = true;
}
if (localStorage.getItem('arsclib')) {
document.getElementById('ARSCLibBtn').checked = true;
}

accentColors.forEach((color) => {
if (
Expand Down Expand Up @@ -60,4 +63,13 @@ document.getElementById('ripLibsBtn').addEventListener('click', function () {
} else {
localStorage.setItem('rip-libs', true);
}
});
});
document.getElementById('ARSCLibBtn').addEventListener('click', function () {
if (localStorage.getItem('arsclib')) {
localStorage.removeItem('arsclib');
document.getElementById('set-sources-rvx').click();
} else {
localStorage.setItem('arsclib', true);
document.getElementById('set-sources-rvx-arsclib').click();
}
});
18 changes: 18 additions & 0 deletions public/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ <h3>
autocomplete="off" /><span class="slider"></span
></label>
</div>
<div class="option">
<h3>
<i class="fa-solid fa-screwdriver-wrench"></i>ARSCLib (WIP)
</h3>

<p>
Use ARSCLib (WIP).
<br /><br />Caution: ARSCLib is still in the development stage, so there may be some features that don't work.
</p>
<label class="switch"
><input
class="check"
id="ARSCLibBtn"
type="checkbox"
autocomplete="off" /><span class="slider"></span
></label>
</div>
<div id="src" class="option">
<h3><i class="fa-solid fa-server"></i>Sources</h3>

Expand All @@ -134,6 +151,7 @@ <h3><i class="fa-solid fa-server"></i>Sources</h3>
<button id="set-sources-rvx" class="highlighted" onclick="setSourcesRVX();">RVX</button>
<button id="set-sources-rex" class="highlighted" onclick="setSourcesReX();">ReX</button>
<button id="set-sources-rvx-anddea" class="highlighted" onclick="setSourcesRVX_anddea();">RVX (anddea)</button>
<button id="set-sources-rvx-arsclib" class="highlighted" onclick="setSourcesRVX_ARSCLib();"></button>
<button id="set-sources-pre-releases" class="highlighted" onclick="setSourcesPreReleases();"></button>
</div>

Expand Down
4 changes: 4 additions & 0 deletions public/styles/fontawesome.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
content: '\f121';
}

.fa-screwdriver-wrench:before {
content: '\f7d9';
}

.fa-download:before {
content: '\f019';
}
Expand Down
4 changes: 4 additions & 0 deletions public/styles/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ p {
margin-bottom: 15px;
}

#set-sources-rvx-arsclib {
display: none;
}

#set-sources-pre-releases {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion utils/PatchesParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = async function parsePatch(packageName, hasRoot) {
description: patch.description || ' ',
maxVersion: compatibleVersion || ' ',
isRooted,
excluded: patch.excluded || patch.deprecated || !patch.use
excluded: patch.excluded || (patch.use !== undefined && !patch.use)
});
}

Expand Down
2 changes: 2 additions & 0 deletions wsEvents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const getSettings = require('./getSettings.js');
const installReVanced = require('./installReVanced.js');
const patchApp = require('./patchApp.js');
const patchAppWithRipLibs = require('./patchAppWithRipLibs.js');
const patchAppArscLib = require('./patchAppArscLib.js');
const selectApp = require('./selectApp.js');
const selectAppVersion = require('./selectAppVersion.js');
const selectPatches = require('./selectPatches.js');
Expand All @@ -26,6 +27,7 @@ module.exports = {
installReVanced,
patchApp,
patchAppWithRipLibs,
patchAppArscLib,
selectApp,
selectAppVersion,
selectPatches,
Expand Down
183 changes: 183 additions & 0 deletions wsEvents/patchAppArscLib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
const { spawn } = require('node:child_process');
const { version } = require('node:os');
const { rmSync, renameSync } = require('node:fs');
const { join, sep: separator } = require('node:path');

const exec = require('../utils/promisifiedExec.js');

/**
* @param {import('ws').WebSocket} ws
*/
async function afterBuild(ws) {
outputName();
renameSync(
join(global.revancedDir, 'base.apk'),
join(global.revancedDir, global.outputName)
);

if (process.platform === 'android') {
await exec(
`cp "${join(
global.revancedDir,
global.outputName
)}" "/storage/emulated/0/${global.outputName}"`
);

ws.send(
JSON.stringify({
event: 'patchLog',
log: `Copied files over to /storage/emulated/0/!\nPlease install ReVanced, its located in /storage/emulated/0/${global.outputName}\nand if you are building YT/YTM ReVanced without root, also install /storage/emulated/0/microg.apk.`
})
);
}
else if (!(global.jarNames.devices && global.jarNames.devices[0]))
ws.send(
JSON.stringify({
event: 'patchLog',
log: `ReVanced has been built!\nPlease transfer over revanced/${global.outputName} and if you are using YT/YTM, revanced/microg.apk and install them!`
})
);

if (global.jarNames.devices && global.jarNames.devices[0]) {
ws.send(JSON.stringify({ event: 'buildFinished', install: true }));
} else ws.send(JSON.stringify({ event: 'buildFinished' }));
}

async function reinstallReVanced() {
let pkgNameToGetUninstalled;

switch (global.jarNames.selectedApp.packageName) {
case 'com.reddit.frontpage':
pkgNameToGetUninstalled = 'com.reddit.frontpage';
break;
}

await exec(
`adb -s ${global.jarNames.deviceID} uninstall ${pkgNameToGetUninstalled}`
);
await exec(
`adb -s ${global.jarNames.deviceID} install ${join(
global.revancedDir,
global.outputName
)}`
);
}

function outputName() {
const part1 = 'ReVanced';
let part2 = global.jarNames?.selectedApp?.appName
? global.jarNames.selectedApp.appName.replace(/[^a-zA-Z0-9\\.\\-]/g, '')
: global?.jarNames?.packageName
? global.jarNames.packageName.replace(/\./g, '')
: ''; // make the app name empty if we cannot detect it

// TODO: If the existing input APK is used from revanced/ without downloading, version and arch aren't set
const part3 = global?.apkInfo?.version ? `v${global.apkInfo.version}` : '';
const part4 = global?.apkInfo?.arch;
const part5 = `cli_${global.jarNames.cli
.split(separator)
.at(-1)
.replace('revanced-cli-', '')
.replace('.jar', '')}`;
const part6 = `patches_${global.jarNames.patchesJar
.split(separator)
.at(-1)
.replace('revanced-patches-', '')
.replace('.jar', '')}`;

// Filename: ReVanced-<AppName>-<AppVersion>-[Arch]-cli_<CLI_Version>-patches_<PatchesVersion>.apk
let outputName = '';

for (const part of [part1, part2, part3, part4, part5, part6])
if (part) outputName += `-${part}`;

outputName += '.apk';

global.outputName = outputName.substring(1);
}

/**
* @param {string[]} args
* @param {import('ws').WebSocket} ws
*/
function reportSys(args, ws) {
ws.send(
JSON.stringify({
event: 'error',
error:
'An error occured while starting the patching process. Please see the server console.'
})
);

console.log(
'[builder] Please report these informations to https://github.com/reisxd/revanced-builder/issues'
);
console.log(
`OS: ${process.platform}\nArguements: ${args.join(
', '
)}\n OS Version${version()}`
);
}

/**
* @param {import('ws').WebSocket} ws
*/
module.exports = async function patchAppArscLib(ws) {
/** @type {string[]} */
const args = [
'-jar',
global.jarNames.cli,
'-b',
global.jarNames.patchesJar,
'-m',
global.jarNames.integrations,
'--options',
'./options.json',
'--experimental',
'-a',
`${join(global.revancedDir, global.jarNames.selectedApp.packageName)}.apk`,
'-o',
'revanced'
];

args.push(...global.jarNames.includedPatches);
args.push(...global.jarNames.excludedPatches);

const buildProcess = spawn(global.javaCmd, args);

buildProcess.stdout.on('data', async (data) => {
ws.send(
JSON.stringify({
event: 'patchLog',
log: data.toString()
})
);

if (data.toString().includes('Finished')) await afterBuild(ws);

if (data.toString().includes('INSTALL_FAILED_UPDATE_INCOMPATIBLE')) {
await reinstallReVanced(ws);
await afterBuild(ws);
}

if (data.toString().includes('Unmatched')) reportSys(args, ws);
});

buildProcess.stderr.on('data', async (data) => {
ws.send(
JSON.stringify({
event: 'patchLog',
log: data.toString()
})
);

if (data.toString().includes('Finished')) await afterBuild(ws);

if (data.toString().includes('INSTALL_FAILED_UPDATE_INCOMPATIBLE')) {
await reinstallReVanced(ws);
await afterBuild(ws);
}

if (data.toString().includes('Unmatched')) reportSys(args, ws);
});
};

0 comments on commit 13f874a

Please sign in to comment.