Skip to content

Commit 0d3e7c2

Browse files
committed
webui/settings: add rehook mode
1 parent e02f0d1 commit 0d3e7c2

5 files changed

Lines changed: 87 additions & 0 deletions

File tree

webui/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@
159159
<div slot="headline" data-i18n="title_clear_superkey">Clear SuperKey</div>
160160
</div>
161161
</div>
162+
<div class="list-item installed-only" id="rehook">
163+
<md-ripple></md-ripple>
164+
<md-icon><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M440-120q-100 0-170-70t-70-170v-240l200 200-56 57-64-64v47q0 66 47 113t113 47q66 0 113-47t47-113v-127q-36-14-58-44.5T520-600q0-38 22-68.5t58-44.5v-167h80v167q36 14 58 44.5t22 68.5q0 38-22 69t-58 44v127q0 100-70 170t-170 70Zm200-440q17 0 28.5-11.5T680-600q0-17-11.5-28.5T640-640q-17 0-28.5 11.5T600-600q0 17 11.5 28.5T640-560Zm0-40Z"/></svg></md-icon>
165+
<div class="list-item-content">
166+
<div slot="headline" data-i18n="title_rehook_mode">Rehook Mode</div>
167+
</div>
168+
<div class="list-item-trailing" id="rehook-menu-container">
169+
<div class="menu-text" id="rehook-text">Disable</div>
170+
<md-menu id="rehook-menu" anchor="rehook" anchor-corner="start-end" menu-corner="start-end">
171+
<md-menu-item data-i18n="label_rehook_mode_disable">Disable</md-menu-item>
172+
<md-menu-item data-i18n="label_rehook_mode_target">Target</md-menu-item>
173+
<md-menu-item data-i18n="label_rehook_mode_minimal">Minimal</md-menu-item>
174+
</md-menu>
175+
</div>
176+
</div>
162177
<div class="list-item" id="language">
163178
<md-ripple></md-ripple>
164179
<md-icon><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m476-80 182-480h84L924-80h-84l-43-122H603L560-80h-84ZM160-200l-56-56 202-202q-35-35-63.5-80T190-640h84q20 39 40 68t48 58q33-33 68.5-92.5T484-720H40v-80h280v-80h80v80h280v80H564q-21 72-63 148t-83 116l96 98-30 82-122-125-202 201Zm468-72h144l-72-204-72 204Z" /></svg></md-icon>

webui/index.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import * as excludeModule from './page/exclude.js';
99
export const modDir = '/data/adb/modules/KPatch-Next';
1010
export const persistDir = '/data/adb/kp-next';
1111

12+
const rehookMode = [
13+
"disable", // 0
14+
"target", // 1
15+
"minimal" // 2
16+
]
17+
1218
export let superkey = localStorage.getItem('kp-next_superkey') || '';
1319
export let MAX_CHUNK_SIZE = 96 * 1024;
1420

@@ -23,6 +29,7 @@ async function updateStatus() {
2329
notInstalled.classList.add('hidden');
2430
working.classList.remove('hidden');
2531
kpmModule.refreshKpmList();
32+
initRehook();
2633
document.querySelector('#superkey md-outlined-text-field').value = superkey;
2734
installedOnly.forEach(el => el.removeAttribute('hidden'));
2835
} else {
@@ -90,6 +97,49 @@ async function reboot(reason = "") {
9097
exec(`/system/bin/svc power reboot ${reason} || /system/bin/reboot ${reason}`);
9198
}
9299

100+
async function initRehook() {
101+
const rehook = document.getElementById('rehook');
102+
const rehookMenu = rehook.querySelector('md-menu');
103+
const mode = await updateRehookStatus();
104+
if (mode) rehook.onclick = () => rehookMenu.open = !rehookMenu.open;
105+
rehookMenu.querySelectorAll('md-menu-item').forEach((item, index) => {
106+
item.onclick = () => {
107+
setRehookMode(index);
108+
rehook.click();
109+
}
110+
});
111+
}
112+
113+
async function updateRehookStatus() {
114+
const rehook = document.getElementById('rehook');
115+
const rehookText = rehook.querySelector('.menu-text');
116+
const rehookRipple = rehook.querySelector('md-ripple');
117+
118+
let modeName = 'target', modeId = null;
119+
120+
const result = await exec(`kpatch ${escapeShell(superkey)} rehook_status`, { env: { PATH: `${modDir}/bin` } });
121+
const mode = result.stdout.split('\n').find(line => line.includes('mode: '));
122+
if (mode) {
123+
modeId = parseInt(mode.split(':')[1].trim());
124+
modeName = rehookMode[modeId];
125+
}
126+
rehookText.textContent = getString('label_rehook_mode_' + modeName);
127+
rehookText.classList.toggle('disabled', !mode);
128+
rehookRipple.disabled = !mode;
129+
130+
return modeId !== null;
131+
}
132+
133+
function setRehookMode(mode) {
134+
exec(`kpatch ${escapeShell(superkey)} rehook ${mode}`, { env: { PATH: `${modDir}/bin` } }).then((result) => {
135+
if (result.errno !== 0) {
136+
toast(getString('msg_error', result.stderr));
137+
return;
138+
}
139+
updateRehookStatus();
140+
})
141+
}
142+
93143
function getMaxChunkSize() {
94144
exec('getconf ARG_MAX').then((result) => {
95145
try {

webui/public/locales/strings/en.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<string name="title_reboot_download">Reboot to Download</string>
2020
<string name="title_reboot_edl">Reboot to EDL</string>
2121
<string name="title_kernel">Kernel</string>
22+
<string name="title_rehook_mode">Rehook Mode</string>
2223
<!-- Buttons -->
2324
<string name="button_install">Click to install</string>
2425
<string name="button_uninstall">Uninstall</string>
@@ -38,6 +39,9 @@
3839
<string name="label_show_system_app">Show system app</string>
3940
<string name="label_system_default">System Default</string>
4041
<string name="label_trigger_event">Trigger Event</string>
42+
<string name="label_rehook_mode_disable">Disable</string>
43+
<string name="label_rehook_mode_target">Target</string>
44+
<string name="label_rehook_mode_minimal">Minimal</string>
4145
<!-- Status -->
4246
<string name="status_not_installed">Not installed</string>
4347
<string name="status_working">Working 😋</string>

webui/public/locales/strings/zh-CN.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<string name="title_reboot_download">重启到 Download</string>
2020
<string name="title_reboot_edl">重启到 EDL</string>
2121
<string name="title_kernel">内核</string>
22+
<string name="title_rehook_mode">重挂钩模式</string>
2223
<!-- Buttons -->
2324
<string name="button_install">点击安装</string>
2425
<string name="button_uninstall">卸载</string>
@@ -38,6 +39,9 @@
3839
<string name="label_show_system_app">显示系统应用</string>
3940
<string name="label_system_default">系统默认</string>
4041
<string name="label_trigger_event">触发事件</string>
42+
<string name="label_rehook_mode_disable">禁用</string>
43+
<string name="label_rehook_mode_target">目标</string>
44+
<string name="label_rehook_mode_minimal">最小化</string>
4145
<!-- Status -->
4246
<string name="status_not_installed">未安装</string>
4347
<string name="status_working">工作中 😋</string>

webui/styles.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ md-outlined-text-field {
421421
color: var(--md-sys-color-outline);
422422
}
423423

424+
.list-item-trailing {
425+
position: relative;
426+
}
427+
424428
.empty-list {
425429
height: 100%;
426430
width: 100%;
@@ -434,6 +438,16 @@ md-outlined-text-field {
434438
display: none;
435439
}
436440

441+
.menu-text {
442+
font-size: 0.9em;
443+
color: var(--md-sys-color-primary);
444+
user-select: none;
445+
}
446+
447+
.menu-text.disabled {
448+
color: var(--md-sys-color-on-surface-variant);
449+
}
450+
437451
md-menu-item {
438452
white-space: nowrap;
439453
}

0 commit comments

Comments
 (0)