diff --git a/packages/desktop/src/cfg.rs b/packages/desktop/src/cfg.rs index d7f1b5dfa..619a6801a 100644 --- a/packages/desktop/src/cfg.rs +++ b/packages/desktop/src/cfg.rs @@ -23,6 +23,7 @@ pub struct Config { pub(crate) custom_head: Option, pub(crate) custom_index: Option, pub(crate) root_name: String, + pub(crate) background_color: Option<(u8, u8, u8, u8)>, } type DropHandler = Box bool>; @@ -50,6 +51,7 @@ impl Config { custom_head: None, custom_index: None, root_name: "main".to_string(), + background_color: None, } } @@ -137,6 +139,14 @@ impl Config { self.root_name = name.into(); self } + + /// Sets the background color of the WebView. + /// This will be set before the HTML is rendered and can be used to prevent flashing when the page loads. + /// Accepts a color in RGBA format + pub fn with_background_color(mut self, color: (u8, u8, u8, u8)) -> Self { + self.background_color = Some(color); + self + } } impl Default for Config { diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index 5d3acf44f..0b7152cfd 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -64,6 +64,10 @@ pub fn build( webview = webview.with_browser_accelerator_keys(false); } + if let Some(color) = cfg.background_color { + webview = webview.with_background_color(color); + } + // These are commented out because wry is currently broken in wry // let mut web_context = WebContext::new(cfg.data_dir.clone()); // .with_web_context(&mut web_context);