Skip to content

Commit 93729c8

Browse files
authored
Add option to enable/disable sound notification; closes #4 (#15)
1 parent 6e716e3 commit 93729c8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

usr/lib/battery-monitor/Notification.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def load_config(self):
110110
self.critical_battery = int(self.config['settings']['critical_battery'])
111111
except ValueError:
112112
self.critical_battery = 10
113+
try:
114+
self.use_sound = int(self.config['settings']['use_sound'])
115+
except ValueError:
116+
self.use_sound = 1
113117
try:
114118
self.notification_stability = int(self.config['settings']['notification_stability'])
115119
except ValueError:
@@ -123,6 +127,7 @@ def load_config(self):
123127
self.third_custom_warning = -3
124128
self.low_battery = 30
125129
self.critical_battery = 10
130+
self.use_sound = 1
126131
self.notification_stability = 5
127132

128133
def show_notification(self, notiftype: str, battery_percentage: int,
@@ -138,7 +143,8 @@ def show_notification(self, notiftype: str, battery_percentage: int,
138143
if ("charging" or "discharging") in notiftype:
139144
notification = self.notifier.new(head, body, icon)
140145
notification.show()
141-
os.system("paplay /usr/share/sounds/Yaru/stereo/complete.oga")
146+
if self.use_sound:
147+
os.system("paplay /usr/share/sounds/Yaru/stereo/complete.oga")
142148
else:
143149
self.monitor.is_updated()
144150
info = self.monitor.get_processed_battery_info()
@@ -147,7 +153,8 @@ def show_notification(self, notiftype: str, battery_percentage: int,
147153
continue
148154
notification = self.notifier.new(head, body, icon)
149155
notification.show()
150-
os.system("paplay /usr/share/sounds/Yaru/stereo/complete.oga")
156+
if self.use_sound:
157+
os.system("paplay /usr/share/sounds/Yaru/stereo/complete.oga")
151158
time.sleep(self.notification_stability)
152159

153160
except GLib.GError as e:

usr/lib/battery-monitor/SettingsWindow.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def __init__(self, application):
7777
self.critical_battery_entry = self.builder.get_object("critical_battery")
7878

7979
## Sound configuration page
80-
self.mute_sound_entry = self.builder.get_object("mute_sound")
80+
self.label_sound_switch = self.builder.get_object("label_sound_switch")
81+
self.sound_switch = self.builder.get_object("sound_switch")
8182
self.sound_file_entry = self.builder.get_object("sound_file")
8283

8384
## Notification configuration page
@@ -148,6 +149,7 @@ def __load_config(self):
148149
self.third_custom_warning = self.config['settings']['third_custom_warning']
149150
self.low_battery = self.config['settings']['low_battery']
150151
self.critical_battery = self.config['settings']['critical_battery']
152+
self.use_sound = int(self.config['settings']['use_sound'])
151153
self.notification_stability = self.config['settings']['notification_stability']
152154
except:
153155
print('Config file is missing or not readable. Using default configurations.')
@@ -158,6 +160,7 @@ def __load_config(self):
158160
self.third_custom_warning = '40'
159161
self.low_battery = '30'
160162
self.critical_battery = '15'
163+
self.use_sound = 1
161164
self.notification_stability = '5'
162165

163166
self.success_shown_entry.set_text(self.success_shown)
@@ -167,6 +170,7 @@ def __load_config(self):
167170
self.third_custom_warning_entry.set_text(self.third_custom_warning)
168171
self.low_battery_entry.set_text(self.low_battery)
169172
self.critical_battery_entry.set_text(self.critical_battery)
173+
self.sound_switch.set_active(self.use_sound)
170174
self.notify_duration_entry.set_text(self.notification_stability)
171175

172176
def __save_config(self, widget):
@@ -180,6 +184,11 @@ def __save_config(self, widget):
180184
else:
181185
os.makedirs(self.config_dir)
182186

187+
if self.sound_switch.get_active():
188+
use_sound = 1
189+
else:
190+
use_sound = 0
191+
183192
self.config['settings'] = {
184193
'success_shown': self.success_shown_entry.get_text(),
185194
'upper_threshold_warning': self.upper_threshold_warning_entry.get_text(),
@@ -188,6 +197,7 @@ def __save_config(self, widget):
188197
'third_custom_warning': self.third_custom_warning_entry.get_text(),
189198
'low_battery': self.low_battery_entry.get_text(),
190199
'critical_battery': self.critical_battery_entry.get_text(),
200+
'use_sound': use_sound,
191201
'notification_stability': self.notify_duration_entry.get_text()
192202
}
193203

0 commit comments

Comments
 (0)