Browse Source

expose wry background color option

Evan Almloff 2 years ago
parent
commit
1e5c220736
2 changed files with 14 additions and 0 deletions
  1. 10 0
      packages/desktop/src/cfg.rs
  2. 4 0
      packages/desktop/src/webview.rs

+ 10 - 0
packages/desktop/src/cfg.rs

@@ -23,6 +23,7 @@ pub struct Config {
     pub(crate) custom_head: Option<String>,
     pub(crate) custom_index: Option<String>,
     pub(crate) root_name: String,
+    pub(crate) background_color: Option<(u8, u8, u8, u8)>,
 }
 
 type DropHandler = Box<dyn Fn(&Window, FileDropEvent) -> 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 {

+ 4 - 0
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);