mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-04 07:24:17 +00:00
update home button status detection
This commit is contained in:
parent
c5fad47a20
commit
5943ea622a
@ -42,7 +42,7 @@ impl Navigation {
|
||||
let reload = Rc::new(Reload::build(window_action));
|
||||
let request = Rc::new(Request::build((browser_action, tab_action)));
|
||||
let bookmark = Rc::new(Bookmark::build(window_action));
|
||||
let home = Rc::new(Home::build(window_action, &request));
|
||||
let home = Rc::new(Home::build(window_action));
|
||||
|
||||
// init main widget
|
||||
let widget = Rc::new(Widget::build(
|
||||
@ -76,9 +76,17 @@ impl Navigation {
|
||||
.update(self.profile.bookmark.get(&request).is_ok());
|
||||
self.history.update();
|
||||
self.reload.update(!request.is_empty());
|
||||
self.request
|
||||
.update(self.profile.identity.get(&request).is_some());
|
||||
self.home.update();
|
||||
self.request.update(
|
||||
self.profile
|
||||
.identity
|
||||
.get(&self.request.strip_prefix())
|
||||
.is_some(),
|
||||
);
|
||||
self.home.update(
|
||||
self.request
|
||||
.home()
|
||||
.is_some_and(|home| home.to_string() != request),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::{Request, WindowAction};
|
||||
use super::WindowAction;
|
||||
use gtk::{
|
||||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
@ -7,13 +7,12 @@ use std::rc::Rc;
|
||||
|
||||
pub struct Home {
|
||||
action: Rc<WindowAction>,
|
||||
request: Rc<Request>,
|
||||
pub button: Button,
|
||||
}
|
||||
|
||||
impl Home {
|
||||
// Construct
|
||||
pub fn build(action: &Rc<WindowAction>, request: &Rc<Request>) -> Self {
|
||||
pub fn build(action: &Rc<WindowAction>) -> Self {
|
||||
// Init gobject
|
||||
let button = Button::builder()
|
||||
.icon_name("go-home-symbolic")
|
||||
@ -30,14 +29,12 @@ impl Home {
|
||||
// Return activated `Self`
|
||||
Self {
|
||||
action: action.clone(),
|
||||
request: request.clone(),
|
||||
button,
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self) {
|
||||
let has_home = self.request.home().is_some();
|
||||
pub fn update(&self, has_home: bool) {
|
||||
self.action.home.simple_action.set_enabled(has_home);
|
||||
self.button.set_sensitive(has_home);
|
||||
}
|
||||
|
@ -119,20 +119,19 @@ impl Request {
|
||||
strip_prefix(self.widget.entry.text())
|
||||
}
|
||||
|
||||
/// Parse home [Uri](https://docs.gtk.org/glib/struct.Uri.html) for self
|
||||
pub fn home(&self) -> Option<GString> {
|
||||
/// Parse home [Uri](https://docs.gtk.org/glib/struct.Uri.html) of `Self`
|
||||
pub fn home(&self) -> Option<Uri> {
|
||||
match self.uri() {
|
||||
Some(uri) => {
|
||||
let scheme = uri.scheme().replace("titan", "gemini");
|
||||
let port = uri.port();
|
||||
uri.host().map(|host| {
|
||||
if port.is_positive() {
|
||||
gformat!("{scheme}://{host}:{port}/")
|
||||
} else {
|
||||
gformat!("{scheme}://{host}/")
|
||||
}
|
||||
})
|
||||
}
|
||||
Some(uri) => Some(Uri::build(
|
||||
UriFlags::NONE,
|
||||
&uri.scheme(),
|
||||
uri.userinfo().as_deref(),
|
||||
uri.host().as_deref(),
|
||||
uri.port(),
|
||||
"/",
|
||||
None,
|
||||
None,
|
||||
)),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user