mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
implement cancelable move, close connection on reload complete
This commit is contained in:
parent
60574ae449
commit
f9296265ab
@ -92,6 +92,7 @@ impl Page {
|
|||||||
let _ = widget.activate_action("win.update", None);
|
let _ = widget.activate_action("win.update", None);
|
||||||
|
|
||||||
// Create new connection
|
// Create new connection
|
||||||
|
let cancellable = Cancellable::new();
|
||||||
let client = SocketClient::new();
|
let client = SocketClient::new();
|
||||||
|
|
||||||
client.set_timeout(10);
|
client.set_timeout(10);
|
||||||
@ -102,7 +103,7 @@ impl Page {
|
|||||||
client.connect_to_uri_async(
|
client.connect_to_uri_async(
|
||||||
"gemini://geminiprotocol.net:1965/", // @TODO &uri.to_str(),
|
"gemini://geminiprotocol.net:1965/", // @TODO &uri.to_str(),
|
||||||
1965,
|
1965,
|
||||||
Some(&Cancellable::new()),
|
Some(&cancellable.clone()),
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok(connection) => {
|
Ok(connection) => {
|
||||||
// Update
|
// Update
|
||||||
@ -115,7 +116,7 @@ impl Page {
|
|||||||
connection.output_stream().write_all_async(
|
connection.output_stream().write_all_async(
|
||||||
"gemini://geminiprotocol.net:1965/\r\n", // @TODO
|
"gemini://geminiprotocol.net:1965/\r\n", // @TODO
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Some(&Cancellable::new()),
|
Some(&cancellable.clone()),
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Update
|
// Update
|
||||||
@ -128,7 +129,7 @@ impl Page {
|
|||||||
connection.input_stream().read_all_async(
|
connection.input_stream().read_all_async(
|
||||||
vec![0; 0xfffff], // 1Mb @TODO
|
vec![0; 0xfffff], // 1Mb @TODO
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Some(&Cancellable::new()),
|
Some(&cancellable.clone()),
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match GString::from_utf8_until_nul(
|
match GString::from_utf8_until_nul(
|
||||||
@ -191,19 +192,32 @@ impl Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO connection.close(cancellable);
|
// Close connection
|
||||||
|
if let Err(e) = connection.close(Some(&cancellable)) {
|
||||||
|
eprintln!("Error closing connection: {:?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Failed to read response: {:?}",
|
"Failed to read response: {:?}",
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Close connection
|
||||||
|
if let Err(e) = connection.close(Some(&cancellable)) {
|
||||||
|
eprintln!("Error closing connection: {:?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to write request: {:?}", e);
|
eprintln!("Failed to write request: {:?}", e);
|
||||||
|
|
||||||
|
// Close connection
|
||||||
|
if let Err(e) = connection.close(Some(&cancellable)) {
|
||||||
|
eprintln!("Error closing connection: {:?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user