Skip to content

Commit 10e114e

Browse files
committed
webui/kpm: update status on kpm load
1 parent dedec1a commit 10e114e

3 files changed

Lines changed: 37 additions & 13 deletions

File tree

module/service.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ KPNDIR="/data/adb/kp-next"
55
PATH="$MODDIR/bin:$PATH"
66
CONFIG="$KPNDIR/package_config"
77
key="$(cat $KPNDIR/key | base64 -d)"
8-
active="Status: active 😊"
9-
inactive="Status: inactive 😕"
10-
info="info: key incorrect, not set or kernel not patched yet ❌"
11-
string="description=$inactive | $info"
128

13-
sed -i "s/^description=.*/$string/" "$MODDIR/module.prop"
9+
sh "$MODDIR/status.sh" "$key"
1410

1511
if [ -z "$key" ] || [ -z "$(kpatch $key hello)" ]; then
1612
touch "$MODDIR/unresolved"
@@ -37,10 +33,3 @@ tail -n +2 "$CONFIG" | while IFS=, read -r pkg exclude allow uid; do
3733
[ -n "$UID" ] && kpatch "$key" exclude_set "$UID" 1
3834
fi
3935
done
40-
41-
if [ -n "$key" ] && kpatch "$key" hello >/dev/null 2>&1; then
42-
KPM_COUNT="$(kpatch "$key" kpm num 2>/dev/null || echo 0)"
43-
[ -z "$KPM_COUNT" ] && KPM_COUNT=0
44-
string="description=$active | kpmodule: $KPM_COUNT 💉"
45-
sed -i "s/^description=.*/$string/" "$MODDIR/module.prop"
46-
fi

module/status.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
MODDIR=${0%/*}
4+
key="$1"
5+
6+
set_prop() {
7+
local prop="$1"
8+
local value="$2"
9+
local file="$3"
10+
11+
if ! grep -q "^$prop=" "$file"; then
12+
echo "$prop=$value" >> "$file"
13+
return
14+
fi
15+
sed "s/^$prop=.*/$prop=$value/" "$file" > "$file.tmp"
16+
cat "$file.tmp" > "$file"
17+
rm -f "$file.tmp"
18+
}
19+
20+
active="Status: active 😊"
21+
inactive="Status: inactive 😕"
22+
info="info: key incorrect, not set or kernel not patched yet ❌"
23+
string="$inactive | $info"
24+
25+
until [ "$(getprop sys.boot_completed)" = "1" ]; do
26+
sleep 1
27+
done
28+
29+
if [ -n "$key" ] && kpatch "$key" hello >/dev/null 2>&1; then
30+
KPM_COUNT="$(kpatch "$key" kpm num 2>/dev/null || echo 0)"
31+
[ -z "$KPM_COUNT" ] && KPM_COUNT=0
32+
string="$active | kpmodule: $KPM_COUNT 💉"
33+
fi
34+
35+
set_prop "description" "$string" "$MODDIR/module.prop"

webui/page/kpm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function unloadModule(moduleName) {
7878
}
7979

8080
async function loadModule(modulePath) {
81-
const result = await exec(`kpatch ${superkey} kpm load "${modulePath}"`, { env: { PATH: `${modDir}/bin` } });
81+
const result = await exec(`kpatch ${superkey} kpm load "${modulePath}" && sh "${modDir}/status.sh" "${superkey}"`, { env: { PATH: `${modDir}/bin` } });
8282
return result.errno === 0;
8383
}
8484

0 commit comments

Comments
 (0)