Skip to content

Commit 19eda1d

Browse files
committed
1. Add init script.
2. Add custom.conf.
1 parent a723ddf commit 19eda1d

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

custom.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"title": "背光控制",
3+
"content": "控制背光",
4+
"button2": {
5+
"cmd": "lua /system/share/lua/5.1/tp_entry.lua sys_api.release_backlight",
6+
"txt": "锁定背光",
7+
"code": {"0": "执行成功", "-1": "执行失败"}
8+
},
9+
"button1": {
10+
"cmd": "lua /system/share/lua/5.1/tp_entry.lua sys_api.lock_backlight",
11+
"txt": "解锁背光",
12+
"code": {"0": "执行成功", "-1": "执行失败"}
13+
}
14+
}

init

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
3+
CURWDIR="$(cd $(dirname $0) && pwd)"
4+
TITLE="背光控制"
5+
PROGRAM_NAME="backlight-control"
6+
CUSTOM_BIN="/system/apps/tp/bin/custom"
7+
CUSTOM_CONFIG_FILE="$CURWDIR/custom.conf"
8+
9+
APPS_CONFIG_DIR="/data/conf"
10+
LAUNCHER_CONFIG_DIR="$APPS_CONFIG_DIR/launcher/conf.d"
11+
LAUNCHER_CONFIG_FILE="$LAUNCHER_CONFIG_DIR/$PROGRAM_NAME.conf"
12+
13+
ICON="normal.png"
14+
PRESSED_ICON="pressed.png"
15+
16+
PID_FILE="$CURWDIR/$PROGRAM_NAME.pid"
17+
PKILL_BIN="/usr/bin/pkill"
18+
INSTALL_BIN="/usr/bin/install"
19+
REMOVE="/usr/bin/rm -f"
20+
21+
usage() {
22+
echo "ERROR: action missing"
23+
echo "syntax: $0 <start|stop|restart|status|config|install|uninstall>"
24+
echo "example: $0 start"
25+
}
26+
27+
start() {
28+
$CUSTOM_BIN "$CUSTOM_CONFIG_FILE" &
29+
[ "$!""XXX" != "XXX" ] && echo "$!" > $PID_FILE
30+
}
31+
32+
stop() {
33+
if [ -f $PID_FILE ]; then
34+
$PKILL_BIN "$CUSTOM_BIN $CUSTOM_CONFIG_FILE" -F "$PID_FILE"
35+
$REMOVE $PID_FILE
36+
fi
37+
}
38+
39+
config() {
40+
echo "{" > "$PROGRAM_NAME.conf"
41+
echo "\"name\" : \"$TITLE\"," >> "$PROGRAM_NAME.conf"
42+
echo "\"icon\" : \"$CURWDIR/$ICON\"," >> "$PROGRAM_NAME.conf"
43+
echo "\"iconPressed\" : \"$CURWDIR/$PRESSED_ICON\"," >> "$PROGRAM_NAME.conf"
44+
echo "\"exec\" : \"$CURWDIR/init start\"," >> "$PROGRAM_NAME.conf"
45+
echo "\"msgNum\" : 4" >> "$PROGRAM_NAME.conf"
46+
echo "}" >> "$PROGRAM_NAME.conf"
47+
48+
$INSTALL_BIN -d $LAUNCHER_CONFIG_DIR
49+
$INSTALL_BIN "$PROGRAM_NAME.conf" "$LAUNCHER_CONFIG_FILE"
50+
}
51+
52+
uninstall() {
53+
$REMOVE "$LAUNCHER_CONFIG_FILE"
54+
}
55+
56+
# main
57+
if [ $# -lt 1 ]; then
58+
usage
59+
exit 255
60+
fi
61+
62+
case "$1" in
63+
"start" )
64+
start;;
65+
"stop" )
66+
stop;;
67+
"restart" )
68+
start
69+
stop;;
70+
"install" )
71+
config;;
72+
"uninstall" )
73+
uninstall;;
74+
* )
75+
usage ;;
76+
esac

normal.png

794 Bytes
Loading

pressed.png

5.24 KB
Loading

0 commit comments

Comments
 (0)