Skip to content

Commit

Permalink
Merge pull request #352 from autonomys/switch-to-LinkButton
Browse files Browse the repository at this point in the history
Switch to LinkButton
  • Loading branch information
nazar-pc authored Dec 6, 2024
2 parents 67f93e2 + f0e0f85 commit c9840fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 74 deletions.
50 changes: 13 additions & 37 deletions src/frontend/new_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use reqwest::Client;
use semver::Version;
use serde::Deserialize;
use std::time::Duration;
use tracing::{debug, error, warn};
use tracing::{debug, warn};

/// Check new release every hour
const NEW_VERSION_CHECK_INTERVAL: Duration = Duration::from_secs(3600);
Expand Down Expand Up @@ -38,54 +38,30 @@ impl Component for NewVersion {

view! {
#[root]
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
gtk::Button {
gtk::LinkButton {
add_css_class: "suggested-action",
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
connect_clicked => move |_| {
remove_css_class: "link",
set_has_frame: true,
#[track = "model.changed_new_version()"]
set_label: T
.new_version_available(
model.new_version.as_ref().map(Version::to_string).unwrap_or_default()
)
.as_str(),
set_tooltip: &T.new_version_available_button_open(),
set_uri: &{
let repository = env!("CARGO_PKG_REPOSITORY");

let link = if repository.starts_with("https://github.com") {
if repository.starts_with("https://github.com") {
// Turn:
// https://github.com/autonomys/space-acres
// Into:
// https://github.com/autonomys/space-acres/releases
format!("{}/releases", env!("CARGO_PKG_REPOSITORY"))
} else {
repository.to_string()
};

if let Err(error) = open::that_detached(link) {
error!(%error, "Failed to open releases page in default browser");
}
},
remove_css_class: "flat",
remove_css_class: "link",
remove_css_class: "text-button",
#[track = "model.changed_new_version()"]
set_label: T
.new_version_available(
model.new_version.as_ref().map(Version::to_string).unwrap_or_default()
)
.as_str(),
set_tooltip: &T.new_version_available_button_open(),
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
// set_uri: &{
// let repository = env!("CARGO_PKG_REPOSITORY");
//
// if repository.starts_with("https://github.com") {
// // Turn:
// // https://github.com/autonomys/space-acres
// // Into:
// // https://github.com/autonomys/space-acres/releases
// format!("{}/releases", env!("CARGO_PKG_REPOSITORY"))
// } else {
// repository.to_string()
// }
// },
set_use_underline: false,
#[track = "model.changed_new_version()"]
set_visible: model.new_version.is_some(),
Expand Down
24 changes: 4 additions & 20 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use subspace_farmer::farm::{
FarmingNotification, ProvingResult, SectorPlottingDetails, SectorUpdate,
};
use subspace_runtime_primitives::{Balance, SSC};
use tracing::{debug, error, warn};
use tracing::{debug, warn};

#[derive(Debug)]
pub struct RunningInit {
Expand All @@ -51,9 +51,6 @@ pub enum RunningInput {
FarmerNotification(FarmerNotification<FarmIndex>),
ToggleFarmDetails,
TogglePausePlotting,
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
OpenRewardAddressInExplorer,
}

#[derive(Debug)]
Expand Down Expand Up @@ -152,20 +149,12 @@ impl Component for RunningView {
model.farmer_state.reward_eta_progress_circle.widget().clone(),
},

// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
gtk::Button {
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
connect_clicked => RunningInput::OpenRewardAddressInExplorer,
gtk::LinkButton {
remove_css_class: "link",
set_cursor_from_name: Some("pointer"),
set_has_frame: false,
set_tooltip: &T.running_farmer_account_balance_tooltip(),
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
// #[watch]
// set_uri: &model.farmer_state.reward_address_url,
#[track = "model.farmer_state.changed_reward_address_url()"]
set_uri: &model.farmer_state.reward_address_url,
set_use_underline: false,

gtk::Label {
Expand Down Expand Up @@ -504,11 +493,6 @@ impl RunningView {
debug!("Failed to send RunningOutput::TogglePausePlotting");
}
}
RunningInput::OpenRewardAddressInExplorer => {
if let Err(error) = open::that_detached(&self.farmer_state.reward_address_url) {
error!(%error, "Failed to open explorer in default browser");
}
}
}
}

Expand Down
19 changes: 2 additions & 17 deletions src/frontend/running/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub enum NodeInput {
},
NodeNotification(NodeNotification),
OpenNodeFolder,
OpenP2pPortsDocs,
}

#[derive(Debug)]
Expand Down Expand Up @@ -125,10 +124,7 @@ impl Component for NodeView {
},
},

gtk::Button {
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
connect_clicked => NodeInput::OpenP2pPortsDocs,
gtk::LinkButton {
remove_css_class: "link",
set_cursor_from_name: Some("pointer"),
#[track = "model.changed_connected_peers()"]
Expand All @@ -140,18 +136,14 @@ impl Component for NodeView {
_ => "warning-label",
},
],
set_has_frame: false,
#[track = "model.changed_connected_peers()"]
set_tooltip: T
.running_node_connections_tooltip(
model.connected_peers,
IN_PEERS + OUT_PEERS,
)
.as_str(),
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
// #[watch]
// set_uri: "https://docs.autonomys.xyz/farming/guides/port-config",
set_uri: "https://docs.autonomys.xyz/farming/guides/port-config",
set_use_underline: false,

gtk::Box {
Expand Down Expand Up @@ -395,13 +387,6 @@ impl NodeView {
error!(%error, path = %node_path.display(), "Failed to open node folder");
}
}
NodeInput::OpenP2pPortsDocs => {
if let Err(error) =
open::that_detached("https://docs.autonomys.xyz/farming/guides/port-config")
{
error!(%error, "Failed to P2P ports docs");
}
}
}
}

Expand Down

0 comments on commit c9840fe

Please sign in to comment.