Skip to content

Commit 5d443ed

Browse files
earboxerErikReider
andauthored
hints: parse sound-name and sound-file (#477)
* hints: parse sound-name and sound-file * Added docs --------- Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com>
1 parent 3cf08d6 commit 5d443ed

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

man/swaync.5.scd

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,14 @@ config file to be able to detect config errors
751751
type: string ++
752752
optional: true ++
753753
description: Which category the notification belongs to. Uses Regex.++
754+
*sound-file*++
755+
type: string ++
756+
optional: true ++
757+
description: Which sound file the notification requested. Uses Regex.++
758+
*sound-name*++
759+
type: string ++
760+
optional: true ++
761+
description: Which sound name the notification requested. Uses Regex.++
754762
*run-on*++
755763
type: string ++
756764
optional: true ++
@@ -781,15 +789,17 @@ config file to be able to detect config errors
781789

782790
You can also use these environment variables in your script:
783791
```
784-
SWAYNC_BODY="Notification body content"
785-
SWAYNC_DESKTOP_ENTRY="Desktop entry"
786-
SWAYNC_URGENCY="Notification urgency"
787-
SWAYNC_TIME="Notification time"
788-
SWAYNC_APP_NAME="Notification app name"
789-
SWAYNC_CATEGORY="SwayNC notification category"
790-
SWAYNC_REPLACES_ID="ID of notification to replace"
791-
SWAYNC_ID="SwayNC notification ID"
792-
SWAYNC_SUMMARY="Notification summary"
793-
SWAYNC_HINT_[NAME]="Value of the hint [NAME]"
792+
$SWAYNC_BODY="Notification body content"
793+
$SWAYNC_DESKTOP_ENTRY="Desktop entry"
794+
$SWAYNC_URGENCY="Notification urgency"
795+
$SWAYNC_TIME="Notification time"
796+
$SWAYNC_APP_NAME="Notification app name"
797+
$SWAYNC_CATEGORY="SwayNC notification category"
798+
$SWAYNC_REPLACES_ID="ID of notification to replace"
799+
$SWAYNC_ID="SwayNC notification ID"
800+
$SWAYNC_SUMMARY="Notification summary"
801+
$SWAYNC_HINT_[NAME]="Value of the hint [NAME]"
802+
$SWAYNC_SOUND_NAME="The name of the requested sound"
803+
$SWAYNC_SOUND_FILE="The file path of the requested sound"
794804
```
795805
#END scripting

src/configModel/configModel.vala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ namespace SwayNotificationCenter {
8787
public string ? body { get; set; default = null; }
8888
public string ? urgency { get; set; default = null; }
8989
public string ? category { get; set; default = null; }
90+
public string ? sound_name { get; set; default = null; }
91+
public string ? sound_file { get; set; default = null; }
9092

9193
private const RegexCompileFlags REGEX_COMPILE_OPTIONS =
9294
RegexCompileFlags.MULTILINE;
@@ -141,6 +143,22 @@ namespace SwayNotificationCenter {
141143
REGEX_MATCH_FLAGS);
142144
if (!result) return false;
143145
}
146+
if (sound_file != null) {
147+
if (param.sound_file == null) return false;
148+
bool result = Regex.match_simple (
149+
sound_file, param.sound_file,
150+
REGEX_COMPILE_OPTIONS,
151+
REGEX_MATCH_FLAGS);
152+
if (!result) return false;
153+
}
154+
if (sound_name != null) {
155+
if (param.sound_name == null) return false;
156+
bool result = Regex.match_simple (
157+
sound_name, param.sound_name,
158+
REGEX_COMPILE_OPTIONS,
159+
REGEX_MATCH_FLAGS);
160+
if (!result) return false;
161+
}
144162
return true;
145163
}
146164

@@ -256,6 +274,8 @@ namespace SwayNotificationCenter {
256274
spawn_env += "SWAYNC_BODY=%s".printf (param.body);
257275
spawn_env += "SWAYNC_URGENCY=%s".printf (param.urgency.to_string ());
258276
spawn_env += "SWAYNC_CATEGORY=%s".printf (param.category);
277+
spawn_env += "SWAYNC_SOUND_NAME=%s".printf (param.sound_name);
278+
spawn_env += "SWAYNC_SOUND_FILE=%s".printf (param.sound_file);
259279
spawn_env += "SWAYNC_ID=%s".printf (param.applied_id.to_string ());
260280
spawn_env += "SWAYNC_REPLACES_ID=%s".printf (param.replaces_id.to_string ());
261281
spawn_env += "SWAYNC_TIME=%s".printf (param.time.to_string ());

src/configSchema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@
239239
"type": "string",
240240
"description": "Which category the notification belongs to. Uses Regex."
241241
},
242+
"sound-file": {
243+
"type": "string",
244+
"description": "Which sound file the notification requested. Uses Regex."
245+
},
246+
"sound-name": {
247+
"type": "string",
248+
"description": "Which sound name the notification requested. Uses Regex."
249+
},
242250
"run-on": {
243251
"type": "string",
244252
"description": "Whether to run the script on an action being activated, or when the notification is received.",

src/notiModel/notiModel.vala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ namespace SwayNotificationCenter {
8282
public string image_path { get; set; }
8383
public string desktop_entry { get; set; }
8484
public string category { get; set; }
85+
public string sound_name { get; set; }
86+
public string sound_file { get; set; }
8587
public bool resident { get; set; }
8688
public bool transient { get; set; }
8789
public UrgencyLevels urgency { get; set; }
@@ -250,6 +252,16 @@ namespace SwayNotificationCenter {
250252
category = hint_value.get_string ();
251253
}
252254
break;
255+
case "sound-name":
256+
if (hint_value.is_of_type (VariantType.STRING)) {
257+
sound_name = hint_value.get_string ();
258+
}
259+
break;
260+
case "sound-file":
261+
if (hint_value.is_of_type (VariantType.STRING)) {
262+
sound_file = hint_value.get_string ();
263+
}
264+
break;
253265
case "resident":
254266
if (hint_value.is_of_type (VariantType.BOOLEAN)) {
255267
resident = hint_value.get_boolean ();
@@ -336,6 +348,8 @@ namespace SwayNotificationCenter {
336348
params.set ("image_path", image_path);
337349
params.set ("desktop_entry", desktop_entry);
338350
params.set ("category", category);
351+
params.set ("sound_name", sound_name);
352+
params.set ("sound_file", sound_file);
339353
params.set ("resident", resident.to_string ());
340354
params.set ("urgency", urgency.to_string ());
341355
string[] _actions = {};

0 commit comments

Comments
 (0)