Skip to content

Commit 79c7ff3

Browse files
committed
hints: parse sound-name and sound-file
1 parent f55b433 commit 79c7ff3

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
@@ -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/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)