Skip to content

Commit

Permalink
Add Patch rememberer
Browse files Browse the repository at this point in the history
  • Loading branch information
reisxd committed Aug 5, 2022
1 parent d086b23 commit 6793a03
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ revanced-builder-nodejs-macos
revanced-builder-nodejs-linux
revanced-builder-nodejs-win.exe
excludedPatchesList.json
includedPatchesList.json
dist/
revanced-cache/
index-old.js
11 changes: 10 additions & 1 deletion public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ ws.onmessage = (msg) => {
</li>`;
i++;
}

for (const patch of document.getElementsByClassName('select')) {
if (
message.rememberedPatchList.includes(
patch.attributes.patchName.nodeValue
)
) {
patch.checked = true;
}
}
break;
}

Expand Down Expand Up @@ -256,7 +266,6 @@ ws.onmessage = (msg) => {

case 'error': {
const failureURL = `/failure?error=${message.error}`;
console.log(failureURL);
location.href = failureURL;
break;
}
Expand Down
6 changes: 1 addition & 5 deletions public/patch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
<title>Patching</title>
<link href="../styles/fontawesome.css" rel="stylesheet" type="text/css" />
<link href="../styles/core.css" rel="stylesheet" type="text/css" />
<link
href="../styles/dependencies.css"
rel="stylesheet"
type="text/css"
/>
<link href="../styles/dependencies.css" rel="stylesheet" type="text/css" />
<script src="../index.js"></script>
</head>

Expand Down
6 changes: 1 addition & 5 deletions public/versions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
<link href="../styles/fontawesome.css" rel="stylesheet" type="text/css" />
<link href="../styles/core.css" rel="stylesheet" type="text/css" />
<link href="../styles/apps.css" rel="stylesheet" type="text/css" />
<link
href="../styles/dependencies.css"
rel="stylesheet"
type="text/css"
/>
<link href="../styles/dependencies.css" rel="stylesheet" type="text/css" />
<script src="../index.js"></script>
</head>

Expand Down
68 changes: 68 additions & 0 deletions utils/PatchListRememberer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const fs = require('fs');

function createRemembererFile() {
fs.writeFileSync(
'./includedPatchesList.json',
JSON.stringify({
packages: [
{
name: 'youtube',
patches: []
},
{
name: 'music',
patches: []
},
{
name: 'android',
patches: []
},
{
name: 'frontpage',
patches: []
}
]
})
);
}

function getPatchesList(pkgName) {
let file = fs.readFileSync('./includedPatchesList.json');
file = file.toString();
file = JSON.parse(file);

for (const package of file.packages) {
if (package.name !== pkgName) continue;

return package.patches;
}
}

function writePatches(pkgName, patches) {
let file = fs.readFileSync('./includedPatchesList.json');
file = file.toString();
file = JSON.parse(file);

for (const package of file.packages) {
if (package.name !== pkgName) continue;
const packageIndex = file.packages.indexOf(package);

file.packages[packageIndex].patches = patches;

return fs.writeFileSync('./includedPatchesList.json', JSON.stringify(file));
}
}

function getPatchList(pkgName) {
if (!fs.existsSync('./includedPatchesList.json')) {
createRemembererFile();
return [];
} else {
return getPatchesList(pkgName);
}
}

module.exports = {
getPatchList,
writePatches
};
6 changes: 5 additions & 1 deletion wsEvents/GetPatches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { promisify } = require('util');
const { exec } = require('child_process');
const { getPatchList } = require('../utils/PatchListRememberer.js');
const os = require('os');
const actualExec = promisify(exec);

Expand Down Expand Up @@ -61,10 +62,13 @@ module.exports = async function (message, ws) {
}
}

const rememberedPatchList = getPatchList(global.jarNames.selectedApp);

return ws.send(
JSON.stringify({
event: 'patchList',
patchList
patchList,
rememberedPatchList
})
);
};
3 changes: 3 additions & 0 deletions wsEvents/SelectPatches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { writePatches } = require('../utils/PatchListRememberer.js');

module.exports = async function (message, ws) {
global.jarNames.patches = '';
writePatches(global.jarNames.selectedApp, message.selectedPatches);
const includedPatchesArray = [];
for (const patch of message.selectedPatches) {
const patchName = patch.replace(/\|.+(.*)$/, '').replace(/\s/g, '');
Expand Down

0 comments on commit 6793a03

Please sign in to comment.