From 41f79a992e4cf69abc59f20f4b897c40f047ace1 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Tue, 4 Jun 2024 22:12:54 +0200 Subject: [PATCH] Fix icons not showing when using flake --- Cargo.toml | 2 +- flake.lock | 6 ++--- flake.nix | 73 +++++++++++++++++++++++++++++++-------------------- icons.toml | 2 +- src/ui/app.rs | 6 ++++- 5 files changed, 55 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f34d2dc..fc5df31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] # Core library -relm4 = "0.8.1" +relm4 = { version = "0.8.1" } # relm4-macros = "0.6.2" # Optional: reusable components relm4-components = "0.8.1" diff --git a/flake.lock b/flake.lock index c6af7fc..905efe1 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1716745752, - "narHash": "sha256-8K1R9Yg4r08rYk86Yq+lu3E9L3uRUb4xMqYHgl0VGS0=", + "lastModified": 1717469187, + "narHash": "sha256-UVvFGiWFGPfVXG7Xr6HPKChx9hhtzkGaGAS/Ph1Khjg=", "owner": "ipetkov", "repo": "crane", - "rev": "19ca94ec2d288de334ae932107816b4a97736cd8", + "rev": "7e86136dc729cdf237aa59a5a02687bc0d1144b6", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 347455f..df6c83c 100644 --- a/flake.nix +++ b/flake.nix @@ -12,17 +12,24 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, crane, flake-utils, ... }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + crane, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; craneLib = crane.mkLib pkgs; dbMigrationsFilter = path: _type: builtins.match ".*sql$" path != null; - dbMigrationsOrCargoFilter = path: type: - (dbMigrationsFilter path type) - || (craneLib.filterCargoSources path type); + dbMigrationsOrCargoFilter = + path: type: (dbMigrationsFilter path type) || (craneLib.filterCargoSources path type); dbMigrations = pkgs.lib.cleanSourceWith { src = craneLib.path ./db-migrations; # The original, unfiltered source @@ -36,7 +43,6 @@ src = craneLib.path ./.; # The original, unfiltered source filter = dbMigrationsOrCargoFilter; }; - # src = craneLib.cleanCargoSource (craneLib.path ./.); # Add icons.toml to $src when compiling dependencies (needed by relm4-icons) # Add db-migrations to $src when compiling dependencies (needed by sqlx) @@ -46,25 +52,36 @@ cp -r --no-preserve=mode,ownership ${dbMigrations} --no-target-dir $out/db-migrations/ ''; - nativeBuildInputs = with pkgs; [ pkg-config gtk4 ]; - - buildInputs = [ - # Add additional build inputs here - ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ - # Additional darwin specific inputs can be set here - pkgs.libiconv + nativeBuildInputs = with pkgs; [ + pkg-config + gtk4 ]; + + buildInputs = + [ + # Add additional build inputs here + ] + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; }; - my-crate = craneLib.buildPackage (commonArgs // { - cargoArtifacts = craneLib.buildDepsOnly commonArgs; + my-crate = craneLib.buildPackage ( + commonArgs + // { + cargoArtifacts = craneLib.buildDepsOnly commonArgs; - # Additional environment variables or build phases/hooks can be set - # here *without* rebuilding all dependency crates - # MY_CUSTOM_VAR = "some value"; - }); - in { - checks = { inherit my-crate; }; + # Additional environment variables or build phases/hooks can be set + # here *without* rebuilding all dependency crates + # MY_CUSTOM_VAR = "some value"; + } + ); + in + { + checks = { + inherit my-crate; + }; packages.default = my-crate; @@ -78,12 +95,12 @@ # MY_CUSTOM_DEVELOPMENT_VAR = "something else"; # Extra inputs can be added here; cargo and rustc are provided by default. - packages = with pkgs; - [ - # rustPackages.clippy - # rustfmt - # pre-commit - ]; + packages = with pkgs; [ + # rustPackages.clippy + # rustfmt + # pre-commit + ]; }; - }); + } + ); } diff --git a/icons.toml b/icons.toml index a4a8269..0a49695 100644 --- a/icons.toml +++ b/icons.toml @@ -1,5 +1,5 @@ # Recommended: Specify your app ID *OR* your base resource path for more robust icon loading -# app_id = "de.frajul.sheet-organizer" +base_resource_path = "/org/gtkrs/" # List of icon names you found (shipped with this crate) # Note: the file ending `-symbolic.svg` isn't part of the icon name. diff --git a/src/ui/app.rs b/src/ui/app.rs index 22d9e6d..2e9d78c 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -4,7 +4,7 @@ use chrono::Utc; use gtk::prelude::*; use relm4::{ component::{AsyncComponent, AsyncComponentParts, AsyncController}, - gtk::Adjustment, + gtk::{gdk, Adjustment}, prelude::*, AsyncComponentSender, }; @@ -115,6 +115,10 @@ impl AsyncComponent for AppModel { sender: AsyncComponentSender, ) -> AsyncComponentParts { relm4_icons::initialize_icons(); + let display = gdk::Display::default().unwrap(); + let theme = gtk::IconTheme::for_display(&display); + theme.add_resource_path("/org/gtkrs/icons/"); + theme.add_resource_path("/org/gtkrs/icons/scalable/actions/"); let mcdu = McduModel::builder() .launch(())