mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-08-26 14:32:26 +00:00
use previously constructed ProxyResolver
object (prevent extra search operations)
This commit is contained in:
parent
1cbcd72c71
commit
b548fb16d3
@ -162,7 +162,7 @@ fn handle(
|
|||||||
|
|
||||||
this.client
|
this.client
|
||||||
.socket
|
.socket
|
||||||
.set_proxy_resolver(this.page.profile.proxy.matches(&url).as_ref());
|
.set_proxy_resolver(this.page.navigation.request.proxy_resolver().as_ref());
|
||||||
|
|
||||||
this.client.request_async(
|
this.client.request_async(
|
||||||
request,
|
request,
|
||||||
|
@ -69,7 +69,7 @@ impl Nex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let socket = SocketClient::new();
|
let socket = SocketClient::new();
|
||||||
socket.set_proxy_resolver(self.page.profile.proxy.matches(&url).as_ref());
|
socket.set_proxy_resolver(self.page.navigation.request.proxy_resolver().as_ref());
|
||||||
socket.set_protocol(SocketProtocol::Tcp);
|
socket.set_protocol(SocketProtocol::Tcp);
|
||||||
socket.set_timeout(30); // @TODO optional
|
socket.set_timeout(30); // @TODO optional
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use adw::{AlertDialog, prelude::AdwDialogExt};
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
Entry, EntryIconPosition, StateFlags,
|
Entry, EntryIconPosition, StateFlags,
|
||||||
gio::Cancellable,
|
gio::{Cancellable, ProxyResolver},
|
||||||
glib::{GString, Uri, UriFlags, gformat},
|
glib::{GString, Uri, UriFlags, gformat},
|
||||||
prelude::{EditableExt, EntryExt, ProxyResolverExt, WidgetExt},
|
prelude::{EditableExt, EntryExt, ProxyResolverExt, WidgetExt},
|
||||||
};
|
};
|
||||||
@ -29,8 +29,9 @@ const PREFIX_SOURCE: &str = "source:";
|
|||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub entry: Entry,
|
pub entry: Entry,
|
||||||
pub info: Rc<RefCell<Info>>,
|
pub info: Rc<RefCell<Info>>,
|
||||||
suggestion: Rc<Suggestion>,
|
|
||||||
profile: Rc<Profile>,
|
profile: Rc<Profile>,
|
||||||
|
proxy_resolver: Rc<RefCell<Option<ProxyResolver>>>,
|
||||||
|
suggestion: Rc<Suggestion>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
@ -40,6 +41,7 @@ impl Request {
|
|||||||
pub fn build(item_action: &Rc<ItemAction>, profile: &Rc<Profile>) -> Self {
|
pub fn build(item_action: &Rc<ItemAction>, profile: &Rc<Profile>) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
let info = Rc::new(RefCell::new(Info::new()));
|
let info = Rc::new(RefCell::new(Info::new()));
|
||||||
|
let proxy_resolver = Rc::new(RefCell::new(None));
|
||||||
|
|
||||||
// Init main widget
|
// Init main widget
|
||||||
let entry = Entry::builder()
|
let entry = Entry::builder()
|
||||||
@ -124,6 +126,7 @@ impl Request {
|
|||||||
let a = item_action.clone();
|
let a = item_action.clone();
|
||||||
let i = info.clone();
|
let i = info.clone();
|
||||||
let p = profile.clone();
|
let p = profile.clone();
|
||||||
|
let r = proxy_resolver.clone();
|
||||||
let s = suggestion.clone();
|
let s = suggestion.clone();
|
||||||
move |e| {
|
move |e| {
|
||||||
// Allocate once
|
// Allocate once
|
||||||
@ -140,11 +143,13 @@ impl Request {
|
|||||||
}
|
}
|
||||||
// Indicate proxy connections @TODO cancel previous operation on update
|
// Indicate proxy connections @TODO cancel previous operation on update
|
||||||
match p.proxy.matches(&t) {
|
match p.proxy.matches(&t) {
|
||||||
Some(r) => r.lookup_async(&t, Cancellable::NONE, {
|
Some(m) => m.clone().lookup_async(&t, Cancellable::NONE, {
|
||||||
let e = e.clone();
|
let e = e.clone();
|
||||||
move |r| {
|
let r = r.clone();
|
||||||
|
move |l| {
|
||||||
|
r.replace(Some(m));
|
||||||
e.set_tooltip_text(Some(&{
|
e.set_tooltip_text(Some(&{
|
||||||
match r {
|
match l {
|
||||||
Ok(h) => {
|
Ok(h) => {
|
||||||
e.set_css_classes(&["accent"]);
|
e.set_css_classes(&["accent"]);
|
||||||
format!("Proxy over {}", h.join(","))
|
format!("Proxy over {}", h.join(","))
|
||||||
@ -208,8 +213,9 @@ impl Request {
|
|||||||
Self {
|
Self {
|
||||||
entry,
|
entry,
|
||||||
info,
|
info,
|
||||||
suggestion,
|
|
||||||
profile: profile.clone(),
|
profile: profile.clone(),
|
||||||
|
proxy_resolver,
|
||||||
|
suggestion,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,6 +311,14 @@ impl Request {
|
|||||||
self.entry.text().starts_with("file://")
|
self.entry.text().starts_with("file://")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get [ProxyResolver](https://docs.gtk.org/gio/iface.ProxyResolver.html)
|
||||||
|
/// which is constructed for every `Request` entry change
|
||||||
|
/// * useful on build new [SocketClient](https://docs.gtk.org/gio/class.SocketClient.html)
|
||||||
|
/// to prevent double search / construct operations
|
||||||
|
pub fn proxy_resolver(&self) -> Option<ProxyResolver> {
|
||||||
|
self.proxy_resolver.borrow().clone()
|
||||||
|
}
|
||||||
|
|
||||||
// Tools
|
// Tools
|
||||||
|
|
||||||
/// Get request value with formatted `download` prefix
|
/// Get request value with formatted `download` prefix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user