Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions man/swaync.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,14 @@ config file to be able to detect config errors
type: string ++
optional: true ++
description: Which category the notification belongs to. Uses Regex.++
*sound-file*++
type: string ++
optional: true ++
description: Which sound file the notification requested. Uses Regex.++
*sound-name*++
type: string ++
optional: true ++
description: Which sound name the notification requested. Uses Regex.++
*run-on*++
type: string ++
optional: true ++
Expand Down Expand Up @@ -781,15 +789,17 @@ config file to be able to detect config errors

You can also use these environment variables in your script:
```
SWAYNC_BODY="Notification body content"
SWAYNC_DESKTOP_ENTRY="Desktop entry"
SWAYNC_URGENCY="Notification urgency"
SWAYNC_TIME="Notification time"
SWAYNC_APP_NAME="Notification app name"
SWAYNC_CATEGORY="SwayNC notification category"
SWAYNC_REPLACES_ID="ID of notification to replace"
SWAYNC_ID="SwayNC notification ID"
SWAYNC_SUMMARY="Notification summary"
SWAYNC_HINT_[NAME]="Value of the hint [NAME]"
$SWAYNC_BODY="Notification body content"
$SWAYNC_DESKTOP_ENTRY="Desktop entry"
$SWAYNC_URGENCY="Notification urgency"
$SWAYNC_TIME="Notification time"
$SWAYNC_APP_NAME="Notification app name"
$SWAYNC_CATEGORY="SwayNC notification category"
$SWAYNC_REPLACES_ID="ID of notification to replace"
$SWAYNC_ID="SwayNC notification ID"
$SWAYNC_SUMMARY="Notification summary"
$SWAYNC_HINT_[NAME]="Value of the hint [NAME]"
$SWAYNC_SOUND_NAME="The name of the requested sound"
$SWAYNC_SOUND_FILE="The file path of the requested sound"
```
#END scripting
20 changes: 20 additions & 0 deletions src/configModel/configModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ namespace SwayNotificationCenter {
public string ? body { get; set; default = null; }
public string ? urgency { get; set; default = null; }
public string ? category { get; set; default = null; }
public string ? sound_name { get; set; default = null; }
public string ? sound_file { get; set; default = null; }

private const RegexCompileFlags REGEX_COMPILE_OPTIONS =
RegexCompileFlags.MULTILINE;
Expand Down Expand Up @@ -141,6 +143,22 @@ namespace SwayNotificationCenter {
REGEX_MATCH_FLAGS);
if (!result) return false;
}
if (sound_file != null) {
if (param.sound_file == null) return false;
bool result = Regex.match_simple (
sound_file, param.sound_file,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) return false;
}
if (sound_name != null) {
if (param.sound_name == null) return false;
bool result = Regex.match_simple (
sound_name, param.sound_name,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) return false;
}
return true;
}

Expand Down Expand Up @@ -256,6 +274,8 @@ namespace SwayNotificationCenter {
spawn_env += "SWAYNC_BODY=%s".printf (param.body);
spawn_env += "SWAYNC_URGENCY=%s".printf (param.urgency.to_string ());
spawn_env += "SWAYNC_CATEGORY=%s".printf (param.category);
spawn_env += "SWAYNC_SOUND_NAME=%s".printf (param.sound_name);
spawn_env += "SWAYNC_SOUND_FILE=%s".printf (param.sound_file);
spawn_env += "SWAYNC_ID=%s".printf (param.applied_id.to_string ());
spawn_env += "SWAYNC_REPLACES_ID=%s".printf (param.replaces_id.to_string ());
spawn_env += "SWAYNC_TIME=%s".printf (param.time.to_string ());
Expand Down
8 changes: 8 additions & 0 deletions src/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@
"type": "string",
"description": "Which category the notification belongs to. Uses Regex."
},
"sound-file": {
"type": "string",
"description": "Which sound file the notification requested. Uses Regex."
},
"sound-name": {
"type": "string",
"description": "Which sound name the notification requested. Uses Regex."
},
"run-on": {
"type": "string",
"description": "Whether to run the script on an action being activated, or when the notification is received.",
Expand Down
14 changes: 14 additions & 0 deletions src/notiModel/notiModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ namespace SwayNotificationCenter {
public string image_path { get; set; }
public string desktop_entry { get; set; }
public string category { get; set; }
public string sound_name { get; set; }
public string sound_file { get; set; }
public bool resident { get; set; }
public bool transient { get; set; }
public UrgencyLevels urgency { get; set; }
Expand Down Expand Up @@ -250,6 +252,16 @@ namespace SwayNotificationCenter {
category = hint_value.get_string ();
}
break;
case "sound-name":
if (hint_value.is_of_type (VariantType.STRING)) {
sound_name = hint_value.get_string ();
}
break;
case "sound-file":
if (hint_value.is_of_type (VariantType.STRING)) {
sound_file = hint_value.get_string ();
}
break;
case "resident":
if (hint_value.is_of_type (VariantType.BOOLEAN)) {
resident = hint_value.get_boolean ();
Expand Down Expand Up @@ -336,6 +348,8 @@ namespace SwayNotificationCenter {
params.set ("image_path", image_path);
params.set ("desktop_entry", desktop_entry);
params.set ("category", category);
params.set ("sound_name", sound_name);
params.set ("sound_file", sound_file);
params.set ("resident", resident.to_string ());
params.set ("urgency", urgency.to_string ());
string[] _actions = {};
Expand Down