feat: added warning on clicking cosmetics button (#899)
This commit is contained in:
parent
efbde53326
commit
76d929b82a
2 changed files with 27 additions and 4 deletions
|
|
@ -18,6 +18,17 @@ impl Component for ConfirmLinkOverlay {
|
|||
};
|
||||
|
||||
let open_url = url.clone();
|
||||
let (title, body) = if is_first_party(&url) {
|
||||
(
|
||||
"Leave the launcher?",
|
||||
"This will open the page in your web browser.",
|
||||
)
|
||||
} else {
|
||||
(
|
||||
"Open external link?",
|
||||
"This link was provided by a third party. Only open it if you trust the source.",
|
||||
)
|
||||
};
|
||||
|
||||
OverlayPopup::new()
|
||||
.overlay_level(OVERLAY_BASE_LEVEL + 3)
|
||||
|
|
@ -49,7 +60,7 @@ impl Component for ConfirmLinkOverlay {
|
|||
)
|
||||
.child(
|
||||
label()
|
||||
.text("Open external link?")
|
||||
.text(title)
|
||||
.font_size(16.)
|
||||
.font_weight(FontWeight::SEMI_BOLD)
|
||||
.color(colors::fg_primary()),
|
||||
|
|
@ -57,7 +68,7 @@ impl Component for ConfirmLinkOverlay {
|
|||
)
|
||||
.child(
|
||||
label()
|
||||
.text("This link was provided by a third party. Only open it if you trust the source.")
|
||||
.text(body)
|
||||
.font_size(12.)
|
||||
.color(colors::fg_secondary()),
|
||||
)
|
||||
|
|
@ -105,3 +116,13 @@ impl Component for ConfirmLinkOverlay {
|
|||
.into_element()
|
||||
}
|
||||
}
|
||||
|
||||
fn is_first_party(url: &str) -> bool {
|
||||
let host = url
|
||||
.split_once("://")
|
||||
.map_or(url, |(_, rest)| rest)
|
||||
.split(['/', '?', '#', ':'])
|
||||
.next()
|
||||
.unwrap_or_default();
|
||||
host == "polyfrost.org" || host.ends_with(".polyfrost.org")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ use crate::{
|
|||
components::{Avatar, Icon, IconType},
|
||||
hooks::{
|
||||
settled_or_loading, try_default_account, use_active_cluster_id, use_browser_type,
|
||||
use_clusters, use_current_account, use_dispatch, use_notifications_snapshot,
|
||||
use_clusters, use_current_account, use_dispatch, use_link_confirm,
|
||||
use_notifications_snapshot,
|
||||
},
|
||||
theme,
|
||||
utils::default_cluster,
|
||||
|
|
@ -185,6 +186,7 @@ impl Component for NavLink {
|
|||
let mut hovering = use_state(|| false);
|
||||
let a11y_id = use_a11y();
|
||||
let focused = use_focus(a11y_id);
|
||||
let mut confirm_link = use_link_confirm();
|
||||
|
||||
let active = self.active;
|
||||
let target = self.target.clone();
|
||||
|
|
@ -229,7 +231,7 @@ impl Component for NavLink {
|
|||
NavTarget::Route(route) => {
|
||||
let _ = RouterContext::get().push(route.clone());
|
||||
}
|
||||
NavTarget::External(url) => crate::platform::open_url(url),
|
||||
NavTarget::External(url) => confirm_link.set(Some((*url).to_string())),
|
||||
}
|
||||
})
|
||||
.on_pointer_over(move |_| hovering.set(true))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue