Skip to content

Commit

Permalink
allow homepage to be custom html
Browse files Browse the repository at this point in the history
  • Loading branch information
LegitCamper committed Oct 11, 2024
1 parent 4a9c74a commit 9b7db45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub trait BrowserEngine {
fn get_cursor(&self) -> Interaction;
// fn get_icon(&self) -> Image<Handle>;
fn goto_url(&self, url: &Url);
fn goto_html(&self, html: String);
fn has_loaded(&self) -> bool;
fn new_tab(&mut self, url: Url, size: Size<u32>) -> Tab<Self::Info>;
fn get_tabs(&self) -> &Tabs<Self::Info>;
Expand Down
4 changes: 4 additions & 0 deletions src/engines/ultralight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ impl BrowserEngine for Ultralight {
*self.tabs.get_current().info.cursor.read().unwrap()
}

fn goto_html(&self, html: String) {
self.tabs.get_current().info.view.load_html(&html).unwrap();
}

fn goto_url(&self, url: &Url) {
self.tabs
.get_current()
Expand Down
17 changes: 15 additions & 2 deletions src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ impl Default for TabSelectionType {
}
}

/// Allows the user to write a custom homepage
pub enum HomepageType {
Url(String),
/// This is rendered with html
Custom(String),
}

pub struct IcyBrowser<Engine: BrowserEngine> {
engine: Engine,
home: Url,
Expand Down Expand Up @@ -150,8 +157,14 @@ impl<Engine: BrowserEngine> IcyBrowser<Engine> {
Self::default()
}

pub fn with_homepage(mut self, homepage: &str) -> Self {
self.home = Url::parse(homepage).expect("Failed to parse homepage as a url!");
pub fn with_homepage(mut self, homepage: HomepageType) -> Self {
match homepage {
HomepageType::Url(url) => {
self.home = Url::parse(&url).expect("Failed to parse homepage as a url!");
}
HomepageType::Custom(_) => todo!(),
}

self
}

Expand Down

0 comments on commit 9b7db45

Please sign in to comment.