Skip to content

Commit 93c8273

Browse files
committed
webui/patch: fully async patch loading process
1 parent 3e0492b commit 93c8273

1 file changed

Lines changed: 34 additions & 15 deletions

File tree

webui/page/patch.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,25 @@ async function parseBootimg() {
9393
return;
9494
}
9595

96-
const result = await exec(`kptools -l -i kernel`, {
96+
let stdout = '', stderr = '';
97+
const result = spawn('kptools', ['-l', '-i', 'kernel'], {
9798
cwd: `${modDir}/tmp`,
9899
env: { PATH: `${modDir}/bin:${modDir}/tmp:$PATH` }
99100
});
100101

101-
if (result.errno) {
102-
toast(getString('msg_failed_parse_kernel', result.stderr));
102+
result.stdout.on('data', (data) => stdout += data + '\n');
103+
result.stderr.on('data', (data) => stderr += data);
104+
105+
const errno = await new Promise((resolve) => {
106+
result.on('exit', (code) => resolve(code));
107+
});
108+
109+
if (errno !== 0) {
110+
toast(getString('msg_failed_parse_kernel', stderr));
103111
return;
104112
}
105113

106-
const ini = parseIni(result.stdout);
114+
const ini = parseIni(stdout);
107115

108116
if (ini.kernel) {
109117
kimgInfo.banner = ini.kernel.banner;
@@ -152,26 +160,37 @@ async function extractAndParseBootimg() {
152160
}
153161

154162
// Prepare work directory
155-
await exec(`mkdir -p ${modDir}/tmp && rm -rf ${modDir}/tmp/* && cp ${modDir}/bin/kpimg ${modDir}/tmp/`);
163+
const prepare = spawn(`mkdir -p ${modDir}/tmp && rm -rf ${modDir}/tmp/* && cp ${modDir}/bin/kpimg ${modDir}/tmp/`);
164+
await new Promise((resolve) => {
165+
prepare.on('exit', () => resolve());
166+
});
156167

157168
// get slot and device
158-
const result = await exec(`busybox sh ${modDir}/boot_extract.sh`, {
169+
const result = spawn('busybox', ['sh', `${modDir}/boot_extract.sh`], {
159170
env: { PATH: `${modDir}/bin:/data/adb/ksu/bin:/data/adb/magisk:$PATH`, ASH_STANDALONE: '1' }
160171
});
161172

162-
if (result.errno && !import.meta.env.DEV) {
163-
toast(getString('msg_boot_extract_failed'), result.stderr);
173+
result.stdout.on('data', (data) => {
174+
if (data.match(/SLOT=(.*)/)) {
175+
bootSlot = data.match(/SLOT=(.*)/)[1].trim();
176+
} else if (data.match(/BOOTIMAGE=(.*)/)) {
177+
bootDev = data.match(/BOOTIMAGE=(.*)/)[1].trim();
178+
}
179+
});
180+
181+
let stderr = '';
182+
result.stderr.on('data', (data) => stderr += data);
183+
184+
const errno = await new Promise((resolve) => {
185+
result.on('exit', (code) => resolve(code));
186+
});
187+
188+
if (errno !== 0 && !import.meta.env.DEV) {
189+
toast(getString('msg_boot_extract_failed'), stderr);
164190
document.getElementById('bootimg-device').textContent = getString('msg_failed_locate_boot');
165191
return;
166192
}
167193

168-
const output = result.stdout;
169-
const matchSlot = output.match(/SLOT=(.*)/);
170-
const matchBoot = output.match(/BOOTIMAGE=(.*)/);
171-
172-
bootSlot = matchSlot ? matchSlot[1].trim() : '';
173-
bootDev = matchBoot ? matchBoot[1].trim() : '';
174-
175194
// Bootimg info card
176195
document.getElementById('bootimg-slot').textContent = bootSlot ? getString('info_slot', bootSlot) : '';
177196
document.getElementById('bootimg-device').textContent = bootDev ? getString('info_device', bootDev) : getString('info_device_unknown');

0 commit comments

Comments
 (0)