@@ -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,35 @@ 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- }
73- } ) ;
59+ const rehookSwitch = rehook . querySelector ( 'md-switch' ) ;
60+ const isEnabled = await updateRehookStatus ( ) ;
61+ if ( isEnabled !== null ) {
62+ rehookSwitch . addEventListener ( 'change' , ( ) => {
63+ setRehookMode ( rehookSwitch . selected ) ;
64+ } ) ;
65+ }
7466}
7567
7668async function updateRehookStatus ( ) {
7769 const rehook = document . getElementById ( 'rehook' ) ;
78- const rehookText = rehook . querySelector ( '.menu-text' ) ;
7970 const rehookRipple = rehook . querySelector ( 'md-ripple' ) ;
71+ const rehookSwitch = rehook . querySelector ( 'md-switch' ) ;
8072
81- let modeName = 'target' , modeId = null ;
73+ let isEnabled = null ;
8274
8375 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 ] ;
76+ if ( result . errno === 0 ) {
77+ isEnabled = result . stdout . split ( ':' ) [ 1 ] . trim ( ) === 'enabled' ;
78+ rehookSwitch . selected = isEnabled ;
8879 }
89- rehookText . textContent = getString ( 'label_rehook_mode_' + modeName ) ;
90- rehookText . classList . toggle ( 'disabled' , ! mode ) ;
91- rehookRipple . disabled = ! mode ;
80+ rehookRipple . disabled = ! isEnabled ;
81+ rehookSwitch . disabled = ! isEnabled ;
9282
93- return modeId !== null ;
83+ return isEnabled ;
9484}
9585
96- function setRehookMode ( mode ) {
86+ function setRehookMode ( isEnable ) {
87+ const mode = isEnable ? 1 : 0 ;
9788 exec ( `
9889 kpatch rehook ${ mode } && echo ${ mode } > ${ persistDir } /rehook && sh "${ modDir } /status.sh"` ,
9990 { env : { PATH : `${ modDir } /bin:$PATH` } }
0 commit comments