Skip to content

Commit c75ae9a

Browse files
committed
feat: Add Show universal patches setting
1 parent 49b32eb commit c75ae9a

File tree

6 files changed

+90
-9
lines changed

6 files changed

+90
-9
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ wsServer.on('connection', (ws) => {
191191
await getDevices(ws);
192192
break;
193193
case 'getPatches':
194-
await getPatches(ws);
194+
await getPatches(ws, message);
195195
break;
196196
case 'getSettings':
197197
await getSettings(ws);

public/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function setApp() {
3939
}
4040

4141
function loadPatches() {
42-
sendCommand({ event: 'getPatches' });
42+
sendCommand({ event: 'getPatches', showUniversalPatches: localStorage.getItem('universal-patches') });
4343
}
4444

4545
function updateFiles() {

public/settings.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if (localStorage.getItem('pre-releases')) {
1212
if (localStorage.getItem('rip-libs')) {
1313
document.getElementById('ripLibsBtn').checked = true;
1414
}
15+
if (localStorage.getItem('universal-patches')) {
16+
document.getElementById('universalPatchesBtn').checked = true;
17+
}
1518

1619
accentColors.forEach((color) => {
1720
if (
@@ -60,3 +63,10 @@ document.getElementById('ripLibsBtn').addEventListener('click', function () {
6063
localStorage.setItem('rip-libs', true);
6164
}
6265
});
66+
document.getElementById('universalPatchesBtn').addEventListener('click', function () {
67+
if (localStorage.getItem('universal-patches')) {
68+
localStorage.removeItem('universal-patches');
69+
} else {
70+
localStorage.setItem('universal-patches', true);
71+
}
72+
});

public/settings/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ <h3>
122122
autocomplete="off" /><span class="slider"></span
123123
></label>
124124
</div>
125+
126+
<div class="option">
127+
<h3>
128+
<i class="fa-solid fa-screwdriver-wrench"></i>Show universal patches
129+
</h3>
130+
131+
<p>
132+
Display all universal patches.
133+
</p>
134+
<label class="switch"
135+
><input
136+
class="check"
137+
id="universalPatchesBtn"
138+
type="checkbox"
139+
autocomplete="off" /><span class="slider"></span
140+
></label>
141+
</div>
142+
125143
<div class="option">
126144
<h3>
127145
<i class="fa-solid fa-backward"></i>Reset settings

utils/PatchesParser.js

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { readFileSync } = require('node:fs');
44
* @param {string} packageName
55
* @param {boolean} hasRoot
66
*/
7-
module.exports = async function parsePatch(packageName, hasRoot) {
7+
module.exports = async function parsePatch(packageName, hasRoot, showUniversalPatches) {
88
const patchesList = JSON.parse(
99
readFileSync(global.jarNames.patchesList, 'utf8')
1010
);
@@ -14,6 +14,8 @@ module.exports = async function parsePatch(packageName, hasRoot) {
1414
'GmsCore support'
1515
];
1616
const patches = [];
17+
const generalPatches = [];
18+
const universalPatches = [];
1719

1820
global.versions = [];
1921

@@ -44,18 +46,68 @@ module.exports = async function parsePatch(packageName, hasRoot) {
4446

4547
if (isRooted && !hasRoot) continue;
4648

47-
patches.push({
49+
generalPatches.push({
4850
name: patch.name,
49-
description: patch.description || ' ',
50-
maxVersion: compatibleVersion || ' ',
51+
description: patch.description || '(Not Provided)',
52+
maxVersion: compatibleVersion || 'ALL',
53+
universal: false,
5154
isRooted,
52-
excluded: patch.excluded || (patch.use !== undefined && !patch.use)
55+
excluded: patch.excluded || (patch.use !== undefined && !patch.use),
5356
});
5457
}
5558

5659
if (global.versions.length === 0) {
5760
global.versions = 'NOREC';
5861
}
5962

63+
if (!showUniversalPatches) return generalPatches;
64+
65+
for (const patch of patchesList) {
66+
const isRooted = rootedPatches.includes(patch.name);
67+
68+
// Check if the patch is compatible:
69+
let isCompatible = false;
70+
71+
/** @type {string} */
72+
let compatibleVersion;
73+
74+
if (patch.compatiblePackages !== null) continue;
75+
patch.compatiblePackages = [];
76+
77+
for (const pkg of patch.compatiblePackages)
78+
if (pkg.name === packageName) {
79+
isCompatible = true;
80+
81+
if (pkg.versions !== null) {
82+
compatibleVersion = pkg.versions.at(-1);
83+
84+
global.versions.push(compatibleVersion);
85+
}
86+
}
87+
88+
if (!isCompatible) {
89+
if (patch.compatiblePackages.length !== 0) continue;
90+
}
91+
92+
if (isRooted && !hasRoot) continue;
93+
94+
universalPatches.push({
95+
name: patch.name,
96+
description: patch.description || '(Not Provided)',
97+
maxVersion: 'UNIVERSAL',
98+
universal: true,
99+
isRooted,
100+
excluded: patch.excluded || (patch.use !== undefined && !patch.use),
101+
});
102+
}
103+
104+
for (const patch of generalPatches) {
105+
patches.push(patch);
106+
}
107+
108+
for (const patch of universalPatches) {
109+
patches.push(patch);
110+
}
111+
60112
return patches;
61113
};

wsEvents/getPatches.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const parsePatch = require('../utils/PatchesParser.js');
66
/**
77
* @param {import('ws').WebSocket} ws
88
*/
9-
module.exports = async function getPatches(ws) {
9+
module.exports = async function getPatches(ws, message) {
1010
let hasRoot = true;
1111

1212
if (process.platform === 'android')
@@ -29,7 +29,8 @@ module.exports = async function getPatches(ws) {
2929
event: 'patchList',
3030
patchList: await parsePatch(
3131
global.jarNames.selectedApp.packageName,
32-
hasRoot
32+
hasRoot,
33+
message.showUniversalPatches
3334
),
3435
rememberedPatchList,
3536
uploadedApk: global.jarNames.selectedApp.uploaded

0 commit comments

Comments
 (0)