make arc pointer on construct, draft meta update steps

This commit is contained in:
yggverse 2024-09-25 22:52:41 +03:00
parent 597e472154
commit 4608d96eff

View File

@ -42,7 +42,7 @@ pub struct Page {
impl Page { impl Page {
// Construct // Construct
pub fn new(name: GString) -> Page { pub fn new(name: GString) -> Arc<Page> {
// Init components // Init components
let content = Content::new(); let content = Content::new();
let navigation = Navigation::new(); let navigation = Navigation::new();
@ -65,12 +65,12 @@ impl Page {
}); });
// Result // Result
Self { Arc::new(Self {
widget, widget,
content, content,
navigation, navigation,
meta, meta,
} })
} }
// Actions // Actions
@ -95,6 +95,14 @@ impl Page {
todo!() todo!()
} }
"gemini" => { "gemini" => {
// Update
self.meta.borrow_mut().title = GString::from("Connect");
//self.meta.borrow_mut().description = uri.host();
self.meta.borrow_mut().progress_fraction = 0.25;
let _ = self.widget.activate_action("win.update", None);
// Create new connection
let client = SocketClient::new(); let client = SocketClient::new();
client.set_timeout(10); client.set_timeout(10);
@ -108,12 +116,26 @@ impl Page {
Some(&Cancellable::new()), Some(&Cancellable::new()),
move |result| match result { move |result| match result {
Ok(connection) => { Ok(connection) => {
// Update
//self.meta.borrow_mut().title = GString::from("Request");
//self.meta.borrow_mut().progress_fraction = 0.50;
//let _ = self.widget.activate_action("win.update", None);
// Send request
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::new()),
move |result| match result { move |result| match result {
Ok(_) => { Ok(_) => {
// Update
//self.meta.borrow_mut().title = GString::from("Response");
//self.meta.borrow_mut().progress_fraction = 0.75;
//let _ = self.widget.activate_action("win.update", None);
// Read response
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,
@ -124,6 +146,12 @@ impl Page {
response.0, response.0,
) { ) {
Ok(data) => { Ok(data) => {
// Update
//self.meta.borrow_mut().title = GString::from("Done"); // @TODO
//self.meta.borrow_mut().progress_fraction = 1.0;
//let _ = self.widget.activate_action("win.update", None);
// Detect page meta // Detect page meta
let meta = Regex::split_simple( let meta = Regex::split_simple(
r"^(\d+)?\s([\w]+\/[\w]+)?", r"^(\d+)?\s([\w]+\/[\w]+)?",