mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
move common handler features to the parent level
This commit is contained in:
parent
025899ba68
commit
133d0f39f2
2 changed files with 65 additions and 73 deletions
|
|
@ -9,7 +9,7 @@ use feature::Feature;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::Cancellable,
|
gio::Cancellable,
|
||||||
glib::{Uri, UriFlags},
|
glib::{Uri, UriFlags},
|
||||||
prelude::{CancellableExt, EntryExt},
|
prelude::{CancellableExt, EditableExt, EntryExt},
|
||||||
};
|
};
|
||||||
use std::{cell::Cell, rc::Rc};
|
use std::{cell::Cell, rc::Rc};
|
||||||
use subject::Subject;
|
use subject::Subject;
|
||||||
|
|
@ -43,16 +43,47 @@ impl Client {
|
||||||
/// Route tab item `request` to protocol driver
|
/// Route tab item `request` to protocol driver
|
||||||
/// * or `navigation` entry if the value not provided
|
/// * or `navigation` entry if the value not provided
|
||||||
pub fn handle(&self, request: &str, is_snap_history: bool) {
|
pub fn handle(&self, request: &str, is_snap_history: bool) {
|
||||||
|
// Move focus out from navigation entry
|
||||||
|
self.subject
|
||||||
|
.page
|
||||||
|
.browser_action
|
||||||
|
.escape
|
||||||
|
.activate_stateful_once(Some(self.subject.page.id.as_str().into()));
|
||||||
|
|
||||||
|
// Initially disable find action
|
||||||
|
self.subject
|
||||||
|
.page
|
||||||
|
.window_action
|
||||||
|
.find
|
||||||
|
.simple_action
|
||||||
|
.set_enabled(false);
|
||||||
|
|
||||||
|
// Reset widgets
|
||||||
|
self.subject.page.search.unset();
|
||||||
|
self.subject.page.input.unset();
|
||||||
|
self.subject.page.title.replace("Loading..".into());
|
||||||
|
self.subject
|
||||||
|
.page
|
||||||
|
.navigation
|
||||||
|
.request
|
||||||
|
.widget
|
||||||
|
.entry
|
||||||
|
.set_progress_fraction(0.1);
|
||||||
|
|
||||||
|
self.subject.tab_page.set_loading(true);
|
||||||
|
|
||||||
|
if is_snap_history {
|
||||||
|
snap_history(&self.subject, None);
|
||||||
|
}
|
||||||
|
|
||||||
// run async resolver to detect Uri, scheme-less host, or search query
|
// run async resolver to detect Uri, scheme-less host, or search query
|
||||||
lookup(request, self.cancellable(), {
|
lookup(request, self.cancellable(), {
|
||||||
let driver = self.driver.clone();
|
let driver = self.driver.clone();
|
||||||
let subject = self.subject.clone();
|
let subject = self.subject.clone();
|
||||||
move |feature, cancellable, result| match result {
|
move |feature, cancellable, result| match result {
|
||||||
// route by scheme parsed
|
// route by scheme
|
||||||
Ok(uri) => match uri.scheme().as_str() {
|
Ok(uri) => match uri.scheme().as_str() {
|
||||||
"gemini" => driver
|
"gemini" => driver.gemini.handle(uri, feature, cancellable),
|
||||||
.gemini
|
|
||||||
.handle(uri, feature, cancellable, is_snap_history),
|
|
||||||
scheme => {
|
scheme => {
|
||||||
// no scheme match driver, complete with failure message
|
// no scheme match driver, complete with failure message
|
||||||
let status = subject.page.content.to_status_failure();
|
let status = subject.page.content.to_status_failure();
|
||||||
|
|
@ -160,3 +191,30 @@ fn search(query: &str) -> Uri {
|
||||||
None,
|
None,
|
||||||
) // @TODO optional settings
|
) // @TODO optional settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Make new history record in related components
|
||||||
|
/// * optional [Uri](https://docs.gtk.org/glib/struct.Uri.html) reference wanted only for performance reasons, to not parse it twice
|
||||||
|
fn snap_history(subject: &Rc<Subject>, uri: Option<&Uri>) {
|
||||||
|
let request = subject.page.navigation.request.widget.entry.text();
|
||||||
|
|
||||||
|
// Add new record into the global memory index (used in global menu)
|
||||||
|
// * if the `Uri` is `None`, try parse it from `request`
|
||||||
|
match uri {
|
||||||
|
Some(uri) => subject.page.profile.history.memory.request.set(uri.clone()),
|
||||||
|
None => {
|
||||||
|
// this case especially useful for some routes that contain redirects
|
||||||
|
// maybe some parental optimization wanted @TODO
|
||||||
|
if let Some(uri) = subject.page.navigation.request.as_uri() {
|
||||||
|
subject.page.profile.history.memory.request.set(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new record into the page navigation history
|
||||||
|
if match subject.page.navigation.history.current() {
|
||||||
|
Some(current) => current != request, // apply additional filters
|
||||||
|
None => true,
|
||||||
|
} {
|
||||||
|
subject.page.navigation.history.add(request, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,46 +72,7 @@ impl Gemini {
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
pub fn handle(
|
pub fn handle(&self, uri: Uri, feature: Feature, cancellable: Cancellable) {
|
||||||
&self,
|
|
||||||
uri: Uri,
|
|
||||||
feature: Feature,
|
|
||||||
cancellable: Cancellable,
|
|
||||||
is_snap_history: bool,
|
|
||||||
) {
|
|
||||||
// Move focus out from navigation entry
|
|
||||||
self.subject
|
|
||||||
.page
|
|
||||||
.browser_action
|
|
||||||
.escape
|
|
||||||
.activate_stateful_once(Some(self.subject.page.id.as_str().into()));
|
|
||||||
|
|
||||||
// Initially disable find action
|
|
||||||
self.subject
|
|
||||||
.page
|
|
||||||
.window_action
|
|
||||||
.find
|
|
||||||
.simple_action
|
|
||||||
.set_enabled(false);
|
|
||||||
|
|
||||||
// Reset widgets
|
|
||||||
self.subject.page.search.unset();
|
|
||||||
self.subject.page.input.unset();
|
|
||||||
self.subject.page.title.replace("Loading..".into());
|
|
||||||
self.subject
|
|
||||||
.page
|
|
||||||
.navigation
|
|
||||||
.request
|
|
||||||
.widget
|
|
||||||
.entry
|
|
||||||
.set_progress_fraction(0.1);
|
|
||||||
|
|
||||||
self.subject.tab_page.set_loading(true);
|
|
||||||
|
|
||||||
if is_snap_history {
|
|
||||||
snap_history(&self.subject, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.client.request_async(
|
self.client.request_async(
|
||||||
Request::gemini(uri.clone()),
|
Request::gemini(uri.clone()),
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
|
|
@ -392,7 +353,7 @@ impl Gemini {
|
||||||
.set_text(&uri.to_string());
|
.set_text(&uri.to_string());
|
||||||
}
|
}
|
||||||
redirects.replace(total);
|
redirects.replace(total);
|
||||||
subject.page.tab_action.load.activate(Some(&target.to_string()), is_snap_history);
|
subject.page.tab_action.load.activate(Some(&target.to_string()), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -459,30 +420,3 @@ fn uri_to_title(uri: &Uri) -> GString {
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make new history record in related components
|
|
||||||
/// * optional [Uri](https://docs.gtk.org/glib/struct.Uri.html) reference wanted only for performance reasons, to not parse it twice
|
|
||||||
fn snap_history(subject: &Rc<Subject>, uri: Option<&Uri>) {
|
|
||||||
let request = subject.page.navigation.request.widget.entry.text();
|
|
||||||
|
|
||||||
// Add new record into the global memory index (used in global menu)
|
|
||||||
// * if the `Uri` is `None`, try parse it from `request`
|
|
||||||
match uri {
|
|
||||||
Some(uri) => subject.page.profile.history.memory.request.set(uri.clone()),
|
|
||||||
None => {
|
|
||||||
// this case especially useful for some routes that contain redirects
|
|
||||||
// maybe some parental optimization wanted @TODO
|
|
||||||
if let Some(uri) = subject.page.navigation.request.as_uri() {
|
|
||||||
subject.page.profile.history.memory.request.set(uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new record into the page navigation history
|
|
||||||
if match subject.page.navigation.history.current() {
|
|
||||||
Some(current) => current != request, // apply additional filters
|
|
||||||
None => true,
|
|
||||||
} {
|
|
||||||
subject.page.navigation.history.add(request, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue