Skip to content

Commit 1fa561d

Browse files
committed
hints: parse sound-name and sound-file
1 parent aef8fd7 commit 1fa561d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/configModel/configModel.vala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ namespace SwayNotificationCenter {
7373
public string ? body { get; set; default = null; }
7474
public string ? urgency { get; set; default = null; }
7575
public string ? category { get; set; default = null; }
76+
public string ? sound_name { get; set; default = null; }
77+
public string ? sound_file { get; set; default = null; }
7678

7779
private const RegexCompileFlags REGEX_COMPILE_OPTIONS =
7880
RegexCompileFlags.MULTILINE
@@ -128,6 +130,22 @@ namespace SwayNotificationCenter {
128130
REGEX_MATCH_FLAGS);
129131
if (!result) return false;
130132
}
133+
if (sound_file != null) {
134+
if (param.sound_file == null) return false;
135+
bool result = Regex.match_simple (
136+
sound_file, param.sound_file,
137+
REGEX_COMPILE_OPTIONS,
138+
REGEX_MATCH_FLAGS);
139+
if (!result) return false;
140+
}
141+
if (sound_name != null) {
142+
if (param.sound_name == null) return false;
143+
bool result = Regex.match_simple (
144+
sound_name, param.sound_name,
145+
REGEX_COMPILE_OPTIONS,
146+
REGEX_MATCH_FLAGS);
147+
if (!result) return false;
148+
}
131149
return true;
132150
}
133151

@@ -243,6 +261,8 @@ namespace SwayNotificationCenter {
243261
spawn_env += "SWAYNC_BODY=%s".printf (param.body);
244262
spawn_env += "SWAYNC_URGENCY=%s".printf (param.urgency.to_string ());
245263
spawn_env += "SWAYNC_CATEGORY=%s".printf (param.category);
264+
spawn_env += "SWAYNC_SOUND_NAME=%s".printf (param.sound_name);
265+
spawn_env += "SWAYNC_SOUND_FILE=%s".printf (param.sound_file);
246266
spawn_env += "SWAYNC_ID=%s".printf (param.applied_id.to_string ());
247267
spawn_env += "SWAYNC_REPLACES_ID=%s".printf (param.replaces_id.to_string ());
248268
spawn_env += "SWAYNC_TIME=%s".printf (param.time.to_string ());

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)