浏览代码

Custom for icon

Aster 3 年之前
父节点
当前提交
78ac592c0a
共有 2 个文件被更改,包括 17 次插入0 次删除
  1. 1 0
      packages/desktop/Cargo.toml
  2. 16 0
      packages/desktop/src/cfg.rs

+ 1 - 0
packages/desktop/Cargo.toml

@@ -32,6 +32,7 @@ dioxus-html = { path = "../html", features = ["serialize"], version = "^0.1.6" }
 webbrowser = "0.5.5"
 mime_guess = "2.0.3"
 dioxus-interpreter-js = { path = "../interpreter", version = "^0.0.0" }
+image = "0.24.0"
 
 
 [features]

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

@@ -1,3 +1,6 @@
+use image::io::Reader as ImageReader;
+use image::ImageFormat;
+use std::io::Cursor;
 use wry::application::window::Icon;
 use wry::{
     application::{
@@ -86,6 +89,19 @@ impl DesktopConfig {
     }
 }
 
+impl DesktopConfig {
+    pub(crate) fn with_default_icon(mut self) -> Self {
+        let png: &[u8] = include_bytes!("default_icon.png");
+        let mut reader = ImageReader::new(Cursor::new(png));
+        reader.set_format(ImageFormat::Png);
+        let icon = reader.decode().expect("image parse failed");
+        let rgba = Icon::from_rgba(icon.as_bytes().to_owned(), icon.width(), icon.height())
+            .expect("image parse failed");
+        self.window.window.window_icon = Some(rgba);
+        self
+    }
+}
+
 impl Default for DesktopConfig {
     fn default() -> Self {
         Self::new()