Commit 2265b27a authored by Erik Reider's avatar Erik Reider

Fixed segfault when reloading config

parent 6b4e6734
...@@ -148,11 +148,10 @@ namespace SwayNotificationCenter { ...@@ -148,11 +148,10 @@ namespace SwayNotificationCenter {
/** Adds all custom widgets. Removes previous widgets */ /** Adds all custom widgets. Removes previous widgets */
public void add_widgets () { public void add_widgets () {
// Remove all widgets // Remove all widgets
while (widgets.length > 0) { foreach (var widget in widgets.data) {
uint i = widgets.length - 1; box.remove(widget);
widgets.index (i).destroy ();
widgets.remove_index (i);
} }
widgets.remove_range (0, widgets.length);
string[] w = ConfigModel.instance.widgets.data; string[] w = ConfigModel.instance.widgets.data;
if (w.length == 0) w = DEFAULT_WIDGETS; if (w.length == 0) w = DEFAULT_WIDGETS;
......
...@@ -39,10 +39,10 @@ namespace SwayNotificationCenter.Widgets { ...@@ -39,10 +39,10 @@ namespace SwayNotificationCenter.Widgets {
public virtual void on_cc_visibility_change (bool value) {} public virtual void on_cc_visibility_change (bool value) {}
protected void get_prop<T> (Json.Object config, string value_key, ref T value) { protected T? get_prop<T> (Json.Object config, string value_key) {
if (!config.has_member (value_key)) { if (!config.has_member (value_key)) {
warning ("%s: Config doesn't have key: %s!\n", key, value_key); debug ("%s: Config doesn't have key: %s!\n", key, value_key);
return; return null;
} }
var member = config.get_member (value_key); var member = config.get_member (value_key);
...@@ -57,18 +57,17 @@ namespace SwayNotificationCenter.Widgets { ...@@ -57,18 +57,17 @@ namespace SwayNotificationCenter.Widgets {
key, key,
typeof (T).name (), typeof (T).name (),
member.get_value_type ().name ()); member.get_value_type ().name ());
return; return null;
} }
switch (generic_base_type) { switch (generic_base_type) {
case Type.STRING: case Type.STRING:
value = member.get_string (); return member.get_string ();
return;
case Type.INT64: case Type.INT64:
value = member.get_int (); return (int) member.get_int ();
return;
case Type.BOOLEAN: case Type.BOOLEAN:
value = member.get_boolean (); return member.get_boolean ();
return; default:
return null;
} }
} }
} }
......
...@@ -18,7 +18,8 @@ namespace SwayNotificationCenter.Widgets { ...@@ -18,7 +18,8 @@ namespace SwayNotificationCenter.Widgets {
Json.Object ? config = get_config (this); Json.Object ? config = get_config (this);
if (config != null) { if (config != null) {
// Get title // Get title
get_prop<string> (config, "text", ref title); string? title = get_prop<string> (config, "text");
if (title != null) this.title = title;
} }
// Title // Title
......
...@@ -18,9 +18,11 @@ namespace SwayNotificationCenter.Widgets { ...@@ -18,9 +18,11 @@ namespace SwayNotificationCenter.Widgets {
Json.Object ? config = get_config (this); Json.Object ? config = get_config (this);
if (config != null) { if (config != null) {
// Get text // Get text
get_prop<string> (config, "text", ref text); string? text = get_prop<string> (config, "text");
if (text != null) this.text = text;
// Get max lines // Get max lines
get_prop<int> (config, "max-lines", ref max_lines); int? max_lines = get_prop<int> (config, "max-lines");
if (max_lines != null) this.max_lines = max_lines;
} }
label_widget = new Gtk.Label (null); label_widget = new Gtk.Label (null);
......
...@@ -82,10 +82,12 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -82,10 +82,12 @@ namespace SwayNotificationCenter.Widgets.Mpris {
Json.Object ? config = get_config (this); Json.Object ? config = get_config (this);
if (config != null) { if (config != null) {
// Get image-size // Get image-size
get_prop<int> (config, "image-size", ref mpris_config.image_size); int? image_size = get_prop<int> (config, "image-size");
if (image_size != null) mpris_config.image_size = image_size;
// Get image-border-radius // Get image-border-radius
get_prop<int> (config, "image-radius", ref mpris_config.image_radius); int? image_radius = get_prop<int> (config, "image-radius");
if (image_radius != null) mpris_config.image_radius = image_radius;
// Clamp the radius // Clamp the radius
mpris_config.image_radius = mpris_config.image_radius.clamp ( mpris_config.image_radius = mpris_config.image_radius.clamp (
0, (int) (mpris_config.image_size * 0.5)); 0, (int) (mpris_config.image_size * 0.5));
......
...@@ -20,10 +20,14 @@ namespace SwayNotificationCenter.Widgets { ...@@ -20,10 +20,14 @@ namespace SwayNotificationCenter.Widgets {
Json.Object ? config = get_config (this); Json.Object ? config = get_config (this);
if (config != null) { if (config != null) {
// Get title // Get title
get_prop<string> (config, "text", ref title); string? title = get_prop<string> (config, "text");
if (title != null) this.title = title;
// Get has clear-all-button // Get has clear-all-button
get_prop<bool> (config, "clear-all-button", ref has_clear_all_button); bool? has_clear_all_button = get_prop<bool> (config, "clear-all-button");
get_prop<string> (config, "button-text", ref button_text); if (has_clear_all_button != null) this.has_clear_all_button = has_clear_all_button;
// Get button text
string? button_text = get_prop<string> (config, "button-text");
if (button_text != null) this.button_text = button_text;
} }
title_widget = new Gtk.Label (title); title_widget = new Gtk.Label (title);
......
...@@ -153,6 +153,8 @@ namespace SwayNotificationCenter { ...@@ -153,6 +153,8 @@ namespace SwayNotificationCenter {
/** Reloads the config file */ /** Reloads the config file */
public void reload_config () throws Error { public void reload_config () throws Error {
print("\n");
message("Reloading config\n");
ConfigModel.reload_config (); ConfigModel.reload_config ();
noti_daemon.control_center.add_widgets (); noti_daemon.control_center.add_widgets ();
} }
......
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