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

Fixed segfault when reloading config

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