From 060c708432f1945e8f087ed864f3fd4a3a2344fc Mon Sep 17 00:00:00 2001 From: Alexander Vanhee <160625516+AlexanderVanhee@users.noreply.github.com> Date: Sun, 12 Jul 2026 10:47:55 +0200 Subject: [PATCH] Implement method launch search properly --- src/bazaar-daemon.c | 45 +++++++++++++++++++++++++++++++++++++++++--- src/bz-application.c | 15 ++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/bazaar-daemon.c b/src/bazaar-daemon.c index d02c67b4..da923ff9 100644 --- a/src/bazaar-daemon.c +++ b/src/bazaar-daemon.c @@ -530,9 +530,48 @@ method_activate_result (sd_bus_message *m, static int method_launch_search (sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { - _cleanup_ (strv_freep) char **terms = NULL; - // TODO: Actually open search in app with the terms - launch_app (NULL, 0); + _cleanup_ (strv_freep) char **terms = NULL; + _cleanup_ (generic_freep) char *joined = NULL; + _cleanup_ (generic_freep) char *arg = NULL; + char *args[1] = { NULL }; + uint32_t timestamp = 0; + size_t len = 0; + int n_terms = 0; + int i = 0; + int r = 0; + + r = sd_bus_message_read_strv (m, &terms); + if (r < 0) + return r; + + r = sd_bus_message_read (m, "u", ×tamp); + if (r < 0) + return r; + + n_terms = strv_count_local (terms); + if (n_terms == 0) + { + launch_app (NULL, 0); + return sd_bus_reply_method_return (m, NULL); + } + + for (i = 0; i < n_terms; i++) + len += strlen (terms[i]) + 1; + + joined = malloc (len); + joined[0] = '\0'; + for (i = 0; i < n_terms; i++) + { + strcat (joined, terms[i]); + if (i + 1 < n_terms) + strcat (joined, " "); + } + + arg = malloc (strlen ("--search-for=") + strlen (joined) + 1); + sprintf (arg, "--search-for=%s", joined); + + args[0] = arg; + launch_app (args, 1); return sd_bus_reply_method_return (m, NULL); } diff --git a/src/bz-application.c b/src/bz-application.c index e6adcd41..d0581478 100644 --- a/src/bz-application.c +++ b/src/bz-application.c @@ -466,6 +466,7 @@ bz_application_command_line (GApplication *app, g_auto (GStrv) content_configs_strv = NULL; g_auto (GStrv) locations = NULL; gboolean preview_metainfo = FALSE; + g_autofree char *search_term = NULL; GOptionEntry main_entries[] = { { "help", 0, 0, G_OPTION_ARG_NONE, &help, "Print help" }, @@ -475,6 +476,7 @@ bz_application_command_line (GApplication *app, /* Here for backwards compat */ { "extra-content-config", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &content_configs_strv, "Add an extra yaml file with which to configure the app browser (backwards compat)" }, { "preview-metainfo", 0, 0, G_OPTION_ARG_NONE, &preview_metainfo, "Preview a metainfo file by selecting it via file dialog" }, + { "search-for", 0, 0, G_OPTION_ARG_STRING, &search_term, "Open search with this term" }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &locations, "flatpakref file to open" }, { NULL } }; @@ -572,7 +574,7 @@ bz_application_command_line (GApplication *app, if (!preview_metainfo) { - if (locations == NULL || *locations == NULL) + if ((locations == NULL || *locations == NULL) && search_term == NULL) new_window (self); else get_or_create_window (self); @@ -594,6 +596,17 @@ bz_application_command_line (GApplication *app, dex_future_disown (g_steal_pointer (&future)); } + if (search_term != NULL) + { + GtkWindow *window = NULL; + + window = get_or_create_window (self); + if (adw_application_window_get_visible_dialog (ADW_APPLICATION_WINDOW (window)) != NULL) + window = new_window (self); + + bz_window_search (BZ_WINDOW (window), search_term); + } + return EXIT_SUCCESS; }