Skip to content

Commit b5c3fc4

Browse files
committed
webui/kpm: define chunck size with system ARG_MAX
1 parent d54fd28 commit b5c3fc4

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

webui/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const modDir = '/data/adb/modules/KPatch-Next';
99
export const persistDir = '/data/adb/kp-next';
1010

1111
export let superkey = localStorage.getItem('kp-next_superkey') || '';
12+
export let MAX_CHUNK_SIZE = 96 * 1024;
1213

1314
async function updateStatus() {
1415
const version = await patchModule.getInstalledVersion();
@@ -64,7 +65,7 @@ function updateBtnState(value) {
6465
}
6566

6667
export function initInfo() {
67-
exec('uname -r && getprop ro.build.version.release && getprop ro.build.fingerprint && getenforce').then((result) => {
68+
return exec('uname -r && getprop ro.build.version.release && getprop ro.build.fingerprint && getenforce').then((result) => {
6869
if (import.meta.env.DEV) { // vite debug
6970
result.stdout = '6.18.2-linux\n16\nLinuxPC\nEnforcing'
7071
}
@@ -84,6 +85,18 @@ async function reboot(reason = "") {
8485
exec(`/system/bin/svc power reboot ${reason} || /system/bin/reboot ${reason}`);
8586
}
8687

88+
function getMaxChunkSize() {
89+
exec('getconf ARG_MAX').then((result) => {
90+
try {
91+
const max_arg = parseInt(result.stdout.trim());
92+
if (!isNaN(max_arg)) {
93+
// max_arg * 0.75 (base64 size increase) - command length
94+
MAX_CHUNK_SIZE = Math.floor(max_arg * 0.75) - 1024;
95+
}
96+
} catch (e) { }
97+
});
98+
}
99+
87100
document.addEventListener('DOMContentLoaded', async () => {
88101
document.querySelectorAll('[unresolved]').forEach(el => el.removeAttribute('unresolved'));
89102
const splash = document.getElementById('splash');
@@ -169,9 +182,8 @@ document.addEventListener('DOMContentLoaded', async () => {
169182
kpmModule.refreshKpmList();
170183
}
171184

172-
updateStatus();
173185
updateBtnState(superkey);
174-
initInfo();
186+
getMaxChunkSize();
175187
excludeModule.initExcludePage();
176188
kpmModule.initKPMPage();
177189

webui/page/kpm.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { exec, spawn, toast } from 'kernelsu-alt';
2-
import { modDir, persistDir, superkey, initInfo } from '../index.js';
2+
import { modDir, persistDir, superkey, initInfo, MAX_CHUNK_SIZE } from '../index.js';
33

44
let allKpms = [];
55
let searchQuery = '';
@@ -153,7 +153,7 @@ async function renderKpmList() {
153153
}
154154

155155
async function uploadFile(file, targetPath, onProgress, signal) {
156-
const CHUNK_SIZE = 256 * 1024; // 256KB chunks
156+
const CHUNK_SIZE = file.size > MAX_CHUNK_SIZE * 4 ? MAX_CHUNK_SIZE : Math.max(1, Math.ceil(file.size / 4));
157157
const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
158158
const CONCURRENCY = 8;
159159

@@ -314,7 +314,7 @@ async function uploadAndLoadModule() {
314314
toast(`Successfully loaded ${info.name}`);
315315
refreshKpmList();
316316
if (!checkbox.checked) { // Save module to load on boot automatically
317-
exec(`
317+
exec(`
318318
mkdir -p ${persistDir}/kpm
319319
cp -f "${modDir}/tmp/${file.name}" "${persistDir}/kpm/${info.name}.kpm"
320320
`);
@@ -375,8 +375,6 @@ export function initKPMPage() {
375375
document.getElementById('refresh-kpm-list-menu').onclick = () => {
376376
refreshKpmList();
377377
};
378-
379-
refreshKpmList();
380378
}
381379

382380
export { loadModule, refreshKpmList, uploadAndLoadModule, handleFileUpload, uploadFile }

0 commit comments

Comments
 (0)