Reload theme on SIGHUP signal

Fixes #28

Allows for users/applications to request a theme reload
by sending SIGHUP signal to the daemon.
This commit is contained in:
Pablo Correa Gómez
2021-10-19 14:24:04 +00:00
committed by Guido Gunther
parent 753fff3e7a
commit 8e9bbd9d4c
4 changed files with 47 additions and 19 deletions
+4
View File
@@ -95,6 +95,10 @@ You can add your own themes in one of two ways:
$ sudo cp my_awesome_theme.json /usr/local/share/feedbackd/themes/
```
Upon reception of `SIGHUP` signal, the daemon process will proceed to retrigger
the above logic to find the themes, and reload the corresponding one. This can
be used to avoid having to restart the daemon in case of configuration changes.
Check out the companion [feedbackd-device-themes][1] repository for a
selection of device-specific themes. In order for your theme to be recognized
it must be named properly. Currently, theme names are based on the `compatible`
+29 -19
View File
@@ -492,29 +492,11 @@ find_themefile (void)
static void
fbd_feedback_manager_constructed (GObject *object)
{
g_autoptr (GError) err = NULL;
FbdFeedbackManager *self = FBD_FEEDBACK_MANAGER (object);
const gchar *themefile;
G_OBJECT_CLASS (fbd_feedback_manager_parent_class)->constructed (object);
// Overide themefile with environment variable if requested
themefile = g_getenv (FEEDBACKD_THEME_VAR);
// Search for device-specific configuration
if (!themefile)
themefile = find_themefile ();
// Fallback to default configuration if needed
if (!themefile)
themefile = FEEDBACKD_THEME_DIR "/default.json";
g_info ("Using themefile: %s", themefile);
self->theme = fbd_feedback_theme_new_from_file (themefile, &err);
if (!self->theme) {
/* No point to carry on */
g_error ("Failed to load theme: %s", err->message);
}
fbd_feedback_manager_load_theme(self);
g_signal_connect (self, "notify::profile", (GCallback)on_profile_changed, NULL);
lfb_gdbus_feedback_set_profile (LFB_GDBUS_FEEDBACK (self),
@@ -617,6 +599,34 @@ fbd_feedback_manager_get_dev_leds (FbdFeedbackManager *self)
return self->leds;
}
void fbd_feedback_manager_load_theme (FbdFeedbackManager *self) {
g_autoptr (GError) err = NULL;
g_autoptr (FbdFeedbackTheme) theme = NULL;
const gchar *themefile;
// Overide themefile with environment variable if requested
themefile = g_getenv (FEEDBACKD_THEME_VAR);
// Search for device-specific configuration
if (!themefile)
themefile = find_themefile ();
// Fallback to default configuration if needed
if (!themefile)
themefile = FEEDBACKD_THEME_DIR "/default.json";
g_info ("Using themefile: %s", themefile);
theme = fbd_feedback_theme_new_from_file (themefile, &err);
if (theme) {
g_set_object(&self->theme, theme);
} else {
if (self->theme)
g_warning ("Failed to reload theme: %s", err->message);
else
g_error ("Failed to load theme: %s", err->message); // No point to carry on
}
}
gboolean
fbd_feedback_manager_set_profile (FbdFeedbackManager *self, const gchar *profile)
{
+1
View File
@@ -22,6 +22,7 @@ FbdFeedbackManager *fbd_feedback_manager_get_default (void);
FbdDevVibra *fbd_feedback_manager_get_dev_vibra (FbdFeedbackManager *self);
FbdDevSound *fbd_feedback_manager_get_dev_sound (FbdFeedbackManager *self);
FbdDevLeds *fbd_feedback_manager_get_dev_leds (FbdFeedbackManager *self);
void fbd_feedback_manager_load_theme (FbdFeedbackManager *self);
gboolean fbd_feedback_manager_set_profile (FbdFeedbackManager *self, const gchar *profile);
G_END_DECLS
+13
View File
@@ -42,6 +42,18 @@ quit_cb (gpointer user_data)
return FALSE;
}
static gboolean
reload_cb (gpointer user_data)
{
FbdFeedbackManager *manager = fbd_feedback_manager_get_default();
g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (manager), FALSE);
g_debug ("Caught signal, reloading feedback theme...");
fbd_feedback_manager_load_theme (manager);
return TRUE;
}
static void
bus_acquired_cb (GDBusConnection *connection,
@@ -102,6 +114,7 @@ int main(int argc, char *argv[])
g_unix_signal_add (SIGTERM, quit_cb, NULL);
g_unix_signal_add (SIGINT, quit_cb, NULL);
g_unix_signal_add (SIGHUP, reload_cb, NULL);
loop = g_main_loop_new (NULL, FALSE);