diff options
| author | Namilskyy <alive6863@gmail.com> | 2025-12-04 16:10:12 +0300 |
|---|---|---|
| committer | Namilskyy <alive6863@gmail.com> | 2025-12-04 16:10:12 +0300 |
| commit | d70de444665cb79bc36f9acc807aef5d9706dac1 (patch) | |
| tree | f90d2bcfea7bc222195c2096977fa6dfbdbf454f | |
| parent | 034645f5936dff9233e64bbc62198ee6ad37c0bd (diff) | |
Implemented minimal browser gtk window
| -rw-r--r-- | Cargo.toml | 14 | ||||
| -rw-r--r-- | src/main.rs | 117 |
2 files changed, 131 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6ea9bba --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "i2p-browser" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-only" + +[dependencies] +reqwest = { version = "0.12.24", features = ["stream"] } +serde = { version = "1.0.228", features = ["derive"] } +tokio = { version = "1.48.0", features = ["io-util", "rt"] } +glib = "0.21.5" +gtk4 = "0.10.3" +relm4 = "0.10.0" +webkit6 = "0.5.0" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9bae187 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,117 @@ +use gtk4::prelude::*; +use gtk4::{Application, + ApplicationWindow, + Box, + Button, + Entry, + HeaderBar, + Orientation, + ScrolledWindow}; + +use webkit6::prelude::*; +use webkit6::WebView; + +const APP_ID: &str = "com.namilsk.i2p-browser"; + +fn main() -> glib::ExitCode { + let app = Application::builder().application_id(APP_ID).build(); + app.connect_activate(build_ui); + app.run() +} + +fn build_ui(app: &Application) { + let window = ApplicationWindow::builder() + .application(app) + .title("I2P Browser") + .default_width(1024) + .default_height(768) + .build(); + + let header_bar = HeaderBar::new(); + window.set_titlebar(Some(&header_bar)); + + let url_entry = Entry::builder() + .placeholder_text("Enter I2P URL (e.g., http://example.i2p)") + .build(); + + let button_back = Button::with_label("<"); + let button_forward = Button::with_label(">"); + let button_reload = Button::with_label("R"); + let button_home = Button::with_label("H"); + + header_bar.pack_start(&button_back); + header_bar.pack_start(&button_forward); + header_bar.pack_start(&button_reload); + header_bar.pack_start(&button_home); + header_bar.set_title_widget(Some(&url_entry)); + + let main_box = Box::new(Orientation::Vertical, 0); + window.set_child(Some(&main_box)); + + let web_view = WebView::new(); + + let scrolled_window = ScrolledWindow::builder() + .child(&web_view) + .build(); + + main_box.append(&scrolled_window); + + let web_view_for_entry = web_view.clone(); + let url_entry_for_entry = url_entry.clone(); + url_entry.connect_activate(move |entry| { + let url = entry.text(); + let full_url = if url.starts_with("http://") || url.starts_with("https://") { + url.to_string() + } else { + format!("http://{}", url) + }; + + if glib::Uri::parse(&full_url, glib::UriFlags::NONE).is_ok() { + web_view_for_entry.load_uri(&full_url); + } else { + eprintln!("Invalid URI: {}", full_url); + } + url_entry_for_entry.set_text(&full_url); + }); + + + let web_view_for_back = web_view.clone(); + button_back.connect_clicked(move |_| { + if web_view_for_back.can_go_back() { + web_view_for_back.go_back(); + } + }); + + + let web_view_for_forward = web_view.clone(); + button_forward.connect_clicked(move |_| { + if web_view_for_forward.can_go_forward() { + web_view_for_forward.go_forward(); + } + }); + + let web_view_for_reload = web_view.clone(); + button_reload.connect_clicked(move |_| { + web_view_for_reload.reload(); + }); + + + let web_view_for_home = web_view.clone(); + let url_entry_for_home = url_entry.clone(); + button_home.connect_clicked(move |_| { + let home_url = "http://reg.i2p/"; + web_view_for_home.load_uri(home_url); + url_entry_for_home.set_text(home_url); + }); + + let url_entry_for_notify = url_entry.clone(); + web_view.connect_notify_local(Some("uri"), move |web_view, _| { + if let Some(uri) = web_view.uri() { + url_entry_for_notify.set_text(&uri); + } + }); + + web_view.load_uri("http://legwork.i2p/"); + + window.present(); +}
\ No newline at end of file |
