Unverified Commit 5d443edb authored by Zach DeCook's avatar Zach DeCook Committed by GitHub

hints: parse sound-name and sound-file (#477)

* hints: parse sound-name and sound-file * Added docs --------- Co-authored-by: 's avatarErik Reider <35975961+ErikReider@users.noreply.github.com>
parent 3cf08d6b
...@@ -751,6 +751,14 @@ config file to be able to detect config errors ...@@ -751,6 +751,14 @@ config file to be able to detect config errors
type: string ++ type: string ++
optional: true ++ optional: true ++
description: Which category the notification belongs to. Uses Regex.++ 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*++ *run-on*++
type: string ++ type: string ++
optional: true ++ optional: true ++
...@@ -781,15 +789,17 @@ config file to be able to detect config errors ...@@ -781,15 +789,17 @@ config file to be able to detect config errors
You can also use these environment variables in your script: You can also use these environment variables in your script:
``` ```
SWAYNC_BODY="Notification body content" $SWAYNC_BODY="Notification body content"
SWAYNC_DESKTOP_ENTRY="Desktop entry" $SWAYNC_DESKTOP_ENTRY="Desktop entry"
SWAYNC_URGENCY="Notification urgency" $SWAYNC_URGENCY="Notification urgency"
SWAYNC_TIME="Notification time" $SWAYNC_TIME="Notification time"
SWAYNC_APP_NAME="Notification app name" $SWAYNC_APP_NAME="Notification app name"
SWAYNC_CATEGORY="SwayNC notification category" $SWAYNC_CATEGORY="SwayNC notification category"
SWAYNC_REPLACES_ID="ID of notification to replace" $SWAYNC_REPLACES_ID="ID of notification to replace"
SWAYNC_ID="SwayNC notification ID" $SWAYNC_ID="SwayNC notification ID"
SWAYNC_SUMMARY="Notification summary" $SWAYNC_SUMMARY="Notification summary"
SWAYNC_HINT_[NAME]="Value of the hint [NAME]" $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 #END scripting
...@@ -87,6 +87,8 @@ namespace SwayNotificationCenter { ...@@ -87,6 +87,8 @@ namespace SwayNotificationCenter {
public string ? body { get; set; default = null; } public string ? body { get; set; default = null; }
public string ? urgency { get; set; default = null; } public string ? urgency { get; set; default = null; }
public string ? category { 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 = private const RegexCompileFlags REGEX_COMPILE_OPTIONS =
RegexCompileFlags.MULTILINE; RegexCompileFlags.MULTILINE;
...@@ -141,6 +143,22 @@ namespace SwayNotificationCenter { ...@@ -141,6 +143,22 @@ namespace SwayNotificationCenter {
REGEX_MATCH_FLAGS); REGEX_MATCH_FLAGS);
if (!result) return false; 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; return true;
} }
...@@ -256,6 +274,8 @@ namespace SwayNotificationCenter { ...@@ -256,6 +274,8 @@ namespace SwayNotificationCenter {
spawn_env += "SWAYNC_BODY=%s".printf (param.body); spawn_env += "SWAYNC_BODY=%s".printf (param.body);
spawn_env += "SWAYNC_URGENCY=%s".printf (param.urgency.to_string ()); spawn_env += "SWAYNC_URGENCY=%s".printf (param.urgency.to_string ());
spawn_env += "SWAYNC_CATEGORY=%s".printf (param.category); 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_ID=%s".printf (param.applied_id.to_string ());
spawn_env += "SWAYNC_REPLACES_ID=%s".printf (param.replaces_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 ()); spawn_env += "SWAYNC_TIME=%s".printf (param.time.to_string ());
......
...@@ -239,6 +239,14 @@ ...@@ -239,6 +239,14 @@
"type": "string", "type": "string",
"description": "Which category the notification belongs to. Uses Regex." "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": { "run-on": {
"type": "string", "type": "string",
"description": "Whether to run the script on an action being activated, or when the notification is received.", "description": "Whether to run the script on an action being activated, or when the notification is received.",
......
...@@ -82,6 +82,8 @@ namespace SwayNotificationCenter { ...@@ -82,6 +82,8 @@ namespace SwayNotificationCenter {
public string image_path { get; set; } public string image_path { get; set; }
public string desktop_entry { get; set; } public string desktop_entry { get; set; }
public string category { 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 resident { get; set; }
public bool transient { get; set; } public bool transient { get; set; }
public UrgencyLevels urgency { get; set; } public UrgencyLevels urgency { get; set; }
...@@ -250,6 +252,16 @@ namespace SwayNotificationCenter { ...@@ -250,6 +252,16 @@ namespace SwayNotificationCenter {
category = hint_value.get_string (); category = hint_value.get_string ();
} }
break; 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": case "resident":
if (hint_value.is_of_type (VariantType.BOOLEAN)) { if (hint_value.is_of_type (VariantType.BOOLEAN)) {
resident = hint_value.get_boolean (); resident = hint_value.get_boolean ();
...@@ -336,6 +348,8 @@ namespace SwayNotificationCenter { ...@@ -336,6 +348,8 @@ namespace SwayNotificationCenter {
params.set ("image_path", image_path); params.set ("image_path", image_path);
params.set ("desktop_entry", desktop_entry); params.set ("desktop_entry", desktop_entry);
params.set ("category", category); params.set ("category", category);
params.set ("sound_name", sound_name);
params.set ("sound_file", sound_file);
params.set ("resident", resident.to_string ()); params.set ("resident", resident.to_string ());
params.set ("urgency", urgency.to_string ()); params.set ("urgency", urgency.to_string ());
string[] _actions = {}; string[] _actions = {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment