@@ -9,12 +9,6 @@ import * as excludeModule from './page/exclude.js';
99export const modDir = '/data/adb/modules/KPatch-Next' ;
1010export const persistDir = '/data/adb/kp-next' ;
1111
12- const rehookMode = [
13- "disable" , // 0
14- "target" , // 1
15- "minimal" // 2
16- ]
17-
1812export let MAX_CHUNK_SIZE = 96 * 1024 ;
1913
2014async function updateStatus ( ) {
@@ -62,38 +56,41 @@ async function reboot(reason = "") {
6256
6357async function initRehook ( ) {
6458 const rehook = document . getElementById ( 'rehook' ) ;
65- const rehookMenu = rehook . querySelector ( 'md-menu' ) ;
66- const mode = await updateRehookStatus ( ) ;
67- if ( mode ) rehook . onclick = ( ) => rehookMenu . open = ! rehookMenu . open ;
68- rehookMenu . querySelectorAll ( 'md-menu-item' ) . forEach ( ( item , index ) => {
69- item . onclick = ( ) => {
70- setRehookMode ( index ) ;
71- rehook . click ( ) ;
72- }
59+ const rehookRipple = rehook . querySelector ( 'md-ripple' ) ;
60+ const rehookSwitch = rehook . querySelector ( 'md-switch' ) ;
61+ const isEnabled = await updateRehookStatus ( ) ;
62+ if ( isEnabled === null ) {
63+ rehookRipple . disabled = true ;
64+ rehookSwitch . disabled = true ;
65+ return ;
66+ }
67+ rehookSwitch . addEventListener ( 'change' , ( ) => {
68+ setRehookMode ( rehookSwitch . selected ) ;
7369 } ) ;
7470}
7571
7672async function updateRehookStatus ( ) {
7773 const rehook = document . getElementById ( 'rehook' ) ;
78- const rehookText = rehook . querySelector ( '.menu-text' ) ;
79- const rehookRipple = rehook . querySelector ( 'md-ripple' ) ;
74+ const rehookSwitch = rehook . querySelector ( 'md-switch' ) ;
8075
81- let modeName = 'target' , modeId = null ;
76+ let isEnabled = null ;
8277
8378 const result = await exec ( `kpatch rehook_status` , { env : { PATH : `${ modDir } /bin` } } ) ;
84- const mode = result . stdout . split ( '\n' ) . find ( line => line . includes ( 'mode: ' ) ) ;
85- if ( mode ) {
86- modeId = parseInt ( mode . split ( ':' ) [ 1 ] . trim ( ) ) ;
87- modeName = rehookMode [ modeId ] ;
79+ if ( result . errno === 0 ) {
80+ const mode = result . stdout . split ( ':' ) [ 1 ] . trim ( ) ;
81+ if ( mode === 'enabled' ) {
82+ isEnabled = true ;
83+ } else if ( mode === 'disabled' ) {
84+ isEnabled = false ;
85+ }
86+ rehookSwitch . selected = isEnabled ;
8887 }
89- rehookText . textContent = getString ( 'label_rehook_mode_' + modeName ) ;
90- rehookText . classList . toggle ( 'disabled' , ! mode ) ;
91- rehookRipple . disabled = ! mode ;
9288
93- return modeId !== null ;
89+ return isEnabled ;
9490}
9591
96- function setRehookMode ( mode ) {
92+ function setRehookMode ( isEnable ) {
93+ const mode = isEnable ? "enable" : "disable" ;
9794 exec ( `
9895 kpatch rehook ${ mode } && echo ${ mode } > ${ persistDir } /rehook && sh "${ modDir } /status.sh"` ,
9996 { env : { PATH : `${ modDir } /bin:$PATH` } }
0 commit comments