fix home button status detection

This commit is contained in:
yggverse 2024-12-13 02:52:26 +02:00
parent 27f778e231
commit d08c2fed29
3 changed files with 32 additions and 26 deletions

View File

@ -17,7 +17,6 @@ use crate::app::browser::window::tab::item::Action as TabAction;
use crate::app::browser::window::Action as WindowAction; use crate::app::browser::window::Action as WindowAction;
use crate::app::browser::Action as BrowserAction; use crate::app::browser::Action as BrowserAction;
use crate::Profile; use crate::Profile;
use gtk::prelude::EditableExt;
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::rc::Rc;
@ -36,14 +35,14 @@ impl Navigation {
profile: Rc<Profile>, profile: Rc<Profile>,
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>), action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>),
) -> Self { ) -> Self {
// Init components // init children components
let home = Rc::new(Home::new(action.1.clone())); let home = Rc::new(Home::new(action.1.clone()));
let history = Rc::new(History::new(action.1.clone())); let history = Rc::new(History::new(action.1.clone()));
let reload = Rc::new(Reload::new(action.1.clone())); let reload = Rc::new(Reload::new(action.1.clone()));
let request = Rc::new(Request::new((action.0, action.2))); let request = Rc::new(Request::new((action.0, action.2)));
let bookmark = Rc::new(Bookmark::new(action.1)); let bookmark = Rc::new(Bookmark::new(action.1));
// Init widget // init main widget
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(
&home.widget.gobject, &home.widget.gobject,
&history.widget.gobject, &history.widget.gobject,
@ -52,7 +51,7 @@ impl Navigation {
&bookmark.widget.gobject, &bookmark.widget.gobject,
)); ));
// Done // done
Self { Self {
bookmark, bookmark,
history, history,
@ -67,13 +66,15 @@ impl Navigation {
// Actions // Actions
pub fn update(&self, progress_fraction: Option<f64>) { pub fn update(&self, progress_fraction: Option<f64>) {
let request_text = self.request.widget.entry.text(); // init shared request value
let request = self.request.strip_prefix();
// update children components
self.bookmark self.bookmark
.update(self.profile.bookmark.get(&request_text).is_ok()); .update(self.profile.bookmark.get(&request).is_ok());
self.history.update(); self.history.update();
self.home.update(&request_text); self.home.update(self.request.uri().as_ref());
self.reload.update(!request_text.is_empty()); self.reload.update(!request.is_empty());
self.request.update( self.request.update(
progress_fraction, progress_fraction,
self.profile self.profile
@ -81,7 +82,7 @@ impl Navigation {
.gemini .gemini
.auth .auth
.memory .memory
.match_scope(&request_text) .match_scope(&request)
.is_some(), .is_some(),
); );
} }

View File

@ -3,7 +3,7 @@ mod widget;
use widget::Widget; use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction; use crate::app::browser::window::action::Action as WindowAction;
use gtk::glib::{gformat, GString, Uri, UriFlags}; use gtk::glib::{gformat, GString, Uri};
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
pub struct Home { pub struct Home {
@ -23,13 +23,13 @@ impl Home {
} }
// Actions // Actions
pub fn update(&self, request: &str) { pub fn update(&self, request: Option<&Uri>) {
let has_home = match Uri::parse(request, UriFlags::NONE) { let has_home = match request {
Ok(uri) => { Some(uri) => {
self.uri.replace(Some(uri.clone())); self.uri.replace(Some(uri.clone()));
uri.path().len() > 1 uri.path().len() > 1
} }
_ => { None => {
self.uri.replace(None); self.uri.replace(None);
false false
} }

View File

@ -124,8 +124,9 @@ impl Request {
// Getters // Getters
/// Get current request value in [Uri](https://docs.gtk.org/glib/struct.Uri.html) format /// Get current request value in [Uri](https://docs.gtk.org/glib/struct.Uri.html) format
/// * `strip_prefix` on parse
pub fn uri(&self) -> Option<Uri> { pub fn uri(&self) -> Option<Uri> {
match Uri::parse(&self.widget.entry.text(), UriFlags::NONE) { match Uri::parse(&strip_prefix(self.widget.entry.text()), UriFlags::NONE) {
Ok(uri) => Some(uri), Ok(uri) => Some(uri),
_ => None, _ => None,
} }
@ -134,17 +135,7 @@ impl Request {
/// Get current request value without system prefix /// Get current request value without system prefix
/// * the `prefix` is not `scheme` /// * the `prefix` is not `scheme`
pub fn strip_prefix(&self) -> GString { pub fn strip_prefix(&self) -> GString {
let mut text = self.widget.entry.text(); strip_prefix(self.widget.entry.text())
if let Some(postfix) = text.strip_prefix("source:") {
text = postfix.into()
};
if let Some(postfix) = text.strip_prefix("download:") {
text = postfix.into()
};
text
} }
/// Get request value in `download:` format /// Get request value in `download:` format
@ -188,6 +179,20 @@ impl Request {
// Tools // Tools
/// Strip system prefix from request string
/// * the `prefix` is not `scheme`
pub fn strip_prefix(mut request: GString) -> GString {
if let Some(postfix) = request.strip_prefix("source:") {
request = postfix.into()
};
if let Some(postfix) = request.strip_prefix("download:") {
request = postfix.into()
};
request
}
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = database::init(tx) { if let Err(e) = database::init(tx) {