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

Fix opening links on macOS #216

Merged
merged 1 commit into from
Jul 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "space-acres"
description = "Space Acres is an opinionated GUI application for farming on Subspace Network"
license = "0BSD"
version = "0.1.25"
version = "0.1.26"
authors = ["Nazar Mokrynskyi <nazar@mokrynskyi.com>"]
repository = "https://github.com/subspace/space-acres"
edition = "2021"
Expand Down
49 changes: 36 additions & 13 deletions src/frontend/new_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reqwest::Client;
use semver::Version;
use serde::Deserialize;
use std::time::Duration;
use tracing::{debug, warn};
use tracing::{debug, error, warn};

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

view! {
#[root]
gtk::LinkButton {
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
gtk::Button {
add_css_class: "suggested-action",
remove_css_class: "flat",
remove_css_class: "link",
remove_css_class: "text-button",
#[watch]
set_label: &format!(
"Version {} available 🎉",
model.new_version.as_ref().map(Version::to_string).unwrap_or_default()
),
set_tooltip: "Open releases page",
set_uri: &{
// TODO: Use LinkButton once https://gitlab.gnome.org/GNOME/glib/-/issues/3403 is fixed
// for macOS
connect_clicked => move |_| {
let repository = env!("CARGO_PKG_REPOSITORY");

if repository.starts_with("https://github.com") {
let link = if repository.starts_with("https://github.com") {
// Turn:
// https://github.com/subspace/space-acres
// Into:
// https://github.com/subspace/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",
#[watch]
set_label: &format!(
"Version {} available 🎉",
model.new_version.as_ref().map(Version::to_string).unwrap_or_default()
),
set_tooltip: "Open releases page",
// 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/subspace/space-acres
// // Into:
// // https://github.com/subspace/space-acres/releases
// format!("{}/releases", env!("CARGO_PKG_REPOSITORY"))
// } else {
// repository.to_string()
// }
// },
set_use_underline: false,
#[watch]
set_visible: model.new_version.is_some(),
Expand Down
23 changes: 19 additions & 4 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use relm4::prelude::*;
use relm4_icons::icon_name;
use subspace_core_primitives::BlockNumber;
use subspace_runtime_primitives::{Balance, SSC};
use tracing::debug;
use tracing::{debug, error};

#[derive(Debug)]
pub struct RunningInit {
Expand All @@ -33,6 +33,9 @@ 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 @@ -107,11 +110,18 @@ impl Component for RunningView {
set_halign: gtk::Align::End,
set_hexpand: true,

gtk::LinkButton {
// 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,
remove_css_class: "link",
set_tooltip: "Total account balance and coins farmed since application started, click to see details in Astral",
#[watch]
set_uri: &model.farmer_state.reward_address_url,
// 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,
set_use_underline: false,

gtk::Label {
Expand Down Expand Up @@ -345,6 +355,11 @@ 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");
}
}
}
}
}
Loading