Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/io.github.kolunmi.Bazaar.desktop.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Type=Application
Categories=Utility;
Keywords=GTK;System;PackageManager;Discover;Flatpak;Software;Store;
StartupNotify=true
MimeType=x-scheme-handler/appstream;x-scheme-handler/flatpak;x-scheme-handler/flatpak+https;application/vnd.flatpak;application/vnd.flatpak.ref;
MimeType=x-scheme-handler/appstream;x-scheme-handler/flatpak;x-scheme-handler/flatpak+https;application/vnd.flatpak;application/vnd.flatpak.ref;application/metainfo+xml;
Actions=new-window;
X-Purism-FormFactor=Workstation;Mobile;

Expand Down
1 change: 1 addition & 0 deletions src/bazaar.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<file preprocess="xml-stripblanks">bz-library-page.ui</file>
<file preprocess="xml-stripblanks">bz-license-dialog.ui</file>
<file preprocess="xml-stripblanks">bz-login-page.ui</file>
<file preprocess="xml-stripblanks">bz-metainfo-preview-page.ui</file>
<file preprocess="xml-stripblanks">bz-preferences-dialog.ui</file>
<file preprocess="xml-stripblanks">bz-progress-bar.ui</file>
<file preprocess="xml-stripblanks">bz-releases-dialog.ui</file>
Expand Down
230 changes: 112 additions & 118 deletions src/bz-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ struct _BzApplication
BzYamlParser *curated_parser;
DexChannel *flatpak_notifs;
DexFuture *notif_watch;
DexFuture *preview_metainfo;
DexFuture *sync;
DexPromise *first_window_opened;
DexPromise *ready_to_open_files;
Expand Down Expand Up @@ -179,6 +178,16 @@ BZ_DEFINE_DATA (
BZ_RELEASE_DATA (self, bz_weak_release);
BZ_RELEASE_DATA (file, g_object_unref))

BZ_DEFINE_DATA (
open_metainfo,
OpenMetainfo,
{
GWeakRef *self;
GFile *file;
},
BZ_RELEASE_DATA (self, bz_weak_release);
BZ_RELEASE_DATA (file, g_object_unref))

BZ_DEFINE_DATA (
open_appstream,
OpenAppstream,
Expand Down Expand Up @@ -227,6 +236,13 @@ open_appstream_fiber (OpenAppstreamData *data);
static DexFuture *
open_flatpakref_fiber (OpenFlatpakrefData *data);

static DexFuture *
open_metainfo_fiber (OpenMetainfoData *data);

static void
open_metainfo_take (BzApplication *self,
GFile *file);

static DexFuture *
backend_sync_finally (DexFuture *future,
GWeakRef *wr);
Expand Down Expand Up @@ -347,14 +363,6 @@ static void
open_generic_id (BzApplication *self,
const char *generic_id);

static DexFuture *
preview_metainfo_then (DexFuture *future,
GWeakRef *wr);

static DexFuture *
preview_metainfo_finally (DexFuture *future,
GWeakRef *wr);

static gpointer
map_strings_to_files (GtkStringObject *string,
gpointer data);
Expand Down Expand Up @@ -387,9 +395,6 @@ validate_group_for_ui (BzApplication *self,
static DexFuture *
make_sync_future (BzApplication *self);

static DexFuture *
make_preview_metainfo_future (BzApplication *self);

static void
finish_with_background_task_label (BzApplication *self);

Expand All @@ -404,7 +409,6 @@ bz_application_dispose (GObject *object)
dex_clear (&self->first_window_opened);
dex_clear (&self->flatpak_notifs);
dex_clear (&self->notif_watch);
dex_clear (&self->preview_metainfo);
dex_clear (&self->ready_to_open_files);
dex_clear (&self->sync);
g_clear_handle_id (&self->periodic_timeout_source, g_source_remove);
Expand Down Expand Up @@ -476,7 +480,6 @@ bz_application_command_line (GApplication *app,
g_auto (GStrv) blocklists_strv = NULL;
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[] = {
Expand All @@ -486,7 +489,6 @@ bz_application_command_line (GApplication *app,
{ "extra-curated-config", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &content_configs_strv, "Add an extra yaml file with which to configure the app browser" },
/* 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 }
Expand Down Expand Up @@ -583,20 +585,14 @@ bz_application_command_line (GApplication *app,
dex_future_disown (g_steal_pointer (&init));
}

if (!preview_metainfo)
{
if ((locations == NULL || *locations == NULL) && search_term == NULL)
new_window (self);
else
get_or_create_window (self);
}
if ((locations == NULL || *locations == NULL) && search_term == NULL)
new_window (self);
else
get_or_create_window (self);

if (locations != NULL && *locations != NULL)
command_line_open_location (self, cmdline, locations[0]);

if (preview_metainfo)
dex_future_disown (make_preview_metainfo_future (self));

if (search_term != NULL)
{
GtkWindow *window = NULL;
Expand Down Expand Up @@ -634,16 +630,6 @@ bz_application_class_init (BzApplicationClass *klass)
g_type_ensure (BZ_TYPE_RESULT);
}

static void
bz_application_preview_metainfo_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
BzApplication *self = user_data;

dex_future_disown (make_preview_metainfo_future (self));
}

static void
bz_application_toggle_debug_mode_action (GSimpleAction *action,
GVariant *parameter,
Expand Down Expand Up @@ -905,7 +891,6 @@ static const GActionEntry app_actions[] = {
{ "donate", bz_application_donate_action, NULL },
{ "bazaar-inspector", bz_application_bazaar_inspector_action, NULL },
{ "toggle-debug-mode", bz_application_toggle_debug_mode_action, NULL },
{ "preview-metainfo", bz_application_preview_metainfo_action, NULL },
};

static void
Expand Down Expand Up @@ -2173,6 +2158,59 @@ open_flatpakref_fiber (OpenFlatpakrefData *data)
return dex_future_new_true ();
}

static DexFuture *
open_metainfo_fiber (OpenMetainfoData *data)
{
g_autoptr (BzApplication) self = NULL;
GFile *file = data->file;
g_autoptr (GError) local_error = NULL;
g_autoptr (DexFuture) pick_future = NULL;
const GValue *value = NULL;
BzMetainfoPickResult *result = NULL;
g_autoptr (BzEntry) entry = NULL;
GtkWindow *window = NULL;

bz_weak_get_or_return_reject (self, data->self);
dex_await (dex_ref (self->ready_to_open_files), NULL);

window = get_or_create_window (self);
if (adw_application_window_get_visible_dialog (ADW_APPLICATION_WINDOW (window)) != NULL)
window = new_window (self);

pick_future = bz_metainfo_preview_open_file (file, window);
dex_await (dex_ref (pick_future), NULL);

value = dex_future_get_value (pick_future, &local_error);
if (value == NULL)
{
bz_show_error_for_widget (
GTK_WIDGET (window),
_ ("Failed to open file"),
local_error->message);

return dex_future_new_for_error (g_steal_pointer (&local_error));
}

result = g_value_get_boxed (value);

entry = bz_appstream_parser_entry_from_metainfo (
result->metainfo_file, result->icon_file, &local_error);
if (entry == NULL)
{
bz_show_error_for_widget (
GTK_WIDGET (window),
_ ("Failed to load metainfo"),
local_error->message);

return dex_future_new_for_error (g_steal_pointer (&local_error));
}

g_object_set (entry, "id", "preview", NULL);
bz_window_show_entry (BZ_WINDOW (window), entry);

return dex_future_new_true ();
}

static DexFuture *
init_fiber_finally (DexFuture *future,
GWeakRef *wr)
Expand Down Expand Up @@ -3735,30 +3773,57 @@ open_flatpakref_take (BzApplication *self,
open_flatpakref_data_unref));
}

static void
open_metainfo_take (BzApplication *self,
GFile *file)
{
g_autoptr (OpenMetainfoData) data = NULL;

data = open_metainfo_data_new ();
data->self = bz_track_weak (self);
data->file = g_steal_pointer (&file);

dex_future_disown (dex_scheduler_spawn (
dex_scheduler_get_default (),
bz_get_dex_stack_size (),
(DexFiberFunc) open_metainfo_fiber,
open_metainfo_data_ref (data),
open_metainfo_data_unref));
}

static void
command_line_open_location (BzApplication *self,
GApplicationCommandLine *cmdline,
const char *location)
{
if (g_uri_is_valid (location, G_URI_FLAGS_NONE, NULL))
g_autoptr (GFile) file = NULL;

if (g_uri_is_valid (location, G_URI_FLAGS_NONE, NULL) &&
g_str_has_prefix (location, "appstream:"))
{
if (g_str_has_prefix (location, "appstream:"))
open_appstream_take (self, g_strdup (location));
else
open_flatpakref_take (self, g_file_new_for_uri (location));
open_appstream_take (self, g_strdup (location));
return;
}

if (g_uri_is_valid (location, G_URI_FLAGS_NONE, NULL))
file = g_file_new_for_uri (location);
else if (g_path_is_absolute (location))
open_flatpakref_take (self, g_file_new_for_path (location));
file = g_file_new_for_path (location);
else
{
const char *cwd = NULL;

cwd = g_application_command_line_get_cwd (cmdline);
if (cwd != NULL)
open_flatpakref_take (self, g_file_new_build_filename (cwd, location, NULL));
else
open_flatpakref_take (self, g_file_new_for_path (location));

file = cwd != NULL
? g_file_new_build_filename (cwd, location, NULL)
: g_file_new_for_path (location);
}

if (g_str_has_suffix (location, ".metainfo.xml") ||
g_str_has_suffix (location, ".appdata.xml"))
open_metainfo_take (self, g_steal_pointer (&file));
else
open_flatpakref_take (self, g_steal_pointer (&file));
}

static void
Expand Down Expand Up @@ -3862,55 +3927,6 @@ open_generic_id (BzApplication *self,
}
}

static DexFuture *
preview_metainfo_then (DexFuture *future,
GWeakRef *wr)
{
g_autoptr (BzApplication) self = NULL;
g_autoptr (GError) local_error = NULL;
const GValue *value = NULL;
BzMetainfoPickResult *result = NULL;
g_autoptr (BzEntry) entry = NULL;
GtkWindow *window = NULL;

bz_weak_get_or_return_reject (self, wr);

value = dex_future_get_value (future, &local_error);
if (value == NULL)
return dex_future_new_true ();

result = g_value_get_boxed (value);
window = get_or_create_window (self);

entry = bz_appstream_parser_entry_from_metainfo (
result->metainfo_file,
result->icon_file,
&local_error);
if (entry == NULL)
{
bz_show_error_for_widget (GTK_WIDGET (window),
_ ("Failed to load metainfo"),
local_error->message);
return dex_future_new_true ();
}

bz_window_show_entry (BZ_WINDOW (window), entry);

return dex_future_new_true ();
}

static DexFuture *
preview_metainfo_finally (DexFuture *future,
GWeakRef *wr)
{
g_autoptr (BzApplication) self = NULL;

bz_weak_get_or_return_reject (self, wr);

dex_clear (&self->preview_metainfo);
return dex_future_new_true ();
}

static gpointer
map_strings_to_files (GtkStringObject *string,
gpointer data)
Expand Down Expand Up @@ -4118,28 +4134,6 @@ make_sync_future (BzApplication *self)
return g_steal_pointer (&ret_future);
}

static DexFuture *
make_preview_metainfo_future (BzApplication *self)
{
g_autoptr (DexFuture) future = NULL;

if (self->preview_metainfo != NULL)
return dex_ref (self->preview_metainfo);

future = bz_metainfo_preview_pick_files ();
future = dex_future_then (
g_steal_pointer (&future),
(DexFutureCallback) preview_metainfo_then,
bz_track_weak (self), bz_weak_release);
future = dex_future_finally (
g_steal_pointer (&future),
(DexFutureCallback) preview_metainfo_finally,
bz_track_weak (self), bz_weak_release);

self->preview_metainfo = dex_ref (future);
return g_steal_pointer (&future);
}

static void
finish_with_background_task_label (BzApplication *self)
{
Expand Down
6 changes: 0 additions & 6 deletions src/bz-inspector.blp
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,6 @@ BuilderListItemFactory plain_string_list_factory {
}

menu inspector_menu {
section {
item {
label: "_Preview Metainfo File";
action: "app.preview-metainfo";
}
}
section {
item {
label: "_Quit Bazaar";
Expand Down
Loading
Loading