Skip to content

Commit

Permalink
Merge pull request #119 from ranfdev/Virtual-branch
Browse files Browse the repository at this point in the history
Upgrade to gnome 47 sdk
  • Loading branch information
ranfdev authored Sep 26, 2024
2 parents 19bdc85 + c2ef2c5 commit 03efdff
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 157 deletions.
191 changes: 72 additions & 119 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ edition = "2021"

[dependencies.gtk]
package = "gtk4"
version = "0.8"
features = ["v4_8"]
version = "0.9"
features = ["v4_12"]

[dependencies]
gemini = { path = "gemini" }
Expand All @@ -26,4 +26,4 @@ toml = "0.5.6"
serde = { version = "1.0.116", features = ["derive"] }
env_logger = "0.8.1"
log = "0.4.0"
adw = { package = "libadwaita", version = "0.6", features = ["v1_5"]}
adw = { package = "libadwaita", version = "0.7", features = ["v1_5"]}
6 changes: 3 additions & 3 deletions build-aux/com.ranfdev.Geopard.Devel.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"app-id" : "com.ranfdev.Geopard.Devel",
"runtime" : "org.gnome.Platform",
"runtime-version" : "46",
"runtime-version" : "47",
"sdk" : "org.gnome.Sdk",
"sdk-extensions" : [
"org.freedesktop.Sdk.Extension.rust-stable",
"org.freedesktop.Sdk.Extension.llvm16"
"org.freedesktop.Sdk.Extension.llvm18"
],
"command" : "geopard",
"tags" : [
Expand All @@ -20,7 +20,7 @@
"--filesystem=xdg-download"
],
"build-options" : {
"append-path" : "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm16/bin",
"append-path" : "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm18/bin",
"build-args" : [
"--share=network"
],
Expand Down
4 changes: 2 additions & 2 deletions gemini/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ futures = "0.3.5"
log = "0.4.0"
url = "2.1.1"
thiserror = "1.0.20"
glib = "0.19"
glib = "0.20"

[dependencies.gio]
package = "gio"
version = "0.19"
version = "0.20"
features = ["v2_70"]
19 changes: 18 additions & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gtk::glib;
use gtk::{glib, gio};
use once_cell::sync::Lazy;
use url::Url;

Expand Down Expand Up @@ -57,3 +57,20 @@ pub fn bookmarks_url() -> Url {
pub fn glibctx() -> glib::MainContext {
glib::MainContext::default()
}

pub fn open_uri_externally(uri: &str) {
gtk::UriLauncher::new(&uri).launch(None::<&gtk::Window>, None::<&gio::Cancellable>, |res| {
if let Err(e) = res {
log::error!("error opening external uri {:?}", e);
}
});
}

pub fn open_file_externally(path: &std::path::Path) {
let file = gio::File::for_path(path);
gtk::FileLauncher::new(Some(&file)).launch(None::<&gtk::Window>, None::<&gio::Cancellable>, |res| {
if let Err(e) = res {
log::error!("error opening external file {:?}", e);
}
});
}
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ macro_rules! self_action {
{
let this = &$self;
let action = gio::SimpleAction::new($name, None);
action.connect_activate(clone!(@weak this => move |_,_| this.$method()));
action.connect_activate(clone!(#[weak] this, move |_,_| this.$method()));
$self.add_action(&action);
action
}
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/pages/hypertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,22 @@ impl Hypertext {
let motion_ctrl = gtk::EventControllerMotion::new();

left_click_ctrl.connect_released(
clone!(@strong this => @default-panic, move |ctrl, _n_press, x, y| {
clone!(#[strong] this, move |ctrl, _n_press, x, y| {
if let Err(e) = this.handle_click(ctrl, x, y) {
log::info!("{}", e);
};
}),
);

right_click_ctrl.connect_pressed(
clone!(@strong this => @default-panic, move |_ctrl, _n_press, x, y| {
clone!(#[strong] this, move |_ctrl, _n_press, x, y| {
if let Err(e) = this.handle_right_click(x, y) {
log::info!("{}", e);
};
}),
);

motion_ctrl.connect_motion(clone!(@strong this => @default-panic,move |_ctrl, x, y| {
motion_ctrl.connect_motion(clone!(#[strong] this, move |_ctrl, x, y| {
let _ = this.handle_motion(x, y);
}));

Expand Down
12 changes: 6 additions & 6 deletions src/widgets/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use url::Url;

use super::pages::{self, hypertext};
use crate::common;
use crate::common::glibctx;
use crate::common::{glibctx, open_uri_externally, open_file_externally};
use crate::lossy_text_read::*;
use crate::session_provider::SessionProvider;

Expand Down Expand Up @@ -470,7 +470,7 @@ impl Tab {
let downloaded_file_url = format!("file://{}", d_path.as_os_str().to_str().unwrap());
info!("Downloading to {}", downloaded_file_url);
page.imp().open_btn.connect_clicked(move |_| {
gtk::show_uri(None::<&gtk::Window>, &downloaded_file_url, 0);
open_file_externally(&std::path::Path::new(&downloaded_file_url));
});

let ext = file_name.split('.').last();
Expand Down Expand Up @@ -594,7 +594,7 @@ impl Tab {
button.set_halign(gtk::Align::Center);
let url_clone = url.clone();
button.connect_clicked(move |_| {
gtk::show_uri(None::<&gtk::Window>, url_clone.as_str(), 0);
open_uri_externally(url_clone.as_str());
});
child.append(&button);

Expand All @@ -615,7 +615,7 @@ impl Tab {
p.connect_local(
"open",
false,
clone!(@weak self as this => @default-panic, move |s| {
clone!(#[weak(rename_to = this)] self, #[upgrade_or_panic] move |s| {
let s: String = s[1].get().unwrap();
let url = Url::parse(&s);
if let Ok(url) = url {
Expand Down Expand Up @@ -705,7 +705,7 @@ impl Tab {
p.set_icon_name(Some("dialog-error-symbolic"));

let override_btn = gtk::Button::with_label("Trust New Certificate");
override_btn.connect_clicked(clone!(@weak self as this => move |_| {
override_btn.connect_clicked(clone!(#[weak(rename_to = this)] self, move |_| {
let url = Url::parse(&this.url()).unwrap();

this.session().validator().remove_known(url.host_str().unwrap());
Expand Down Expand Up @@ -733,7 +733,7 @@ impl Tab {
p.set_icon_name(Some("dialog-error-symbolic"));

let override_btn = gtk::Button::with_label("Continue");
override_btn.connect_clicked(clone!(@weak self as this => move |_| {
override_btn.connect_clicked(clone!(#[weak(rename_to = this)] self, move |_| {
let url = Url::parse(&this.url()).unwrap();

this.session().validator().override_trust(url.host_str().unwrap());
Expand Down
46 changes: 27 additions & 19 deletions src/widgets/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub mod imp {
fn set_zoom(&self, v: f64) {
let Zoom { value, provider } = &mut *self.zoom.borrow_mut();
*value = v.clamp(1.0 / ZOOM_MAX_FACTOR, ZOOM_MAX_FACTOR);
provider.load_from_data(&format!(
provider.load_from_string(&format!(
"textview {{
font-size: {}rem;
}}",
Expand Down Expand Up @@ -232,26 +232,26 @@ impl Window {

let act_open_page = gio::SimpleAction::new("open-omni", Some(glib::VariantTy::STRING));
act_open_page.connect_activate(
clone!(@weak self as this => move |_,v| this.open_omni(v.unwrap().get::<String>().unwrap().as_str())),
clone!(#[weak(rename_to = this)] self, move |_,v| this.open_omni(v.unwrap().get::<String>().unwrap().as_str())),
);
self.add_action(&act_open_page);

let act_open_url = gio::SimpleAction::new("open-url", Some(glib::VariantTy::STRING));
act_open_url.connect_activate(
clone!(@weak self as this => move |_,v| this.open_url_str(v.unwrap().get::<String>().unwrap().as_str())),
clone!(#[weak(rename_to = this)] self, move |_,v| this.open_url_str(v.unwrap().get::<String>().unwrap().as_str())),
);
self.add_action(&act_open_url);

let act_open_in_new_tab =
gio::SimpleAction::new("open-in-new-tab", Some(glib::VariantTy::STRING));
act_open_in_new_tab.connect_activate(
clone!(@weak self as this => move |_,v| this.open_in_new_tab(v.unwrap().get::<String>().unwrap().as_str())),
clone!(#[weak(rename_to = this)] self, move |_,v| this.open_in_new_tab(v.unwrap().get::<String>().unwrap().as_str())),
);
self.add_action(&act_open_in_new_tab);

let act_set_clipboard =
gio::SimpleAction::new("set-clipboard", Some(glib::VariantTy::STRING));
act_set_clipboard.connect_activate(clone!(@weak self as this => move |_,v| {
act_set_clipboard.connect_activate(clone!(#[weak(rename_to = this)] self, move |_,v| {
this.set_clipboard(v.unwrap().get::<String>().unwrap().as_str());
this.imp().toast_overlay.add_toast(adw::Toast::new("Copied to clipboard"));
}));
Expand All @@ -267,7 +267,8 @@ impl Window {
imp.scroll_ctrl
.set_flags(gtk::EventControllerScrollFlags::VERTICAL);
imp.scroll_ctrl.connect_scroll(
clone!(@weak self as this => @default-panic, move |ctrl, _, y| {
clone!(#[weak(rename_to = this)] self, #[upgrade_or_panic]
move |ctrl, _, y| {
let up = y < 0.0;
if let Some(gdk::ModifierType::CONTROL_MASK) = ctrl.current_event().map(|e| e.modifier_state()) {
if up {
Expand All @@ -283,7 +284,7 @@ impl Window {
);
imp.mouse_prev_next_ctrl.set_button(0);
imp.mouse_prev_next_ctrl.connect_pressed(
clone!(@weak self as this => @default-panic, move |ctrl, _, _, _| {
clone!(#[weak(rename_to = this)] self, move |ctrl, _, _, _| {
match ctrl.current_button() {
8 => {
this.previous();
Expand All @@ -299,7 +300,8 @@ impl Window {
self.connect_local(
"notify::url",
false,
clone!(@weak self as this => @default-panic, move |_| {
clone!(#[weak(rename_to = this)] self, #[upgrade_or_default]
move |_| {
this.update_domain_color();

let bar = &this.imp().url_bar;
Expand All @@ -313,35 +315,39 @@ impl Window {
);

imp.tab_view.connect_selected_page_notify(
clone!(@weak self as this => @default-panic, move |tab_view| {
clone!(#[weak(rename_to = this)] self, move |tab_view| {
this.page_switched(tab_view);
}),
);
imp.tab_view.connect_close_page(
clone!(@weak self as this => @default-panic, move |tab_view, page| {
clone!(#[weak(rename_to = this)] self,
#[upgrade_or_panic]
move |tab_view, page| {
tab_view.close_page_finish(page, !page.is_pinned());

if tab_view.n_pages() == 0 {
this.close();
};

true
glib::Propagation::Proceed
}),
);
imp.tab_overview.connect_create_tab(
clone!(@weak self as this => @default-panic, move |_| {
clone!(#[weak(rename_to = this)] self,
#[upgrade_or_panic]
move |_| {
this.new_tab();
this.imp().tab_view.selected_page().unwrap()
}),
);

imp.url_bar
.connect_activate(clone!(@weak self as this => @default-panic, move |_sq| {
.connect_activate(clone!(#[weak(rename_to = this)] self, move |_sq| {
this.open_omni(this.imp().url_bar.text().as_str());
}));

adw::StyleManager::default().connect_dark_notify(
clone!(@weak self as this => @default-panic, move |_| {
clone!(#[weak(rename_to = this)] self, move |_| {
this.update_domain_color()
}),
);
Expand All @@ -358,7 +364,8 @@ impl Window {
ctrl.set_propagation_phase(gtk::PropagationPhase::Capture);

ctrl.connect_key_pressed(
clone!(@weak self as this => @default-panic, move |_, key, _, modif| {
clone!(#[weak(rename_to = this)] self, #[upgrade_or_panic]
move |_, key, _, modif| {
let action = match (modif.contains(gdk::ModifierType::CONTROL_MASK), key) {
(true, gdk::Key::ISO_Left_Tab) => Some("win.focus-previous-tab"),
(true, gdk::Key::Tab) => Some("win.focus-next-tab"),
Expand All @@ -380,7 +387,8 @@ impl Window {
.build();

drop_target.connect_drop(
clone!(@weak self as this => @default-return false, move |_, value, _, _| {
clone!(#[weak(rename_to = this)] self, #[upgrade_or_panic]
move |_, value, _, _| {
if let Ok(files) = value.get::<gdk::FileList>() {
for f in files.files() {
this.open_in_new_tab(&format!("file://{}", f.path().unwrap().to_str().unwrap()));
Expand Down Expand Up @@ -626,7 +634,7 @@ impl Window {
let imp = self.imp();
let url = imp.url_bar.text().to_string();

glibctx().spawn_local(clone!(@weak imp => async move {
glibctx().spawn_local(clone!(#[weak] imp, async move {
match Self::append_bookmark(&url).await {
Ok(_) => {
info!("{} saved to bookmarks", url);
Expand Down Expand Up @@ -717,7 +725,7 @@ impl Window {
)
};

imp.style_provider.borrow().load_from_data(&stylesheet);
imp.style_provider.borrow().load_from_string(&stylesheet);

Ok(())
}
Expand Down Expand Up @@ -746,7 +754,7 @@ impl Window {
.website("https://github.com/ranfdev/Geopard")
.build();
about.add_link("Donate 💝", "https://github.com/sponsors/ranfdev");
about.present(self);
about.present(Some(self));
}

fn focus_next_tab(&self) {
Expand Down

0 comments on commit 03efdff

Please sign in to comment.