From 8921bc2cbd60f3839fcb93751b2016f42af08822 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 11 Sep 2020 20:01:39 -0400 Subject: [PATCH] WIP Flatpak --- .gitignore | 2 + Jenkinsfile | 2 +- ...thebrokenrail.FeedbackD-Configuration.json | 47 ++++++++++++ src/main.c | 71 +++++++++++++------ 4 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 com.thebrokenrail.FeedbackD-Configuration.json diff --git a/.gitignore b/.gitignore index 567609b..fea391b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ build/ +build-flatpak/ +.flatpak-builder/ diff --git a/Jenkinsfile b/Jenkinsfile index a047c8e..aa7a017 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { stages { stage('Prepare Build') { steps { - sh 'mkdir build; cd build; cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILEr=clang++ ..' + sh 'mkdir build; cd build; cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..' } } stage('Build') { diff --git a/com.thebrokenrail.FeedbackD-Configuration.json b/com.thebrokenrail.FeedbackD-Configuration.json new file mode 100644 index 0000000..b8253f3 --- /dev/null +++ b/com.thebrokenrail.FeedbackD-Configuration.json @@ -0,0 +1,47 @@ +{ + "app-id": "com.thebrokenrail.FeedbackD-Configuration", + "runtime": "org.gnome.Platform", + "runtime-version": "3.36", + "sdk": "org.gnome.Sdk", + "command": "feedbackd-configuration", + "finish-args": [ + "--share=ipc", + "--socket=fallback-x11", + "--socket=wayland", + "--share=network", + "--talk-name=org.gtk.vfs", + "--talk-name=org.gtk.vfs.*", + "--parent-expose-pids" + ], + "modules": [ + { + "name": "feedbackd-configuration", + "builddir": true, + "buildsystem": "cmake", + "config-opts": [ + "-DCMAKE_C_COMPILER=clang", + "-DCMAKE_CXX_COMPILER=clang++" + ], + "sources": [ + { + "type": "dir", + "path": "." + } + ], + "modules": [ + { + "name": "libhandy1", + "builddir": true, + "buildsystem": "meson", + "sources": [ + { + "type": "git", + "url": "https://gitlab.gnome.org/GNOME/libhandy.git", + "tag": "1.0.0" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index 421e269..9e64395 100644 --- a/src/main.c +++ b/src/main.c @@ -11,8 +11,7 @@ static void on_startup() { hdy_init(); } -#define CONFIG_JSON "/usr/share/feedbackd/themes/default.json" -#define ADMIN_CONFIG_JSON "admin://"CONFIG_JSON +#define CONFIG_JSON_URI "admin:///usr/share/feedbackd/themes/default.json" JsonNode *root = NULL; @@ -142,8 +141,8 @@ static void load_profile(GtkListBox *list) { } } -// JSON File On admin:// -GFile *file; +// JSON GIO File +GFile *file = NULL; // Reload And Save Profiles void reload_profiles(int save) { @@ -159,17 +158,20 @@ void reload_profiles(int save) { json_generator_set_indent(generator, 4); json_generator_set_indent_char(generator, ' '); + // Open JSON GError *open_err = NULL; GFileOutputStream *stream = g_file_replace(file, NULL, 0, G_FILE_CREATE_NONE, NULL, &open_err); if (stream == NULL) { g_error("Error Opening File Stream: %s", open_err->message); } + // Write JSON GError *write_err = NULL; if (json_generator_to_stream(generator, G_OUTPUT_STREAM(stream), NULL, &write_err) == 0) { g_error("Error Saving JSON: %s", write_err->message); } + // Close JSON GError *close_err = NULL; if (g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, &close_err) == 0) { g_error("Error Closing File Stream: %s", close_err->message); @@ -177,7 +179,10 @@ void reload_profiles(int save) { g_object_unref(stream); // Restart FeedbackD +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-result" system("killall feedbackd"); +#pragma GCC diagnostic pop g_object_unref(generator); } @@ -196,8 +201,45 @@ void on_new_event(GtkButton *button, GtkStack *stack) { static void finish_mount(__attribute__((unused)) GObject *object, GAsyncResult *result, __attribute__((unused)) gpointer user_data) { GError *err = NULL; if (g_file_mount_enclosing_volume_finish(file, result, &err) == 0) { - g_error("Error Mounting JSON: %s", err->message); + g_error("Error Mounting GVFS: %s", err->message); } + + // Open JSON + GError *open_err = NULL; + GFileInputStream *stream = g_file_read(file, NULL, &open_err); + if (stream == NULL) { + g_error("Error Opening File Stream: %s", open_err->message); + } + + // Create JSON Parser + JsonParser *parser = json_parser_new(); + + // Load JSON + GError *json_err = NULL; + if (json_parser_load_from_stream(parser, G_INPUT_STREAM(stream), NULL, &json_err) == 0) { + g_error("Error Parsing JSON: %s", json_err->message); + } + + // Store JSON Data + root = json_node_copy(json_parser_get_root(parser)); + + // Free JSON Parser + g_object_unref(parser); + + // Close JSON + GError *close_err = NULL; + if (g_input_stream_close(G_INPUT_STREAM(stream), NULL, &close_err) == 0) { + g_error("Error Closing File Stream: %s", close_err->message); + } + g_object_unref(stream); + + // Cache JSON Objects + get_app_data()->full = get_profile("full"); + get_app_data()->quiet = get_profile("quiet"); + get_app_data()->silent = get_profile("silent"); + + // Reload Widgets + reload_profiles(0); } // App Start Handler @@ -209,6 +251,7 @@ static void on_activate(GtkApplication *app) { if (window == NULL) { GtkBuilder *builder = gtk_builder_new(); + // Load Window GError *err = NULL; if (gtk_builder_add_from_resource(builder, "/main_window.glade", &err) == 0) { g_error("Error Loading UI: %s", err->message); @@ -218,34 +261,18 @@ static void on_activate(GtkApplication *app) { gtk_builder_connect_signals(builder, NULL); - JsonParser *parser = json_parser_new(); - - GError *json_err = NULL; - if (json_parser_load_from_file(parser, CONFIG_JSON, &json_err) == 0) { - g_error("Error Parsing JSON: %s", json_err->message); - } - - root = json_node_copy(json_parser_get_root(parser)); + file = g_file_new_for_uri(CONFIG_JSON_URI); init_app_data(); get_app_data()->full_list = GTK_LIST_BOX(gtk_builder_get_object(builder, "full")); - get_app_data()->full = get_profile("full"); get_app_data()->quiet_list = GTK_LIST_BOX(gtk_builder_get_object(builder, "quiet")); - get_app_data()->quiet = get_profile("quiet"); get_app_data()->silent_list = GTK_LIST_BOX(gtk_builder_get_object(builder, "silent")); - get_app_data()->silent = get_profile("silent"); - - reload_profiles(0); - - g_object_unref(parser); g_object_unref(builder); gtk_window_set_application(window, app); - file = g_file_new_for_uri(ADMIN_CONFIG_JSON); - // Mount File GMountOperation *operation = gtk_mount_operation_new(window); g_file_mount_enclosing_volume(file, G_MOUNT_MOUNT_NONE, operation, NULL, finish_mount, NULL);