Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
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