Skip to content

Commit 7a0b05f

Browse files
committed
webui: redirect to KsuWebUI fork if upload api not available
1 parent 74e1e1f commit 7a0b05f

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

webui/index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '@material/web/all.js';
2-
import { exec } from 'kernelsu-alt';
2+
import { exec, toast } from 'kernelsu-alt';
33
import { setupRoute, navigateToHome } from './route.js';
44
import * as patchModule from './page/patch.js';
55
import * as kpmModule from './page/kpm.js';
@@ -96,6 +96,19 @@ function getMaxChunkSize() {
9696
});
9797
}
9898

99+
export function linkRedirect(link) {
100+
toast("Redirecting to " + link);
101+
setTimeout(() => {
102+
exec(`am start -a android.intent.action.VIEW -d ${link}`)
103+
.then(({ errno }) => {
104+
if (errno !== 0) {
105+
toast("Failed to open link with exec");
106+
window.open(link, "_blank");
107+
}
108+
});
109+
}, 100);
110+
}
111+
99112
document.addEventListener('DOMContentLoaded', async () => {
100113
document.querySelectorAll('[unresolved]').forEach(el => el.removeAttribute('unresolved'));
101114
const splash = document.getElementById('splash');
@@ -170,17 +183,6 @@ document.addEventListener('DOMContentLoaded', async () => {
170183
});
171184
document.getElementById('reboot-fab').onclick = () => reboot();
172185

173-
// Kpm
174-
const controlDialog = document.getElementById('control-dialog');
175-
const controlTextField = controlDialog.querySelector('md-outlined-text-field');
176-
controlTextField.addEventListener('input', () => {
177-
controlDialog.querySelector('.confirm').disabled = !controlTextField.value;
178-
});
179-
document.getElementById('load').onclick = () => {
180-
kpmModule.uploadAndLoadModule();
181-
kpmModule.refreshKpmList();
182-
}
183-
184186
updateBtnState(superkey);
185187
getMaxChunkSize();
186188
excludeModule.initExcludePage();

webui/page/kpm.js

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

44
let allKpms = [];
55
let searchQuery = '';
6+
let clickCount = 0;
7+
let lastClickTime = 0;
68

79
async function getKpmInfo(path) {
810
const result = await exec(`kptools -l -M "${path}"`, { env: { PATH: `${modDir}/bin` } });
@@ -255,7 +257,20 @@ async function uploadFile(file, targetPath, onProgress, signal) {
255257
}
256258
}
257259

260+
function checkFileUploadApi() {
261+
// If we reach here 3 times in 2 seconds, upload api is likely available
262+
const currentTime = Date.now();
263+
clickCount = (currentTime - lastClickTime > 2000) ? 1 : clickCount + 1;
264+
lastClickTime = currentTime;
265+
266+
if (clickCount === 3) {
267+
clickCount = 0;
268+
linkRedirect('https://github.com/KOWX712/KsuWebUIStandalone/releases/latest');
269+
}
270+
}
271+
258272
async function handleFileUpload(accept, containerId, onSelected) {
273+
checkFileUploadApi();
259274
const input = document.createElement('input');
260275
input.type = 'file';
261276
input.accept = accept;
@@ -404,6 +419,14 @@ export function initKPMPage() {
404419
kpmItemMap.clear();
405420
refreshKpmList();
406421
};
422+
423+
const controlDialog = document.getElementById('control-dialog');
424+
const controlTextField = controlDialog.querySelector('md-outlined-text-field');
425+
controlTextField.addEventListener('input', () => {
426+
controlDialog.querySelector('.confirm').disabled = !controlTextField.value;
427+
});
428+
429+
document.getElementById('load').onclick = () => uploadAndLoadModule();
407430
}
408431

409-
export { loadModule, refreshKpmList, uploadAndLoadModule, handleFileUpload, uploadFile }
432+
export { loadModule, refreshKpmList, handleFileUpload, uploadFile }

0 commit comments

Comments
 (0)