Skip to content

Commit 32224d6

Browse files
authored
Merge pull request slgobinath#739 from deltragon/audiblealert-volume
audiblealert: add setting for volume
2 parents a2cfaf5 + 69693c3 commit 32224d6

File tree

4 files changed

+80
-7
lines changed

4 files changed

+80
-7
lines changed

safeeyes/config/locale/safeeyes.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,7 @@ msgstr ""
567567

568568
msgid "seconds"
569569
msgstr ""
570+
571+
#, python-format
572+
msgid "Please install one of the command-line tools: %s"
573+
msgstr ""

safeeyes/plugins/audiblealert/config.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"meta": {
33
"name": "Audible Alert",
44
"description": "Play audible alert before and after breaks",
5-
"version": "0.0.3"
5+
"version": "0.0.4"
66
},
77
"dependencies": {
88
"python_modules": [],
9-
"shell_commands": ["aplay"],
9+
"shell_commands": [],
1010
"operating_systems": [],
1111
"desktop_environments": [],
1212
"resources": ["on_pre_break.wav", "on_stop_break.wav"]
@@ -22,6 +22,14 @@
2222
"label": "Play audible alert after breaks",
2323
"type": "BOOL",
2424
"default": true
25+
},
26+
{
27+
"id": "volume",
28+
"label": "Alert volume",
29+
"type": "INT",
30+
"default": 100,
31+
"max": 100,
32+
"min": 0
2533
}],
2634
"break_override_allowed": true
27-
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Safe Eyes is a utility to remind you to take break frequently
2+
# to protect your eyes from eye strain.
3+
4+
# Copyright (C) 2025 Mel Dafert <m@dafert.at>
5+
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from safeeyes import utility
20+
from safeeyes.translations import translate as _
21+
22+
23+
def validate(plugin_config, plugin_settings):
24+
commands = ["ffplay", "pw-play"]
25+
exists = False
26+
for command in commands:
27+
if utility.command_exist(command):
28+
exists = True
29+
break
30+
31+
if not exists:
32+
return _("Please install one of the command-line tools: %s") % ", ".join(
33+
[f"'{command}'" for command in commands]
34+
)
35+
else:
36+
return None

safeeyes/plugins/audiblealert/plugin.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
context = None
2727
pre_break_alert = False
2828
post_break_alert = False
29+
volume: int = 100
2930

3031

3132
def play_sound(resource_name):
@@ -36,27 +37,51 @@ def play_sound(resource_name):
3637
resource_name {string} -- name of the wav file resource
3738
3839
"""
39-
logging.info("Playing audible alert %s", resource_name)
40+
global volume
41+
42+
logging.info("Playing audible alert %s at volume %s%%", resource_name, volume)
4043
try:
4144
# Open the sound file
4245
path = utility.get_resource_path(resource_name)
4346
if path is None:
4447
return
45-
utility.execute_command("aplay", ["-q", path])
46-
4748
except BaseException:
48-
logging.error("Failed to play audible alert %s", resource_name)
49+
logging.error("Failed to load resource %s", resource_name)
50+
return
51+
52+
if utility.command_exist("ffplay"): # ffmpeg
53+
utility.execute_command(
54+
"ffplay",
55+
[
56+
path,
57+
"-nodisp",
58+
"-nostats",
59+
"-hide_banner",
60+
"-autoexit",
61+
"-volume",
62+
str(volume),
63+
],
64+
)
65+
elif utility.command_exist("pw-play"): # pipewire
66+
pwvol = volume / 100 # 0 = silent, 1.0 = 100% volume
67+
utility.execute_command("pw-play", ["--volume", str(pwvol), path])
4968

5069

5170
def init(ctx, safeeyes_config, plugin_config):
5271
"""Initialize the plugin."""
5372
global context
5473
global pre_break_alert
5574
global post_break_alert
75+
global volume
5676
logging.debug("Initialize Audible Alert plugin")
5777
context = ctx
5878
pre_break_alert = plugin_config["pre_break_alert"]
5979
post_break_alert = plugin_config["post_break_alert"]
80+
volume = int(plugin_config.get("volume", 100))
81+
if volume > 100:
82+
volume = 100
83+
if volume < 0:
84+
volume = 0
6085

6186

6287
def on_pre_break(break_obj):

0 commit comments

Comments
 (0)