@@ -66,7 +66,8 @@ struct _BzApplication
6666 BzGnomeShellSearchProvider * gs_search ;
6767
6868 BzFlatpakInstance * flatpak ;
69- GFile * waiting_to_open ;
69+ char * waiting_to_open_appstream ;
70+ GFile * waiting_to_open_file ;
7071 BzFlathubState * flathub ;
7172 BzContentProvider * content_provider ;
7273
@@ -99,6 +100,10 @@ init_service_struct (BzApplication *self);
99100static DexFuture *
100101open_flatpakref_fiber (OpenFlatpakrefData * data );
101102
103+ static void
104+ open_generic_id (BzApplication * self ,
105+ const char * generic_id );
106+
102107static void
103108transaction_success (BzApplication * self ,
104109 BzTransaction * transaction ,
@@ -113,14 +118,18 @@ refresh (BzApplication *self);
113118static GtkWindow *
114119new_window (BzApplication * self );
115120
121+ static void
122+ open_appstream_take (BzApplication * self ,
123+ char * appstream );
124+
116125static void
117126open_flatpakref_take (BzApplication * self ,
118127 GFile * file );
119128
120129static void
121- command_line_open_flatpakref (BzApplication * self ,
122- GApplicationCommandLine * cmdline ,
123- const char * path );
130+ command_line_open_location (BzApplication * self ,
131+ GApplicationCommandLine * cmdline ,
132+ const char * path );
124133
125134static gint
126135cmp_group (BzEntryGroup * a ,
@@ -147,7 +156,7 @@ bz_application_dispose (GObject *object)
147156 g_clear_object (& self -> search_engine );
148157 g_clear_object (& self -> gs_search );
149158 g_clear_object (& self -> flatpak );
150- g_clear_object (& self -> waiting_to_open );
159+ g_clear_object (& self -> waiting_to_open_file );
151160 g_clear_object (& self -> entry_factory );
152161 g_clear_object (& self -> application_filter );
153162 g_clear_object (& self -> application_factory );
@@ -156,6 +165,7 @@ bz_application_dispose (GObject *object)
156165 g_clear_object (& self -> groups );
157166 g_clear_object (& self -> installed_apps );
158167 g_clear_object (& self -> state );
168+ g_clear_pointer (& self -> waiting_to_open_appstream , g_free );
159169 g_clear_pointer (& self -> init_timer , g_timer_destroy );
160170
161171 G_OBJECT_CLASS (bz_application_parent_class )-> dispose (object );
@@ -177,6 +187,7 @@ bz_application_command_line (GApplication *app,
177187 g_autofree GStrv argv_shallow = NULL ;
178188 const char * command = NULL ;
179189 gboolean window_autostart = FALSE;
190+ g_autofree char * location = NULL ;
180191
181192 argv = g_application_command_line_get_arguments (cmdline , & argc );
182193 g_debug ("Handling gapplication command line; argc=%d" , argc );
@@ -233,14 +244,14 @@ bz_application_command_line (GApplication *app,
233244 g_autoptr (GtkStringList ) blocklists = NULL ;
234245 g_auto (GStrv ) content_configs_strv = NULL ;
235246 g_autoptr (GtkStringList ) content_configs = NULL ;
236- g_auto (GStrv ) paths = NULL ;
247+ g_auto (GStrv ) locations = NULL ;
237248
238249 GOptionEntry main_entries [] = {
239250 { "help" , 0 , 0 , G_OPTION_ARG_NONE , & help , "Print help" },
240251 { "is-running" , 0 , 0 , G_OPTION_ARG_NONE , & is_running , "Exit successfully if the Bazaar service is running" },
241252 { "extra-blocklist" , 0 , 0 , G_OPTION_ARG_FILENAME_ARRAY , & blocklists_strv , "Add an extra blocklist to read from" },
242253 { "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" },
243- { G_OPTION_REMAINING , 0 , 0 , G_OPTION_ARG_FILENAME_ARRAY , & paths , "flatpakref file to open" },
254+ { G_OPTION_REMAINING , 0 , 0 , G_OPTION_ARG_FILENAME_ARRAY , & locations , "flatpakref file to open" },
244255 { NULL }
245256 };
246257
@@ -352,8 +363,11 @@ bz_application_command_line (GApplication *app,
352363 bz_state_info_set_curated_configs (self -> state , self -> content_configs );
353364 }
354365
355- if (paths != NULL && * paths != NULL )
356- command_line_open_flatpakref (self , cmdline , * paths );
366+ if (locations != NULL && * locations != NULL )
367+ {
368+ g_clear_pointer (& location , g_free );
369+ location = g_strdup (* locations );
370+ }
357371 }
358372 else if (!self -> running )
359373 {
@@ -411,12 +425,12 @@ bz_application_command_line (GApplication *app,
411425 }
412426 else if (g_strcmp0 (command , "open" ) == 0 )
413427 {
414- gboolean help = FALSE;
415- g_auto (GStrv ) paths = NULL ;
428+ gboolean help = FALSE;
429+ g_auto (GStrv ) locations = NULL ;
416430
417431 GOptionEntry main_entries [] = {
418432 { "help" , 0 , 0 , G_OPTION_ARG_NONE , & help , "Print help" },
419- { G_OPTION_REMAINING , 0 , 0 , G_OPTION_ARG_FILENAME_ARRAY , & paths , "flatpakref file to open" },
433+ { G_OPTION_REMAINING , 0 , 0 , G_OPTION_ARG_FILENAME_ARRAY , & locations , "flatpakref file to open" },
420434 { NULL }
421435 };
422436
@@ -438,7 +452,7 @@ bz_application_command_line (GApplication *app,
438452 return EXIT_SUCCESS ;
439453 }
440454
441- if (paths == NULL || * paths == NULL )
455+ if (locations == NULL || * locations == NULL )
442456 {
443457 g_application_command_line_printerr (cmdline , "Command \"open\" requires a file path argument\n" );
444458 return EXIT_FAILURE ;
@@ -448,8 +462,9 @@ bz_application_command_line (GApplication *app,
448462 if (gtk_application_get_active_window (GTK_APPLICATION (self )) == NULL )
449463 new_window (self );
450464
465+ g_clear_pointer (& location , g_free );
451466 /* Just take the first one for now */
452- command_line_open_flatpakref ( self , cmdline , * paths );
467+ location = g_strdup ( * locations );
453468 }
454469 else if (g_strcmp0 (command , "refresh" ) == 0 )
455470 {
@@ -603,6 +618,9 @@ bz_application_command_line (GApplication *app,
603618 }
604619 }
605620
621+ if (location != NULL )
622+ command_line_open_location (self , cmdline , location );
623+
606624 return EXIT_SUCCESS ;
607625}
608626
@@ -1083,30 +1101,38 @@ open_flatpakref_fiber (OpenFlatpakrefData *data)
10831101 bz_window_show_entry (BZ_WINDOW (window ), entry );
10841102 }
10851103 else
1086- {
1087- const char * generic_id = NULL ;
1088- BzEntryGroup * group = NULL ;
1089-
1090- generic_id = g_value_get_string (value );
1091- group = g_hash_table_lookup (self -> ids_to_groups , generic_id );
1092-
1093- if (group != NULL )
1094- bz_window_show_group (BZ_WINDOW (window ), group );
1095- else
1096- {
1097- g_autofree char * message = NULL ;
1098-
1099- message = g_strdup_printf ("ID '%s' was not found" , generic_id );
1100- bz_show_error_for_widget (GTK_WIDGET (window ), message );
1101- }
1102- }
1104+ open_generic_id (self , g_value_get_string (value ));
11031105 }
11041106 else
11051107 bz_show_error_for_widget (GTK_WIDGET (window ), local_error -> message );
11061108
11071109 return NULL ;
11081110}
11091111
1112+ static void
1113+ open_generic_id (BzApplication * self ,
1114+ const char * generic_id )
1115+ {
1116+ BzEntryGroup * group = NULL ;
1117+ GtkWindow * window = NULL ;
1118+
1119+ group = g_hash_table_lookup (self -> ids_to_groups , generic_id );
1120+
1121+ window = gtk_application_get_active_window (GTK_APPLICATION (self ));
1122+ if (window == NULL )
1123+ window = new_window (self );
1124+
1125+ if (group != NULL )
1126+ bz_window_show_group (BZ_WINDOW (window ), group );
1127+ else
1128+ {
1129+ g_autofree char * message = NULL ;
1130+
1131+ message = g_strdup_printf ("ID '%s' was not found" , generic_id );
1132+ bz_show_error_for_widget (GTK_WIDGET (window ), message );
1133+ }
1134+ }
1135+
11101136static void
11111137transaction_success (BzApplication * self ,
11121138 BzTransaction * transaction ,
@@ -1566,10 +1592,17 @@ refresh_finally (DexFuture *future,
15661592 }
15671593
15681594 g_debug ("Completely done with the refresh process!" );
1569- if (self -> waiting_to_open != NULL )
1595+
1596+ if (self -> waiting_to_open_appstream != NULL )
1597+ {
1598+ g_debug ("An appstream link was requested to be opened during refresh. Doing that now..." );
1599+ open_appstream_take (self , g_steal_pointer (& self -> waiting_to_open_appstream ));
1600+ }
1601+
1602+ if (self -> waiting_to_open_file != NULL )
15701603 {
15711604 g_debug ("A flatpakref was requested to be opened during refresh. Doing that now..." );
1572- open_flatpakref_take (self , g_steal_pointer (& self -> waiting_to_open ));
1605+ open_flatpakref_take (self , g_steal_pointer (& self -> waiting_to_open_file ));
15731606 }
15741607
15751608 return NULL ;
@@ -1629,6 +1662,28 @@ new_window (BzApplication *self)
16291662 return GTK_WINDOW (window );
16301663}
16311664
1665+ static void
1666+ open_appstream_take (BzApplication * self ,
1667+ char * appstream )
1668+ {
1669+ g_assert (appstream != NULL );
1670+
1671+ if (bz_state_info_get_busy (self -> state ))
1672+ {
1673+ g_debug ("Bazaar is currently refreshing, so we will load "
1674+ "the appstream link %s when that is done" ,
1675+ appstream );
1676+
1677+ g_clear_pointer (& self -> waiting_to_open_appstream , g_free );
1678+ self -> waiting_to_open_appstream = g_steal_pointer (& appstream );
1679+ }
1680+ else
1681+ open_generic_id (self , appstream + strlen ("appstream://" ));
1682+
1683+ if (appstream != NULL )
1684+ g_free (appstream );
1685+ }
1686+
16321687static void
16331688open_flatpakref_take (BzApplication * self ,
16341689 GFile * file )
@@ -1644,8 +1699,8 @@ open_flatpakref_take (BzApplication *self,
16441699 "the local flatpakref at %s when that is done" ,
16451700 path );
16461701
1647- g_clear_object (& self -> waiting_to_open );
1648- self -> waiting_to_open = g_steal_pointer (& file );
1702+ g_clear_object (& self -> waiting_to_open_file );
1703+ self -> waiting_to_open_file = g_steal_pointer (& file );
16491704 }
16501705 else
16511706 {
@@ -1669,23 +1724,28 @@ open_flatpakref_take (BzApplication *self,
16691724}
16701725
16711726static void
1672- command_line_open_flatpakref (BzApplication * self ,
1673- GApplicationCommandLine * cmdline ,
1674- const char * path )
1727+ command_line_open_location (BzApplication * self ,
1728+ GApplicationCommandLine * cmdline ,
1729+ const char * location )
16751730{
1676- if (g_uri_is_valid (path , G_URI_FLAGS_NONE , NULL ))
1677- open_flatpakref_take (self , g_file_new_for_uri (path ));
1678- else if (g_path_is_absolute (path ))
1679- open_flatpakref_take (self , g_file_new_for_path (path ));
1731+ if (g_uri_is_valid (location , G_URI_FLAGS_NONE , NULL ))
1732+ {
1733+ if (g_str_has_prefix (location , "appstream://" ))
1734+ open_appstream_take (self , g_strdup (location ));
1735+ else
1736+ open_flatpakref_take (self , g_file_new_for_uri (location ));
1737+ }
1738+ else if (g_path_is_absolute (location ))
1739+ open_flatpakref_take (self , g_file_new_for_path (location ));
16801740 else
16811741 {
16821742 const char * cwd = NULL ;
16831743
16841744 cwd = g_application_command_line_get_cwd (cmdline );
16851745 if (cwd != NULL )
1686- open_flatpakref_take (self , g_file_new_build_filename (cwd , path , NULL ));
1746+ open_flatpakref_take (self , g_file_new_build_filename (cwd , location , NULL ));
16871747 else
1688- open_flatpakref_take (self , g_file_new_for_path (path ));
1748+ open_flatpakref_take (self , g_file_new_for_path (location ));
16891749 }
16901750}
16911751
0 commit comments