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

Commit

Permalink
Merge pull request #192 from shrihanDev/main
Browse files Browse the repository at this point in the history
feat: rename output APK with info about the build
  • Loading branch information
reis authored Aug 8, 2022
2 parents 7ae9e54 + 3178bd8 commit dfe15b3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const wsServer = new WebSocketServer({ server });

app.use(morgan('dev'));
app.use(Express.static(path.join(__dirname, 'public')));
app.use(
'/revanced.apk',
Express.static(path.join(__dirname, 'revanced/revanced.apk'))
);
app.get('/revanced.apk', function (req, res) {
const file = path.join(__dirname, 'revanced', global.outputName);
res.download(file);
});

const open = async () => {
if (require('os').platform === 'android') {
Expand Down
15 changes: 8 additions & 7 deletions utils/downloadApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,44 @@ const fetchURL = require('node-fetch');
const { load } = require('cheerio');
const { dloadFromURL } = require('../utils/FileDownlader.js');

module.exports = async function (version, ws, arch) {
const apkVersion = version.replace(/\./g, '-');
module.exports = async function (ws) {
const { version, arch } = global.apkInfo;
const apkMirrorVersionArg = version.replace(/\./g, '-');

let versionDownload;

switch (global.jarNames.selectedApp) {
case 'youtube': {
versionDownload = await fetchURL(
`https://www.apkmirror.com/apk/google-inc/youtube/youtube-${apkVersion}-release/`
`https://www.apkmirror.com/apk/google-inc/youtube/youtube-${apkMirrorVersionArg}-release/`
);
break;
}

case 'music': {
versionDownload = await fetchURL(
`https://www.apkmirror.com/apk/google-inc/youtube-music/youtube-music-${apkVersion}-release/`
`https://www.apkmirror.com/apk/google-inc/youtube-music/youtube-music-${apkMirrorVersionArg}-release/`
);
break;
}

case 'android': {
versionDownload = await fetchURL(
`https://www.apkmirror.com/apk/twitter-inc/twitter/twitter-${apkVersion}-release/`
`https://www.apkmirror.com/apk/twitter-inc/twitter/twitter-${apkMirrorVersionArg}-release/`
);
break;
}

case 'frontpage': {
versionDownload = await fetchURL(
`https://www.apkmirror.com/apk/redditinc/reddit/reddit-${apkVersion}-release/`
`https://www.apkmirror.com/apk/redditinc/reddit/reddit-${apkMirrorVersionArg}-release/`
);
break;
}

case 'warnapp': {
versionDownload = await fetchURL(
`https://www.apkmirror.com/apk/deutscher-wetterdienst/warnwetter/warnwetter-${apkVersion}-release/`
`https://www.apkmirror.com/apk/deutscher-wetterdienst/warnwetter/warnwetter-${apkMirrorVersionArg}-release/`
);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion utils/mountReVanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const actualExec = promisify(exec);
module.exports = async function (pkg, ws) {
// Copy ReVanced APK to temp.
await actualExec(
'su -c \'cp "revanced/revanced.apk" "/data/local/tmp/revanced.delete"\''
`su -c 'cp "revanced/${global.outputName}" "/data/local/tmp/revanced.delete"'`
);
// Create folder
await actualExec('su -c \'mkdir -p "/data/adb/revanced/"\'');
Expand Down
54 changes: 48 additions & 6 deletions wsEvents/PatchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ async function mount (ws) {

async function afterBuild (ws) {
fs.rmdirSync('./revanced-cache', { recursive: true, force: true });
outputName();
fs.renameSync('./revanced/revanced.apk', `./revanced/${global.outputName}`;
if (!global.jarNames.isRooted && os.platform() === 'android') {
await actualExec(
'cp revanced/revanced.apk /storage/emulated/0/revanced.apk'
`cp revanced/${global.outputName} /storage/emulated/0/${global.outputName}`
);
await actualExec('cp revanced/microg.apk /storage/emulated/0/microg.apk');

ws.send(
JSON.stringify({
event: 'patchLog',
log: 'Copied files over to /storage/emulated/0/!\nPlease install ReVanced, its located in /storage/emulated/0/revanced.apk\nand if you are building YT/YTM ReVanced without root, also install /storage/emulated/0/microg.apk.'
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 (os.platform() === 'android') {
Expand All @@ -48,7 +50,7 @@ async function afterBuild (ws) {
ws.send(
JSON.stringify({
event: 'patchLog',
log: 'ReVanced has been built!\nPlease transfer over revanced/revanced.apk and if you are using YT/YTM, revanced/microg.apk and install them!'
log: `ReVanced has been built!\nPlease transfer over revanced/${global.outputName} and if you are using YT/YTM, revanced/microg.apk and install them!`
})
);
} else if (!global.jarNames.isRooted && global.jarNames.deviceID) {
Expand Down Expand Up @@ -103,14 +105,54 @@ async function reinstallReVanced (ws) {
}

await actualExec(`adb uninstall ${pkgNameToGetUninstalled}`);
await actualExec('adb install revanced/revanced.apk');
await actualExec(`adb install revanced/${global.outputName}`);
ws.send(
JSON.stringify({
event: 'buildFinished'
})
);
}

function outputName () {
const part1 = 'ReVanced';
let part2;
switch (global.jarNames.selectedApp) {
case 'youtube':
part2 = 'YouTube';
break;
case 'music':
part2 = 'YouTube_Music';
break;
case 'frontpage':
part2 = 'Reddit';
break;
case 'android':
part2 = 'Twitter';
break;
case 'warnapp':
part2 = 'WarnWetter';
break;
}
// TODO: If the existing input APK is used from revanced/ without downloading, version and arch aren't set
const part3 = global?.apkInfo?.version;
const part4 = global?.apkInfo?.arch;
const part5 = global.jarNames.cli
.split(require('path').sep)[2]
.replace('revanced-cli-', '')
.replace('-all.jar', '');
const part6 = global.jarNames.patchesJar
.split(require('path').sep)[2]
.replace('revanced-patches-', '')
.replace('.jar', '');
// Filename: ReVanced-<AppName>-<AppVersion>-[Arch]-<CLI_Version>-<PatchesVersion>.apk
global.outputName = '';
for (const part of [part1, part2, part3, part4, part5, part6]) {
if (part) global.outputName += `-${part}`;
}
global.outputName += '.apk';
global.outputName = global.outputName.substring(1);
}

module.exports = async function (message, ws) {
const args = [
'-jar',
Expand All @@ -121,9 +163,9 @@ module.exports = async function (message, ws) {
'./revanced-cache',
'--experimental',
'-a',
`./revanced/${global.jarNames.selectedApp}.apk`,
`./revanced/revanced.apk`,
'-o',
'./revanced/revanced.apk'
`./revanced/${global.outputName}`
];

if (os.platform() === 'android') {
Expand Down
4 changes: 3 additions & 1 deletion wsEvents/SelectAppVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ module.exports = async function (message, ws) {
arch = deviceArch.arch;
}
}
await downloadApp(message.versionChoosen, ws, arch);
global.apkInfo.version = message.versionChoosen;
global.apkInfo.arch = arch;
await downloadApp(ws);
};

0 comments on commit dfe15b3

Please sign in to comment.