From e686b5d974b7751b51b99d3b26fdbf29f303da31 Mon Sep 17 00:00:00 2001 From: Avery Date: Sat, 18 Nov 2023 21:13:08 -0500 Subject: [PATCH] Load about window info from appstream metadata --- data/cafe.avery.Delfin.gresource.xml.in | 6 ++++++ data/cafe.avery.Delfin.metainfo.xml.in | 28 +++++++++++++++++-------- data/meson.build | 20 ++++++++++++++++++ delfin/meson.build | 2 ++ delfin/src/borgar/about.rs | 14 +++++-------- delfin/src/main.rs | 24 +++++++++++++++++++-- delfin/src/meson_config.rs.in | 3 +++ meson.build | 1 + 8 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 data/cafe.avery.Delfin.gresource.xml.in diff --git a/data/cafe.avery.Delfin.gresource.xml.in b/data/cafe.avery.Delfin.gresource.xml.in new file mode 100644 index 0000000..dbd92f5 --- /dev/null +++ b/data/cafe.avery.Delfin.gresource.xml.in @@ -0,0 +1,6 @@ + + + + @APP_ID@.metainfo.xml + + diff --git a/data/cafe.avery.Delfin.metainfo.xml.in b/data/cafe.avery.Delfin.metainfo.xml.in index d1c08a6..4c5726c 100644 --- a/data/cafe.avery.Delfin.metainfo.xml.in +++ b/data/cafe.avery.Delfin.metainfo.xml.in @@ -5,15 +5,6 @@ Delfin Stream movies and TV shows from Jellyfin - CC-BY-SA-4.0 - GPL-3.0-only - - - - - 600 - -

TODO - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor @@ -21,6 +12,25 @@

+ CC-BY-SA-4.0 + GPL-3.0 + + https://delfin.avery.cafe/ + + + Avery + + + + + 600 + pointing + + + + always + + @APP_ID@.desktop @APP_ID@ diff --git a/data/meson.build b/data/meson.build index f0a4fdb..36493ea 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,3 +1,5 @@ +gnome = import('gnome') + subdir('icons') ascli_exe = find_program('appstreamcli') @@ -36,3 +38,21 @@ custom_target('gen-desktop-entry', install: true, install_dir: appsdir, ) + +resources_file = configure_file( + input: 'cafe.avery.Delfin.gresource.xml.in', + output: '@0@.gresource.xml'.format(app_id), + configuration: { + 'APP_ID': app_id, + }, +) + +# Compile and install resources +resources = gnome.compile_resources( + 'resources', + resources_file, + gresource_bundle: true, + source_dir: meson.current_build_dir(), + install: true, + install_dir: pkgdatadir, +) diff --git a/delfin/meson.build b/delfin/meson.build index bd2f8ee..ee6995a 100644 --- a/delfin/meson.build +++ b/delfin/meson.build @@ -3,6 +3,8 @@ config = configure_file( output: 'meson_config.rs', configuration: { 'APP_ID': app_id, + 'BUILDDIR': meson.project_build_root(), + 'PKGDATADIR': pkgdatadir, }, ) diff --git a/delfin/src/borgar/about.rs b/delfin/src/borgar/about.rs index e2c90fb..2fdc63b 100644 --- a/delfin/src/borgar/about.rs +++ b/delfin/src/borgar/about.rs @@ -1,7 +1,7 @@ use gtk::prelude::*; use relm4::{prelude::*, ComponentParts, SimpleComponent}; -use crate::{meson_config::APP_ID, tr}; +use crate::meson_config::APP_ID; pub(crate) struct About; @@ -12,17 +12,13 @@ impl SimpleComponent for About { type Output = (); view! { - // TODO: Load from appstream - adw::AboutWindow { + adw::AboutWindow::from_appdata( + &format!("/cafe/avery/Delfin/{}.metainfo.xml", APP_ID), + None, + ) { set_modal: true, set_visible: true, - - set_application_name: tr!("app-name"), - set_application_icon: APP_ID, - set_developer_name: "Avery ❤️", set_version: "0.0", - set_license_type: gtk::License::Agpl30, - set_website: "https://codeberg.org/avery42/delfin", } } diff --git a/delfin/src/main.rs b/delfin/src/main.rs index 8743397..6f37117 100644 --- a/delfin/src/main.rs +++ b/delfin/src/main.rs @@ -1,8 +1,12 @@ +use std::path::PathBuf; + +use anyhow::{bail, Context, Result}; use delfin::{ app::{App, APP_BROKER}, - meson_config::APP_ID, + meson_config::{APP_ID, BUILDDIR, RESOURCES_FILE}, }; -use relm4::RelmApp; +use gtk::gio; +use relm4::{gtk, RelmApp}; fn main() { env_logger::init(); @@ -12,6 +16,8 @@ fn main() { video_player_gst::init_gst(); } + load_resources().expect("Error loading resources"); + let app = RelmApp::new(APP_ID); relm4_icons::initialize_icons(); @@ -40,3 +46,17 @@ fn load_css() { relm4::set_global_css(&css); } + +fn load_resources() -> Result<()> { + let res = match gio::Resource::load(RESOURCES_FILE) { + Ok(res) => res, + Err(_) if cfg!(debug_assertions) => { + gio::Resource::load(PathBuf::from(BUILDDIR).join("data/resources.gresource")) + .context("Could not load fallback gresource file")? + } + Err(_) => bail!("Could not load gresource file"), + }; + + gio::resources_register(&res); + Ok(()) +} diff --git a/delfin/src/meson_config.rs.in b/delfin/src/meson_config.rs.in index 4c65a28..56de47b 100644 --- a/delfin/src/meson_config.rs.in +++ b/delfin/src/meson_config.rs.in @@ -1,2 +1,5 @@ // Generated by Meson from meson_config.rs.in - do not modify + pub const APP_ID: &str = "@APP_ID@"; +pub const BUILDDIR: &str = "@BUILDDIR@"; +pub const RESOURCES_FILE: &str = concat!("@PKGDATADIR@", "/resources.gresource"); diff --git a/meson.build b/meson.build index 7e34089..ca7e510 100644 --- a/meson.build +++ b/meson.build @@ -29,6 +29,7 @@ endif prefix = get_option('prefix') bindir = prefix / get_option('bindir') datadir = prefix / get_option('datadir') +pkgdatadir = datadir / meson.project_name() appsdir = datadir / 'applications' iconsdir = datadir / 'icons'