Skip to content

Commit

Permalink
Merge pull request #316 from autonomys/update-relm4
Browse files Browse the repository at this point in the history
Update `relm4` and `gtk4` to newer versions
  • Loading branch information
nazar-pc authored Oct 29, 2024
2 parents ddf4d57 + 983b7d3 commit 40deff6
Show file tree
Hide file tree
Showing 10 changed files with 386 additions and 165 deletions.
449 changes: 321 additions & 128 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ frame-system = { git = "https://github.com/subspace/polkadot-sdk", rev = "587181
fs4 = "0.10.0"
futures = "0.3.31"
futures-timer = "3.0.3"
gtk = { version = "0.7.3", package = "gtk4", features = ["v4_14"] }
gtk = { version = "0.9.2", package = "gtk4", features = ["v4_14"] }
hex = "0.4.3"
image = { version = "0.25.4", default-features = false, features = ["png"] }
mimalloc = "0.1.43"
Expand All @@ -61,9 +61,10 @@ open = "5.3.0"
pallet-balances = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42", default-features = false }
parity-scale-codec = "3.6.12"
parking_lot = "0.12.3"
relm4 = "0.7.0-rc.1"
relm4-components = { version = "0.7.0-rc.1", default-features = false }
relm4-icons = { version = "0.7.0-alpha.2", features = ["checkmark", "cross", "grid-filled", "menu-large", "pause", "processor", "puzzle-piece", "size-horizontally", "speedometer2", "speedometer3", "speedometer4", "ssd", "wallet2", "warning"] }
relm4 = "0.9.1"
relm4-components = { version = "0.9.1", default-features = false }
# TODO: Switch to upstream release 0.10.0+ that includes https://github.com/Relm4/icons/pull/19
relm4-icons = { version = "0.9.0", git = "https://github.com/Relm4/icons", rev = "74dc5af44e0dc6bb397cbb6c32d6d57661a26601" }
reqwest = { version = "0.12.8", default-features = false, features = ["json", "rustls-tls"] }
sc-client-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42", default-features = false }
sc-client-db = { git = "https://github.com/subspace/polkadot-sdk", rev = "5871818e1d736f1843eb9078f886290695165c42", default-features = false }
Expand Down Expand Up @@ -125,6 +126,8 @@ ksni = "0.2.2"

[build-dependencies]
fluent-static-codegen = "0.5.0"
# TODO: Switch to upstream release, right now it is unreleased
relm4-icons-build = { version = "0.1.0", git = "https://github.com/Relm4/icons", rev = "74dc5af44e0dc6bb397cbb6c32d6d57661a26601" }

[target.'cfg(windows)'.build-dependencies]
winres = "0.1.12"
Expand Down
23 changes: 23 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,27 @@ fn main() {
res.set_icon("res\\windows\\space-acres.ico");
res.compile().unwrap();
}

relm4_icons_build::bundle_icons(
"icon_names.rs",
None,
None,
None::<&str>,
[
"ssd",
"size-horizontally",
"cross",
"checkmark",
"wallet2",
"warning",
"puzzle-piece",
"pause",
"menu-large",
"processor",
"speedometer2",
"speedometer3",
"speedometer4",
"grid-filled",
],
);
}
14 changes: 6 additions & 8 deletions src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::frontend::loading::{LoadingInput, LoadingView};
use crate::frontend::new_version::NewVersion;
use crate::frontend::running::{RunningInit, RunningInput, RunningOutput, RunningView};
use crate::frontend::translations::{AsDefaultStr, T};
use crate::AppStatusCode;
use crate::{icon_names, AppStatusCode};
use futures::channel::mpsc;
use futures::{SinkExt, StreamExt};
use gtk::glib;
Expand All @@ -23,7 +23,6 @@ use notify_rust::Notification;
use relm4::actions::{RelmAction, RelmActionGroup};
use relm4::prelude::*;
use relm4::{Sender, ShutdownReceiver};
use relm4_icons::icon_name;
use std::any::Any;
use std::cell::{Cell, LazyCell};
use std::future::Future;
Expand Down Expand Up @@ -300,15 +299,15 @@ impl AsyncComponent for App {
// cases, would be nice to just hide corresponding menu item instead
gtk::MenuButton {
set_direction: gtk::ArrowType::None,
set_icon_name: icon_name::MENU_LARGE,
set_icon_name: icon_names::MENU_LARGE,
set_popover: Some(&gtk::PopoverMenu::from_model(Some(&main_menu_without_change_configuration))),
#[track = "model.changed_current_raw_config()"]
set_visible: model.current_raw_config.is_none(),
},

gtk::MenuButton {
set_direction: gtk::ArrowType::None,
set_icon_name: icon_name::MENU_LARGE,
set_icon_name: icon_names::MENU_LARGE,
set_popover: Some(&gtk::PopoverMenu::from_model(Some(&main_menu))),
#[track = "model.changed_current_raw_config()"]
set_visible: model.current_raw_config.is_some(),
Expand All @@ -330,7 +329,7 @@ impl AsyncComponent for App {

gtk::Image {
set_height_request: 256,
set_from_paintable: Some(&*PIXBUF_ABOUT_IMG),
set_paintable: Some(&*PIXBUF_ABOUT_IMG),
},

gtk::Label {
Expand Down Expand Up @@ -360,7 +359,7 @@ impl AsyncComponent for App {

gtk::Image {
set_height_request: 256,
set_from_paintable: Some(&*PIXBUF_ABOUT_IMG),
set_paintable: Some(&*PIXBUF_ABOUT_IMG),
},

gtk::Label {
Expand Down Expand Up @@ -563,8 +562,7 @@ impl AsyncComponent for App {
.program_name("Space Acres")
.version(env!("CARGO_PKG_VERSION"))
.authors(env!("CARGO_PKG_AUTHORS").split(':').collect::<Vec<_>>())
// TODO: Use https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/6643 once available
.license("Zero-Clause BSD: https://opensource.org/license/0bsd/")
.license_type(gtk::License::_0bsd)
.website(env!("CARGO_PKG_REPOSITORY"))
.website_label("GitHub")
.comments(env!("CARGO_PKG_DESCRIPTION"))
Expand Down
10 changes: 5 additions & 5 deletions src/frontend/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::frontend::configuration::farm::{
};
use crate::frontend::configuration::utils::is_directory_writable;
use crate::frontend::translations::{AsDefaultStr, T};
use crate::icon_names;
use gtk::glib;
use gtk::prelude::*;
use relm4::factory::AsyncFactoryVecDeque;
use relm4::prelude::*;
use relm4_components::open_dialog::{
OpenDialog, OpenDialogMsg, OpenDialogResponse, OpenDialogSettings,
};
use relm4_icons::icon_name;
use std::ops::Deref;
use std::path::PathBuf;
use subspace_farmer::utils::ss58::parse_ss58_reward_address;
Expand Down Expand Up @@ -104,9 +104,9 @@ where

fn icon(&self) -> Option<&'static str> {
if self.is_valid {
Some(icon_name::CHECKMARK)
Some(icon_names::CHECKMARK)
} else {
Some(icon_name::CROSS)
Some(icon_names::CROSS)
}
}
}
Expand Down Expand Up @@ -217,7 +217,7 @@ impl AsyncComponent for ConfigurationView {
)
.as_str(),
),
set_primary_icon_name: Some(icon_name::SSD),
set_primary_icon_name: Some(icon_names::SSD),
set_primary_icon_activatable: false,
set_primary_icon_sensitive: false,
#[track = "model.node_path.changed_is_valid()"]
Expand Down Expand Up @@ -290,7 +290,7 @@ impl AsyncComponent for ConfigurationView {
)
.as_str(),
),
set_primary_icon_name: Some(icon_name::WALLET2),
set_primary_icon_name: Some(icon_names::WALLET2),
set_primary_icon_activatable: false,
set_primary_icon_sensitive: false,
#[track = "model.reward_address.changed_is_valid()"]
Expand Down
10 changes: 5 additions & 5 deletions src/frontend/configuration/farm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::backend::config::{Farm, MIN_FARM_SIZE};
use crate::frontend::configuration::MaybeValid;
use crate::icon_names;
use bytesize::ByteSize;
use gtk::prelude::*;
use std::fmt;
Expand All @@ -11,7 +12,6 @@ use crate::frontend::configuration::utils::is_directory_writable;
use crate::frontend::translations::{AsDefaultStr, T};
use relm4::AsyncFactorySender;
use relm4_components::simple_combo_box::SimpleComboBox;
use relm4_icons::icon_name;
use std::path::PathBuf;
use std::str::FromStr;
use tracing::warn;
Expand Down Expand Up @@ -154,7 +154,7 @@ impl AsyncFactoryComponent for FarmWidget {
)
.as_str(),
),
set_primary_icon_name: Some(icon_name::SSD),
set_primary_icon_name: Some(icon_names::SSD),
set_primary_icon_activatable: false,
set_primary_icon_sensitive: false,
#[track = "self.path.changed_is_valid()"]
Expand Down Expand Up @@ -199,7 +199,7 @@ impl AsyncFactoryComponent for FarmWidget {
set_placeholder_text: Some(
&T.configuration_farm_fixed_size_placeholder(),
),
set_primary_icon_name: Some(icon_name::SIZE_HORIZONTALLY),
set_primary_icon_name: Some(icon_names::SIZE_HORIZONTALLY),
set_primary_icon_activatable: false,
set_primary_icon_sensitive: false,
#[track = "self.fixed_size.changed_is_valid()"]
Expand Down Expand Up @@ -231,7 +231,7 @@ impl AsyncFactoryComponent for FarmWidget {
set_placeholder_text: Some(
&T.configuration_farm_free_percentage_size_placeholder(),
),
set_primary_icon_name: Some(icon_name::SIZE_HORIZONTALLY),
set_primary_icon_name: Some(icon_names::SIZE_HORIZONTALLY),
set_primary_icon_activatable: false,
set_primary_icon_sensitive: false,
#[track = "self.free_percentage_size.changed_is_valid()"]
Expand All @@ -254,7 +254,7 @@ impl AsyncFactoryComponent for FarmWidget {
warn!("Can't send delete output");
}
},
set_icon_name: icon_name::CROSS,
set_icon_name: icon_names::CROSS,
set_tooltip: &T.configuration_farm_delete(),
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use crate::frontend::widgets::progress_circle::{
ProgressCircle, ProgressCircleInit, ProgressCircleInput,
};
use crate::frontend::NotificationExt;
use crate::icon_names;
use gtk::prelude::*;
use notify_rust::Notification;
use relm4::factory::FactoryHashMap;
use relm4::prelude::*;
use relm4_icons::icon_name;
use sp_consensus_subspace::ChainConstants;
use std::num::NonZeroU8;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -129,15 +129,15 @@ impl Component for RunningView {
connect_clicked => RunningInput::ToggleFarmDetails,
set_cursor_from_name: Some("pointer"),
set_has_frame: false,
set_icon_name: icon_name::GRID_FILLED,
set_icon_name: icon_names::GRID_FILLED,
set_tooltip: &T.running_farmer_button_expand_details(),
},
gtk::ToggleButton {
connect_clicked => RunningInput::TogglePausePlotting,
set_active: model.plotting_paused,
set_cursor_from_name: Some("pointer"),
set_has_frame: false,
set_icon_name: icon_name::PAUSE,
set_icon_name: icon_names::PAUSE,
set_tooltip: &T.running_farmer_button_pause_plotting(),
},
},
Expand Down
16 changes: 8 additions & 8 deletions src/frontend/running/farm.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::backend::farmer::DiskFarm;
use crate::frontend::translations::{AsDefaultStr, T};
use crate::frontend::NotificationExt;
use crate::icon_names;
use bytesize::ByteSize;
use gtk::prelude::*;
use notify_rust::Notification;
use relm4::prelude::*;
use relm4_icons::icon_name;
use simple_moving_average::{SingleSumSMA, SMA};
use std::collections::HashMap;
use std::path::PathBuf;
Expand Down Expand Up @@ -177,7 +177,7 @@ impl FactoryComponent for FarmWidget {
set_hexpand: true,

gtk::Image {
set_icon_name: Some(icon_name::WARNING),
set_icon_name: Some(icon_names::WARNING),
}
},
None => {
Expand Down Expand Up @@ -215,9 +215,9 @@ impl FactoryComponent for FarmWidget {
gtk::Image {
#[track = "self.changed_proving_result() || self.changed_auditing_time_score() || self.changed_proving_time_score()"]
set_icon_name: Some(match self.farm_score() {
..=0.4 => icon_name::SPEEDOMETER4,
..=0.8 => icon_name::SPEEDOMETER3,
_ => icon_name::SPEEDOMETER2,
..=0.4 => icon_names::SPEEDOMETER4,
..=0.8 => icon_names::SPEEDOMETER3,
_ => icon_names::SPEEDOMETER2,
}),
},
},
Expand All @@ -235,7 +235,7 @@ impl FactoryComponent for FarmWidget {
set_visible: self.farm_details && self.auditing_time.get_num_samples() > 0,

gtk::Image {
set_icon_name: Some(icon_name::PUZZLE_PIECE),
set_icon_name: Some(icon_names::PUZZLE_PIECE),
},

gtk::LevelBar {
Expand All @@ -259,7 +259,7 @@ impl FactoryComponent for FarmWidget {
set_visible: self.farm_details && self.proving_time.get_num_samples() > 0,

gtk::Image {
set_icon_name: Some(icon_name::PROCESSOR),
set_icon_name: Some(icon_names::PROCESSOR),
},

gtk::LevelBar {
Expand All @@ -271,7 +271,7 @@ impl FactoryComponent for FarmWidget {
},

gtk::Image {
set_icon_name: Some(icon_name::WARNING),
set_icon_name: Some(icon_names::WARNING),
#[track = "self.changed_non_fatal_farming_error()"]
set_tooltip: {
let last_error = self.non_fatal_farming_error
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/running/node.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::backend::node::{ChainInfo, SyncState};
use crate::backend::NodeNotification;
use crate::frontend::translations::{AsDefaultStr, T};
use crate::icon_names;
use bytesize::ByteSize;
use gtk::prelude::*;
use parking_lot::Mutex;
use relm4::prelude::*;
use relm4::{Sender, ShutdownReceiver};
use relm4_icons::icon_name;
use simple_moving_average::{SingleSumSMA, SMA};
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Component for NodeView {
.unwrap_or_default(),

gtk::Image {
set_icon_name: Some(icon_name::SSD),
set_icon_name: Some(icon_names::SSD),
},

gtk::LevelBar {
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

mod backend;
mod frontend;
mod icon_names {
include!(concat!(env!("OUT_DIR"), "/icon_names.rs"));
}

use crate::frontend::{App, AppInit, RunBackendResult, GLOBAL_CSS};
use bytesize::ByteSize;
Expand Down Expand Up @@ -271,8 +274,9 @@ impl Cli {
args
});

app.set_global_css(GLOBAL_CSS);
relm4_icons::initialize_icons();
relm4::set_global_css(GLOBAL_CSS);

relm4_icons::initialize_icons(icon_names::GRESOURCE_BYTES, icon_names::RESOURCE_PREFIX);

// Prefer dark theme in cross-platform way if environment is configured that way
if let Some(settings) = gtk::Settings::default() {
Expand Down

0 comments on commit 40deff6

Please sign in to comment.