This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deadd_control.bash
executable file
·178 lines (152 loc) · 4.33 KB
/
deadd_control.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/bash
# This script used to send signals to Deadd notification center.
#
# This script is using `notif-send.py` under the hood, make sure it is
# installed.
start_cmd="deadd-notification-center"
process_name="deadd-notificat"
about="Deadd control script - send signals to Deadd notification center"
# check dependencies
if ! command -v notify-send.py &>/dev/null; then
echo "Please install notify-send.py"
exit 1
fi
# shellcheck disable=SC2317
start() {
# check if service already active
status && return 1
# start the service
exec $start_cmd &>/dev/null &
# disown the process
disown
}
# shellcheck disable=SC2317
status() {
pgrep "$process_name" &>/dev/null
}
# shellcheck disable=SC2317
stop() {
pkill "$process_name"
}
# shellcheck disable=SC2317
toggle() {
pkill -USR1 "$process_name"
}
# shellcheck disable=SC2317
reload_css() {
notify-send.py Reloaded --hint boolean:deadd-notification-center:true string:type:reloadStyle
}
# shellcheck disable=SC2317
restart() {
stop
start
}
# shellcheck disable=SC2317
pause() {
notify-send.py a --hint boolean:deadd-notification-center:true string:type:pausePopups
}
# shellcheck disable=SC2317
resume() {
notify-send.py a --hint boolean:deadd-notification-center:true string:type:unpausePopups
}
# shellcheck disable=SC2317
cnotifications() {
notify-send.py a --hint boolean:deadd-notification-center:true string:type:clearInCenter
}
# shellcheck disable=SC2317
cpopups() {
notify-send.py a --hint boolean:deadd-notification-center:true string:type:clearPopups
}
# shellcheck disable=SC2317
high() {
if [ -z "$1" ]; then
echo "Please provide the id of the action button, e.g. 1"
exit 1
fi
notify-send.py a --hint boolean:deadd-notification-center:true int:id:"$1" \
boolean:state:true type:string:buttons
}
# shellcheck disable=SC2317
low() {
if [ -z "$1" ]; then
echo "Please provide the id of the action button, e.g. 1"
exit 1
fi
notify-send.py a --hint boolean:deadd-notification-center:true int:id:"$1" \
boolean:state:false type:string:buttons
}
# shellcheck disable=SC2317
ping() {
notify-send.py "Deadd Control Script" "Pong" \
--hint boolean:action-icons:true \
string:image-path:face-cool \
int:has-percentage:33 \
--action yes:face-smile no:face-sad
}
# shellcheck disable=SC2317
ping_normal() {
notify-send.py "Deadd Control Script" "Normal Pong"
}
# shellcheck disable=SC2317
ping_silent() {
notify-send.py "Deadd Control Script" "Silent Pong" -t 1
}
# shellcheck disable=SC2317
ping_critical() {
notify-send.py "Deadd Control Script" "Critical Pong" -u critical
}
# shellcheck disable=SC2317
ping_low() {
notify-send.py "Deadd Control Script" "Low Pong" -u low
}
# shellcheck disable=SC2317
ping_slider() {
notify-send.py "This notification has a slider" "33%" \
--hint int:has-percentage:33 \
--action changeValue:abc
}
# main script
# shellcheck disable=SC2317
help() {
echo -e "$about\n\n"
echo "Commands:"
for cmd in "${!commands[@]}"; do
echo -e "\t$cmd:\n\t\t${commands[$cmd]}\n"
done
}
usage() {
local IFS="|"
echo "Usage: deadd_control.sh <${!commands[*]}>"
exit 1
}
# define the commands help messages
declare -A commands=(
["start"]="Starts the service if not already started!"
["stop"]="Stops the service if already started!"
["status"]="Checks if the service is already running"
["toggle"]="Toggles show/hide state of the notification center"
["pause"]="Pauses the popup notifications (do not disturb mode)"
["resume"]="Resumes the popup notifications"
["cnotifications"]="Clears all the notifications"
["cpopups"]="Clears all the popped-up notifications"
["reload_css"]="Reloads css styles"
["restart"]="Restarts the service"
["high"]="Sets the state of action button by its id to high"
["low"]="Sets the state of action button by its id to low"
["ping"]="Send a ping notification for testing"
["ping_normal"]="Send a normal notification for testing"
["ping_silent"]="Send a silent notification for testing"
["ping_critical"]="Send a critical ping notification for testing"
["ping_low"]="Send a low ping notification for testing"
["ping_slider"]="Send a ping notification with a slider for testing"
["help"]="Shows this message"
)
# loop through the commands and execute the matched one
for cmd in "${!commands[@]}"; do
[ "$1" != "$cmd" ] && continue
shift
eval "$cmd $*"
exit $?
done
# if no any commands matched then show the usage
usage