Skip to content

Commit b231d8f

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

5 files changed

Lines changed: 85 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" 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: 48 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

@@ -90,6 +96,36 @@ async function reboot(reason = "") {
9096
exec(`/system/bin/svc power reboot ${reason} || /system/bin/reboot ${reason}`);
9197
}
9298

99+
async function updateRehookStatus() {
100+
const rehook = document.getElementById('rehook');
101+
const rehookText = rehook.querySelector('.menu-text');
102+
const rehookRipple = rehook.querySelector('md-ripple');
103+
104+
let modeName = 'target', modeId = null;
105+
106+
const result = await exec(`kpatch ${escapeShell(superkey)} rehook_status`, { env: { PATH: `${modDir}/bin` } });
107+
const mode = result.stdout.split('\n').find(line => line.includes('mode: '));
108+
if (mode) {
109+
modeId = parseInt(mode.split(':')[1].trim());
110+
modeName = rehookMode[modeId];
111+
}
112+
rehookText.textContent = getString('label_rehook_mode_' + modeName);
113+
rehookText.classList.toggle('disabled', !mode);
114+
rehookRipple.disabled = !mode;
115+
116+
return modeId !== null;
117+
}
118+
119+
function setRehookMode(mode) {
120+
exec(`kpatch ${escapeShell(superkey)} rehook ${mode}`, { env: { PATH: `${modDir}/bin` } }).then((result) => {
121+
if (result.errno !== 0) {
122+
toast(getString('msg_error', result.stderr));
123+
return;
124+
}
125+
updateRehookStatus();
126+
})
127+
}
128+
93129
function getMaxChunkSize() {
94130
exec('getconf ARG_MAX').then((result) => {
95131
try {
@@ -201,6 +237,18 @@ document.addEventListener('DOMContentLoaded', async () => {
201237
await loadTranslations();
202238
await Promise.all([updateStatus(), initInfo()]);
203239

240+
// rehook
241+
const rehook = document.getElementById('rehook');
242+
const rehookMenu = rehook.querySelector('md-menu');
243+
const mode = await updateRehookStatus();
244+
if (mode) rehook.onclick = () => rehookMenu.open = !rehookMenu.open;
245+
rehookMenu.querySelectorAll('md-menu-item').forEach((item, index) => {
246+
item.onclick = () => {
247+
setRehookMode(index);
248+
rehook.click();
249+
}
250+
});
251+
204252
excludeModule.initExcludePage();
205253
kpmModule.initKPMPage();
206254

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)