Skip to content

Commit

Permalink
resource: Make path dependent on app_id
Browse files Browse the repository at this point in the history
AdwApplication automatically loads stylesheets [1] and its ancestor,
GtkApplication, setups an icon search path [2]. By default, the resource
path is derived from the app id [3]. These changes ensure that both,
stable and development builds, work without explicitly specifying
either.

[1] https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Application.html#automatic-resources

[2] https://docs.gtk.org/gtk4/class.Application.html#automatic-resources

[3] https://docs.gtk.org/gio/method.Application.set_resource_base_path.html
  • Loading branch information
oscfdezdz committed Nov 23, 2024
1 parent 7d54261 commit fd98622
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 36 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ config_h = configuration_data()
config_h.set_quoted('APP_VERSION', meson.project_version() + version_suffix)
config_h.set_quoted('GETTEXT_PACKAGE', 'extension-manager')
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
config_h.set_quoted('RESOURCE_PATH', '/' + app_id.replace('.', '/'))
config_h.set_quoted('APP_ID', app_id)
config_h.set_quoted('PKG_NAME', get_option('package'))
config_h.set_quoted('PKG_DISTRIBUTOR', get_option('distributor'))
Expand Down
14 changes: 1 addition & 13 deletions src/exm-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,13 @@ static void
exm_application_activate (GApplication *app)
{
GtkWindow *window;
GdkDisplay *display;
GtkCssProvider *provider;
GtkIconTheme *icon_theme;

/* It's good practice to check your parameters at the beginning of the
* function. It helps catch errors early and in development instead of
* by your users.
*/
g_assert (GTK_IS_APPLICATION (app));

display = gdk_display_get_default ();
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_resource (provider, "/com/mattjakeman/ExtensionManager/style.css");
gtk_style_context_add_provider_for_display (display, GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

icon_theme = gtk_icon_theme_get_for_display (display);
gtk_icon_theme_add_resource_path (icon_theme, "/com/mattjakeman/ExtensionManager/icons");

window = GTK_WINDOW (get_current_window (app));

/* Ask the window manager/compositor to present the window. */
Expand Down Expand Up @@ -175,7 +163,7 @@ exm_application_show_about (GSimpleAction *action,

window = gtk_application_get_active_window (GTK_APPLICATION (self));

about_dialog = adw_about_dialog_new_from_appdata ("/com/mattjakeman/ExtensionManager/com.mattjakeman.ExtensionManager.metainfo.xml",
about_dialog = adw_about_dialog_new_from_appdata (g_strdup_printf ("%s/com.mattjakeman.ExtensionManager.metainfo.xml", RESOURCE_PATH),
strstr (APP_ID, ".Devel") == NULL ? APP_VERSION : NULL);

adw_about_dialog_set_version (ADW_ABOUT_DIALOG (about_dialog), APP_VERSION);
Expand Down
4 changes: 2 additions & 2 deletions src/exm-browse-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ load_suggestions (ExmBrowsePage *self)
char **suggest_array;
gsize length;

contents = exm_utils_read_resource ("/com/mattjakeman/ExtensionManager/suggestions.txt", &length);
contents = exm_utils_read_resource (g_strdup_printf ("%s/suggestions.txt", RESOURCE_PATH), &length);
self->suggestions = gtk_string_list_new (NULL);

if (contents)
Expand Down Expand Up @@ -402,7 +402,7 @@ exm_browse_page_class_init (ExmBrowsePageClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-browse-page.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-browse-page.ui", RESOURCE_PATH));
gtk_widget_class_bind_template_child (widget_class, ExmBrowsePage, search_entry);
gtk_widget_class_bind_template_child (widget_class, ExmBrowsePage, search_results);
gtk_widget_class_bind_template_child (widget_class, ExmBrowsePage, search_stack);
Expand Down
4 changes: 3 additions & 1 deletion src/exm-comment-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <glib/gi18n.h>

#include "exm-config.h"

struct _ExmCommentDialog
{
AdwDialog parent_instance;
Expand Down Expand Up @@ -124,7 +126,7 @@ exm_comment_dialog_class_init (ExmCommentDialogClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-comment-dialog.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-comment-dialog.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmCommentDialog, list_box);
gtk_widget_class_bind_template_child (widget_class, ExmCommentDialog, stack);
Expand Down
4 changes: 3 additions & 1 deletion src/exm-comment-tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "exm-rating.h"

#include "exm-config.h"

struct _ExmCommentTile
{
GtkWidget parent_instance;
Expand Down Expand Up @@ -147,7 +149,7 @@ exm_comment_tile_class_init (ExmCommentTileClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-comment-tile.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-comment-tile.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, author);
gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, author_badge);
Expand Down
4 changes: 3 additions & 1 deletion src/exm-detail-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "exm-types.h"
#include "exm-enums.h"

#include "exm-config.h"

#include <glib/gi18n.h>

struct _ExmDetailView
Expand Down Expand Up @@ -659,7 +661,7 @@ exm_detail_view_class_init (ExmDetailViewClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-detail-view.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-detail-view.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmDetailView, header_bar);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, title);
Expand Down
2 changes: 1 addition & 1 deletion src/exm-error-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ exm_error_dialog_class_init (ExmErrorDialogClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-error-dialog.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-error-dialog.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmErrorDialog, text_view);
gtk_widget_class_bind_template_child (widget_class, ExmErrorDialog, instructions);
Expand Down
4 changes: 3 additions & 1 deletion src/exm-extension-row.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "exm-enums.h"
#include "exm-types.h"

#include "exm-config.h"

struct _ExmExtensionRow
{
AdwExpanderRow parent_instance;
Expand Down Expand Up @@ -298,7 +300,7 @@ exm_extension_row_class_init (ExmExtensionRowClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-extension-row.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-extension-row.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmExtensionRow, description_label);
gtk_widget_class_bind_template_child (widget_class, ExmExtensionRow, version_title);
Expand Down
5 changes: 3 additions & 2 deletions src/exm-info-bar.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "exm-info-bar.h"

#include <adwaita.h>
#include "exm-config.h"

#include <glib/gi18n.h>

struct _ExmInfoBar
Expand Down Expand Up @@ -50,7 +51,7 @@ exm_info_bar_class_init (ExmInfoBarClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-info-bar.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-info-bar.ui", RESOURCE_PATH));

g_type_ensure (EXM_TYPE_INFO_BAR);

Expand Down
2 changes: 1 addition & 1 deletion src/exm-installed-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ exm_installed_page_class_init (ExmInstalledPageClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-installed-page.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-installed-page.ui", RESOURCE_PATH));
gtk_widget_class_bind_template_child (widget_class, ExmInstalledPage, updates_banner);
gtk_widget_class_bind_template_child (widget_class, ExmInstalledPage, global_toggle);
gtk_widget_class_bind_template_child (widget_class, ExmInstalledPage, user_list_box);
Expand Down
4 changes: 3 additions & 1 deletion src/exm-rating.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "exm-rating.h"

#include "exm-config.h"

#include <glib/gi18n.h>

struct _ExmRating
Expand Down Expand Up @@ -155,7 +157,7 @@ exm_rating_class_init (ExmRatingClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-rating.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-rating.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmRating, star_one);
gtk_widget_class_bind_template_child (widget_class, ExmRating, star_two);
Expand Down
4 changes: 3 additions & 1 deletion src/exm-screenshot-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "exm-zoom-picture.h"

#include "exm-config.h"

struct _ExmScreenshotView
{
AdwNavigationPage parent_instance;
Expand Down Expand Up @@ -78,7 +80,7 @@ exm_screenshot_view_class_init (ExmScreenshotViewClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-screenshot-view.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-screenshot-view.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmScreenshotView, overlay_screenshot);

Expand Down
4 changes: 3 additions & 1 deletion src/exm-screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "exm-zoom-picture.h"

#include "exm-config.h"

struct _ExmScreenshot
{
GtkWidget parent_instance;
Expand Down Expand Up @@ -143,7 +145,7 @@ exm_screenshot_class_init (ExmScreenshotClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-screenshot.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-screenshot.ui", RESOURCE_PATH));

widget_class->get_request_mode = exm_screenshot_get_request_mode;
widget_class->measure = exm_screenshot_measure;
Expand Down
4 changes: 3 additions & 1 deletion src/exm-search-row.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "exm-types.h"
#include "exm-enums.h"

#include "exm-config.h"

#include <glib/gi18n.h>

struct _ExmSearchRow
Expand Down Expand Up @@ -186,7 +188,7 @@ exm_search_row_class_init (ExmSearchRowClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-search-row.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-search-row.ui", RESOURCE_PATH));

gtk_widget_class_bind_template_child (widget_class, ExmSearchRow, install_btn);

Expand Down
4 changes: 3 additions & 1 deletion src/exm-upgrade-assistant.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "web/exm-data-provider.h"
#include "exm-upgrade-result.h"

#include "exm-config.h"

#include <glib/gi18n.h>

struct _ExmUpgradeAssistant
Expand Down Expand Up @@ -634,7 +636,7 @@ exm_upgrade_assistant_class_init (ExmUpgradeAssistantClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-upgrade-assistant.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-upgrade-assistant.ui", RESOURCE_PATH));
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, user_list_box);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, system_list_box);
gtk_widget_class_bind_template_child (widget_class, ExmUpgradeAssistant, run_button);
Expand Down
2 changes: 1 addition & 1 deletion src/exm-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ exm_window_class_init (ExmWindowClass *klass)

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-window.ui");
gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-window.ui", RESOURCE_PATH));
gtk_widget_class_bind_template_child (widget_class, ExmWindow, header_bar);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, installed_page);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, browse_page);
Expand Down
8 changes: 2 additions & 6 deletions src/exm.gresource.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/mattjakeman/ExtensionManager">
<gresource prefix="@resource_path@">
<file>exm-window.ui</file>
<file>exm-installed-page.ui</file>
<file>exm-browse-page.ui</file>
Expand All @@ -21,11 +21,7 @@
<file>style.css</file>
</gresource>

<gresource prefix="/com/mattjakeman/ExtensionManager/Devel">
<file alias="gtk/help-overlay.ui">exm-help-overlay.ui</file>
</gresource>

<gresource prefix="/com/mattjakeman/ExtensionManager/icons/scalable/actions">
<gresource prefix="@resource_path@/icons/scalable/actions">
<file preprocess="xml-stripblanks" alias="clock-alt-symbolic.svg">../data/icons/hicolor/scalable/actions/clock-alt-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="donation-symbolic.svg">../data/icons/hicolor/scalable/actions/donation-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="external-link-symbolic.svg">../data/icons/hicolor/scalable/actions/external-link-symbolic.svg</file>
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ run_crash_reporter (const char *error_text)
// Setup CSS
GdkDisplay *display = gdk_display_get_default ();
GtkCssProvider *provider = gtk_css_provider_new ();
gtk_css_provider_load_from_resource (provider, "/com/mattjakeman/ExtensionManager/style.css");
gtk_css_provider_load_from_resource (provider, g_strdup_printf ("%s/style.css", RESOURCE_PATH));
gtk_style_context_add_provider_for_display (display, GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ exm_sources += gnome.mkenums_simple('exm-enums',

gresourceconf = configuration_data()
gresourceconf.set('appstream_file', '@[email protected]'.format(app_id))
gresourceconf.set('resource_path', '/' + app_id.replace('.', '/'))

gresource_file = configure_file(
input: 'exm.gresource.xml.in',
Expand Down

0 comments on commit fd98622

Please sign in to comment.