[PATCH 1/2] Fix crash when Gemini response is missing CLRF
Export this patch
Not sure why this happens, it may be a server bug or issue with the content that I was testing with.
---
src/gemini/client.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/gemini/client.rs b/src/gemini/client.rs
index d62e5d8..7b8ae46 100644
--- a/src/gemini/client.rs
+++ b/src/gemini/client.rs
@@ -49,6 +49,11 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
stream.read_to_end(&mut res).unwrap();
let clrf_idx = find_clrf(&res);
+
+ if clrf_idx.is_none() {
+ return Err(format!("Failed to read response (missing clrf)"));
+ }
+
let content = res.split_off(clrf_idx.unwrap() + 2);
Ok((Some(res), content))
--
2.25.1
[PATCH 2/2] Add refresh button (and shortcut)
Export this patch
Adds a refresh button after the back button, uses ctrl-r as shortcut key.
---
src/castor.glade | 33 +++++++++++++++++++++++++++++ ----
src/gui.rs | 9 +++++++++
src/main.rs | 15 +++++++++++++++
3 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/src/castor.glade b/src/castor.glade
index 8528661..b1be5fb 100644
--- a/src/castor.glade
+++ b/src/castor.glade
@@ -21,6 +21,11 @@
<property name="can_focus">False</property>
<property name="stock">gtk-go-back</property>
</object>
+ <object class="GtkImage" id="image4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-refresh</property>
+ </object>
<object class="GtkApplicationWindow" id="window">
<property name="name">window</property>
<property name="can_focus">False</property>
@@ -48,7 +53,6 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Go back</property>
<property name="margin_left">6</property>
- <property name="margin_right">1</property>
<property name="margin_top">15</property>
<property name="margin_bottom">15</property>
<property name="image">image3</property>
@@ -63,6 +67,27 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkButton" id="refresh_button">
+ <property name="name">refresh_button</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Refresh</property>
+ <property name="margin_right">1</property>
+ <property name="margin_top">15</property>
+ <property name="margin_bottom">15</property>
+ <property name="image">image4</property>
+ <property name="always_show_image">True</property>
+ <accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="padding">1</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
<child>
<object class="GtkButton" id="add_bookmark_button">
<property name="name">add_bookmark_button</property>
@@ -80,7 +105,7 @@
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">1</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
@@ -98,7 +123,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -117,7 +142,7 @@
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">1</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
</object>
diff --git a/src/gui.rs b/src/gui.rs
index 016bc98..eb26e1e 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -8,6 +8,7 @@ pub struct Gui {
url_bar: Entry,
content_view: TextView,
back_button: Button,
+ refresh_button: Button,
add_bookmark_button: Button,
show_bookmarks_button: Button,
}
@@ -33,6 +34,9 @@ impl Gui {
let back_button: Button = builder
.get_object("back_button")
.expect("Couldn't get back_button");
+ let refresh_button: Button = builder
+ .get_object("refresh_button")
+ .expect("Couldn't get refresh_button");
let add_bookmark_button: Button = builder
.get_object("add_bookmark_button")
.expect("Couldn't get add_bookmark_button");
@@ -45,6 +49,7 @@ impl Gui {
url_bar,
content_view,
back_button,
+ refresh_button,
add_bookmark_button,
show_bookmarks_button,
}
@@ -81,6 +86,10 @@ impl Gui {
&self.back_button
}
+ pub fn refresh_button(&self) -> &Button {
+ &self.refresh_button
+ }
+
pub fn add_bookmark_button(&self) -> &Button {
&self.add_bookmark_button
}
diff --git a/src/main.rs b/src/main.rs
index 2f38307..456836f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -60,6 +60,15 @@ fn main() {
});
}
+ // Bind refresh button
+ {
+ let button = gui.refresh_button();
+ let gui = gui.clone();
+ button.connect_clicked(move |_| {
+ refresh(&gui);
+ });
+ }
+
// Bind add_bookmark button
{
let button = gui.add_bookmark_button();
@@ -162,6 +171,12 @@ fn go_back(gui: &Arc<Gui>) {
}
}
+ fn refresh(gui: &Arc<Gui>) {
+ let url_bar = gui.url_bar();
+ let url = url_bar.get_text().expect("get_text failed").to_string();
+ route_url(&gui, url)
+ }
+
fn update_url_field(gui: &Arc<Gui>, url: &str) {
let url_bar = gui.url_bar();
url_bar.get_buffer().set_text(url);
--
2.25.1
Thanks a lot!