Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebase #6

Merged
merged 22 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
491 changes: 482 additions & 9 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ incremental = true
opt-level = "s"
lto = "thin"

[build]
rustflags = ["-Z", "threads=8"]

[features]
default = ["webkit"]
default = ["webkit", "native-tls", "ultralight-resources"]
webkit = ["ultralight"]
ultralight = ["ul-next"]
ultralight-resources = []
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]

[dependencies]
env_home = "0.1.0"
clipboard-rs = "0.2.1"
iced = { version = "0.13", features = ["advanced", "image", "tokio", "lazy"] }
iced_aw = { version = "0.10", features = [
"tab_bar",
"icons",
"selection_list",
] }
iced_aw = { version = "0.10", features = ["tab_bar", "selection_list"] }
iced_fonts = { version = "0.1.1", features = ["bootstrap"] }
iced_on_focus_widget = "0.1.1"
rand = "0.8.5"
reqwest = "0.12.5"
Expand Down
72 changes: 20 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
## Iced library to create custom browsers
<img src="https://raw.githubusercontent.com/gist/hecrj/ad7ecd38f6e47ff3688a38c79fd108f0/raw/74384875ecbad02ae2a926425e9bcafd0695bade/color.svg" width=20%>

[![Build](https://github.com/LegitCamper/rust-browser/actions/workflows/ci.yml/badge.svg)](https://github.com/LegitCamper/rust-browser/actions/workflows/ci.yml)
<img src="https://raw.githubusercontent.com/gist/hecrj/ad7ecd38f6e47ff3688a38c79fd108f0/raw/74384875ecbad02ae2a926425e9bcafd0695bade/color.svg" width=8%>

### Supported Platforms
| Platform | Support |
| Windows | <span>&#10003;</span> |
| Linux | <span>&#10003;</span> |

[![Build](https://github.com/LegitCamper/icy_browser/actions/workflows/ci.yml/badge.svg)](https://github.com/LegitCamper/icy_browser/actions/workflows/ci.yml)

### Supported Browser Engines
| Browser Engine | Support |
Expand All @@ -19,64 +13,38 @@
### Browser Widgets
- Navigation Bar
- Tab Bar
- Bookmark Bar
- Browser View

### Examples
#### basic_browser.rs
<img src="https://github.com/LegitCamper/rust-browser/blob/main/assets/basic_browser.png" width=50%>
<img src="https://github.com/LegitCamper/icy_browser/blob/main/assets/basic_browser.png?raw=true" width=50%>

``` Rust
use iced::{Element, Settings, Theme};
use iced_aw::BOOTSTRAP_FONT_BYTES;
use iced::{Settings, Task, Theme};
use icy_browser::{get_fonts, Bookmark, IcyBrowser, Message, Ultralight};

use icy_browser::{widgets, BrowserWidget, Ultralight};
fn run() -> (IcyBrowser<Ultralight>, Task<Message>) {
(
IcyBrowser::new()
.with_tab_bar()
.with_nav_bar()
.with_bookmark_bar(&[Bookmark::new("https://www.rust-lang.org", "rust-lang.org")])
.build(),
Task::none(),
)
}

fn main() -> iced::Result {
// This imports `icons` for widgets
let bootstrap_font = BOOTSTRAP_FONT_BYTES.into();
let settings = Settings {
fonts: vec![bootstrap_font],
fonts: get_fonts(),
..Default::default()
};

iced::application("Basic Browser Example", Browser::update, Browser::view)
iced::application("Basic Browser", IcyBrowser::update, IcyBrowser::view)
.subscription(IcyBrowser::subscription)
.settings(settings)
.theme(|_| Theme::Dark)
.run()
}

#[derive(Debug, Clone)]
pub enum Message {
BrowserWidget(widgets::Message),
}

struct Browser {
widgets: BrowserWidget<Ultralight>,
}

impl Browser {
fn update(&mut self, message: Message) {
match message {
Message::BrowserWidget(msg) => {
self.widgets.update(msg);
}
}
}

fn view(&self) -> Element<Message> {
self.widgets.view().map(Message::BrowserWidget)
}
}

impl Default for Browser {
fn default() -> Self {
let widgets = BrowserWidget::new_with_ultralight()
.with_tab_bar()
.with_nav_bar()
.with_browsesr_view()
.build();

Self { widgets }
}
.run_with(run)
}
```
56 changes: 28 additions & 28 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
use std::env::var;
use std::fs::{self, DirEntry};
use std::path::Path;

const PATH: &str = env!("CARGO_MANIFEST_DIR");

fn main() {
// ensure runtime resources exist
#[cfg(feature = "ultralight")]
// ensure runtime resources exist - for examples & local tests
#[cfg(feature = "ultralight-resources")]
{
let out = var("OUT_DIR").unwrap();
// This allows it to work in this project but also other projects too
let path = Path::new(&out)
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap();

let mut possible_directories = Vec::new();

let target = Path::new(PATH).join("target");
let target = Path::new(path).join("target");
let debug_path = target.clone().join("debug");
let release_path = target.clone().join("release");

Expand All @@ -33,33 +46,24 @@ fn main() {

assert!(!possible_directories.is_empty());

let local_resources = Path::new(PATH).join("resources");
let local_resources = Path::new(path).join("resources");

for path in possible_directories {
if let Ok(resources) = fs::exists(path.path().join("out/ul-sdk/resources")) {
let resources_dir = path.path().join("out/ul-sdk/resources");
if let Ok(resources) = fs::exists(resources_dir.clone()) {
if resources {
if let Ok(local_resources_exist) = fs::exists(local_resources.clone()) {
if local_resources_exist {
fs::remove_dir_all(local_resources.clone())
fs::remove_file(local_resources.clone())
.expect("Failed to delete resources dir")
}
}

fs::create_dir(local_resources.clone())
.expect("Failed to create resources dir");

copy_file(
path.path().join("out/ul-sdk/resources").as_path(),
local_resources.clone().join("").as_path(),
"cacert.pem",
)
.expect("Failed to copy cacert.pem");
copy_file(
path.path().join("out/ul-sdk/resources").as_path(),
local_resources.clone().join("").as_path(),
"icudt67l.dat",
)
.expect("Failed to copy icudt67l.dat");
#[cfg(unix)]
{
std::os::unix::fs::symlink(resources_dir, local_resources)
.expect("Failed to sym link resource dir")
}

break;
}
Expand All @@ -69,15 +73,11 @@ fn main() {
}
}

println!("cargo:rerun-if-changed=resources");
println!("cargo:rerun-if-changed=target");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=Cargo.lock");
}

fn copy_file(from: &Path, to: &Path, file_name: &str) -> Result<u64, std::io::Error> {
fs::copy(from.join(file_name), to.join(file_name))
}

fn get_paths(possible_paths: &mut Vec<fs::DirEntry>, path_str: String) {
let mut paths: Vec<DirEntry> = fs::read_dir(path_str)
.expect("Could not read dir")
Expand Down
68 changes: 17 additions & 51 deletions examples/basic_browser.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,28 @@
// Simple browser with familiar browser widget and the ultralight(webkit) webengine as a backend
// Simple browser with familiar browser widgets and the ultralight(webkit) webengine as a backend

use iced::Theme;
use iced::{Element, Settings, Subscription, Task};
use iced_aw::BOOTSTRAP_FONT_BYTES;
use std::time::Duration;
use iced::{Settings, Task, Theme};
use icy_browser::{get_fonts, Bookmark, IcyBrowser, Message, Ultralight};

use icy_browser::{widgets, BrowserWidget, Ultralight};
fn run() -> (IcyBrowser<Ultralight>, Task<Message>) {
(
IcyBrowser::new()
.with_tab_bar()
.with_nav_bar()
.with_bookmark_bar(&[Bookmark::new("https://www.rust-lang.org", "rust-lang.org")])
.build(),
Task::none(),
)
}

fn main() -> iced::Result {
// This imports `icons` for widgets
let bootstrap_font = BOOTSTRAP_FONT_BYTES.into();
let settings = Settings {
fonts: vec![bootstrap_font],
fonts: get_fonts(),
..Default::default()
};

iced::application("Basic Browser Example", Browser::update, Browser::view)
.subscription(Browser::subscription)
iced::application("Basic Browser", IcyBrowser::update, IcyBrowser::view)
.subscription(IcyBrowser::subscription)
.settings(settings)
.theme(|_| Theme::Dark)
.run()
}

#[derive(Debug, Clone)]
pub enum Message {
BrowserWidget(widgets::Message), // Passes messagees to Browser widgets
Update,
}

struct Browser {
widgets: BrowserWidget<Ultralight>,
}

impl Default for Browser {
fn default() -> Self {
// Customize the look and feel of the browser here
let widgets = BrowserWidget::new_with_ultralight()
.with_tab_bar()
.with_nav_bar()
.build();

Self { widgets }
}
}

impl Browser {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::BrowserWidget(msg) => self.widgets.update(msg).map(Message::BrowserWidget),
Message::Update => self.widgets.force_update().map(Message::BrowserWidget),
}
}

fn view(&self) -> Element<Message> {
self.widgets.view().map(Message::BrowserWidget)
}

fn subscription(&self) -> Subscription<Message> {
iced::time::every(Duration::from_millis(10)).map(move |_| Message::Update)
}
.run_with(run)
}
92 changes: 92 additions & 0 deletions examples/custom_widgets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Custom view example with rainbow border

use iced::widget::container;
use iced::{time, Border};
use iced::{Color, Element, Length, Settings, Subscription, Task, Theme};
use std::time::{Duration, Instant};

use icy_browser::{get_fonts, widgets, IcyBrowser, Ultralight};

fn main() -> iced::Result {
let settings = Settings {
fonts: get_fonts(),
..Default::default()
};

iced::application("Keyboard Driven Browser", Browser::update, Browser::view)
.subscription(Browser::subscription)
.settings(settings)
.theme(|_| Theme::Dark)
.run()
}

#[derive(Debug, Clone)]
pub enum Message {
BrowserWidget(widgets::Message), // Passes messagees to Browser widgets
Update,
Tick,
}

#[derive(Debug, Clone)]
struct CustomWidgetState {
border_colors: Vec<Color>,
start_time: Instant,
}

struct Browser {
icy_browser: IcyBrowser<Ultralight>,
custom_widget_state: CustomWidgetState,
}

impl Default for Browser {
fn default() -> Self {
Self {
icy_browser: IcyBrowser::new().with_tab_bar().with_nav_bar().build(),
custom_widget_state: CustomWidgetState {
border_colors: vec![
Color::from_rgb(1.0, 0.0, 0.0), // Red
Color::from_rgb(1.0, 0.5, 0.0), // Orange
Color::from_rgb(1.0, 1.0, 0.0), // Yellow
Color::from_rgb(0.0, 1.0, 0.0), // Green
Color::from_rgb(0.0, 0.0, 1.0), // Blue
Color::from_rgb(0.29, 0.0, 0.51), // Indigo
Color::from_rgb(0.56, 0.0, 1.0), // Violet
],
start_time: Instant::now(),
},
}
}
}

impl Browser {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::BrowserWidget(msg) => self.icy_browser.update(msg).map(Message::BrowserWidget),
Message::Update => self.icy_browser.force_update().map(Message::BrowserWidget),
Message::Tick => Task::none(), // Tick
}
}

fn view(&self) -> Element<Message> {
let elapsed = self.custom_widget_state.start_time.elapsed().as_secs_f32();
let color_index = (elapsed * 2.0) as usize % self.custom_widget_state.border_colors.len();
let color = self.custom_widget_state.border_colors[color_index];

container(self.icy_browser.view().map(Message::BrowserWidget))
.center_x(Length::Fill)
.center_y(Length::Fill)
.padding(20)
.style(move |_theme| container::Style {
border: Border::default().color(color).width(20),
..Default::default()
})
.into()
}

fn subscription(&self) -> Subscription<Message> {
Subscription::batch([
time::every(Duration::from_millis(10)).map(move |_| Message::Update),
time::every(Duration::from_millis(16)).map(|_| Message::Tick),
])
}
}
Loading
Loading