From b5cd950218d6deadd46bd3d1529a3cabeac2220f Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Thu, 4 Dec 2025 16:47:12 +0300 Subject: Fixes in main window, started settings window. Added CI workflow. --- .woodpecker.yaml | 57 ++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 26 ++++++++------------- src/settings_window.rs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/.gitkeep | 0 5 files changed, 128 insertions(+), 17 deletions(-) create mode 100644 .woodpecker.yaml create mode 100644 src/settings_window.rs create mode 100644 tests/.gitkeep diff --git a/.woodpecker.yaml b/.woodpecker.yaml new file mode 100644 index 0000000..597c346 --- /dev/null +++ b/.woodpecker.yaml @@ -0,0 +1,57 @@ +steps: + dependencies: + image: rust + environment: + RUST_BACKTRACE: 1 + CARGO_TERM_COLOR: always + commands: + - rustup default stable + - apt install -y libwebkit2 gtk-4.0-dev + when: + branch: main + event: [ push, pull_request ] + build: + image: rust + environment: + RUST_BACKTRACE: 1 + CARGO_TERM_COLOR: always + commands: + - cargo build --verbose --release --jobs 2 + when: + branch: main + event: [ push, pull_request ] + + fmt: + image: rust + environment: + RUST_BACKTRACE: 1 + CARGO_TERM_COLOR: always + commands: + - rustup component add rustfmt + - cargo fmt --all -- --check + when: + branch: main + event: [ push, pull_request ] +# clippy: +# image: rust +# environment: +# RUST_BACKTRACE: 1 +# CARGO_TERM_COLOR: always +# commands: +# - rustup component add clippy rustfmt +# - cargo fmt --all -- --check +# - cargo clippy --jobs 2 -- -D clippy::all -D warnings +# when: +# branch: main +# event: [ push, pull_request ] + +# tests: +# image: rust +# environment: +# RUST_BACKTRACE: 1 +# CARGO_TERM_COLOR: always +# commands: +# - cargo test --verbose --jobs 2 -- --test-threads=2 +# when: +# branch: main +# event: [ push, pull_request ] \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 6ea9bba..1a150db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ glib = "0.21.5" gtk4 = "0.10.3" relm4 = "0.10.0" webkit6 = "0.5.0" +toml = { version = "0.9.8", features = ["serde"] } diff --git a/src/main.rs b/src/main.rs index 9bae187..a74f0bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,12 @@ use gtk4::prelude::*; -use gtk4::{Application, - ApplicationWindow, - Box, - Button, - Entry, - HeaderBar, - Orientation, - ScrolledWindow}; +use gtk4::{ + Application, ApplicationWindow, Box, Button, Entry, HeaderBar, Orientation, ScrolledWindow, +}; -use webkit6::prelude::*; use webkit6::WebView; +use webkit6::prelude::*; + +mod settings_window; const APP_ID: &str = "com.namilsk.i2p-browser"; @@ -50,9 +47,7 @@ fn build_ui(app: &Application) { let web_view = WebView::new(); - let scrolled_window = ScrolledWindow::builder() - .child(&web_view) - .build(); + let scrolled_window = ScrolledWindow::builder().child(&web_view).build(); main_box.append(&scrolled_window); @@ -74,7 +69,6 @@ fn build_ui(app: &Application) { 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() { @@ -82,7 +76,6 @@ fn build_ui(app: &Application) { } }); - let web_view_for_forward = web_view.clone(); button_forward.connect_clicked(move |_| { if web_view_for_forward.can_go_forward() { @@ -95,11 +88,10 @@ fn build_ui(app: &Application) { 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/"; + let home_url = "http://reg.i2p/"; web_view_for_home.load_uri(home_url); url_entry_for_home.set_text(home_url); }); @@ -114,4 +106,4 @@ fn build_ui(app: &Application) { web_view.load_uri("http://legwork.i2p/"); window.present(); -} \ No newline at end of file +} diff --git a/src/settings_window.rs b/src/settings_window.rs new file mode 100644 index 0000000..fbab489 --- /dev/null +++ b/src/settings_window.rs @@ -0,0 +1,61 @@ + +use gtk4::prelude::*; +use gtk4::{ + ApplicationWindow, + Box, + Entry, + Label, + Orientation, + HeaderBar, + CheckButton +}; +use toml; +use serde::Serialize; + +#[allow(dead_code)] +#[derive(Debug, Serialize)] +struct Settings { + js: bool, + outproxy: bool, + i2p_proxy: bool, + web_rtc: bool, + home_addr: str, + +} + +#[allow(dead_code, unused_variables)] +pub fn window() -> ApplicationWindow { + let app = ApplicationWindow::builder() + .title("Settings") + .default_width(400) + .default_height(300) + .build(); + + let header_bar = HeaderBar::new(); + window().set_titlebar(Some(&header_bar)); + + let main_box = Box::new(Orientation::Vertical, 0); + window().set_child(Some(&main_box)); + + Label::new(Some("Settings")).set_markup("Settings"); + + let javascript = CheckButton::new().set_label(Some("Enable JS")); + let outproxy = CheckButton::new().set_label(Some("Enable outproxy")); + let i2pproxy = CheckButton::new().set_label(Some("Enable i2p proxy")); + let webrtc = CheckButton::new().set_label(Some("Enable WebRTC")); + let homeaddr = Entry::new(); + + app +} + +#[allow(dead_code)] +impl Settings { + pub fn serialize_write(path: &std::path::Path, + setts: &Settings) -> Result<(), toml::ser::Error> { + + let toml: String = toml::to_string(setts)?; + std::fs::write(path, toml).expect("Some error occured, is permission granted to ~/.config?"); + + Ok(()) + } +} \ No newline at end of file diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3