Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to LinkButton #352

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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