Remove image at runtime
This commit is contained in:
1 parent
f6b30d26b9
commit
21b436b7bf
3 files changed
+28
-10
No files matched your search
@@ -32,7 +32,6 @@ dioxus-html = { path = "../html", features = ["serialize"], version = "^0.1.6" }
|
|||||||
webbrowser = "0.5.5"
|
webbrowser = "0.5.5"
|
||||||
mime_guess = "2.0.3"
|
mime_guess = "2.0.3"
|
||||||
dioxus-interpreter-js = { path = "../interpreter", version = "^0.0.0" }
|
dioxus-interpreter-js = { path = "../interpreter", version = "^0.0.0" }
|
||||||
image = "0.24.0"
|
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
@@ -42,3 +41,4 @@ tokio_runtime = ["tokio"]
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
dioxus-hooks = { path = "../hooks" }
|
dioxus-hooks = { path = "../hooks" }
|
||||||
|
image = "0.24.0"
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
use image::io::Reader as ImageReader;
|
|
||||||
use image::ImageFormat;
|
|
||||||
use std::io::Cursor;
|
|
||||||
use wry::application::window::Icon;
|
use wry::application::window::Icon;
|
||||||
use wry::{
|
use wry::{
|
||||||
application::{
|
application::{
|
||||||
@@ -91,12 +88,8 @@ impl DesktopConfig {
|
|||||||
|
|
||||||
impl DesktopConfig {
|
impl DesktopConfig {
|
||||||
pub(crate) fn with_default_icon(mut self) -> Self {
|
pub(crate) fn with_default_icon(mut self) -> Self {
|
||||||
let png: &[u8] = include_bytes!("default_icon.png");
|
let bin: &[u8] = include_bytes!("default_icon.bin");
|
||||||
let mut reader = ImageReader::new(Cursor::new(png));
|
let rgba = Icon::from_rgba(bin.to_owned(), 460, 460).expect("image parse failed");
|
||||||
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.window.window.window_icon = Some(rgba);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -107,3 +100,28 @@ impl Default for DesktopConfig {
|
|||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dirty trick, avoid introducing `image` at runtime
|
||||||
|
// TODO: use serde when `Icon` impl serde
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn prepare_default_icon() {
|
||||||
|
use image::io::Reader as ImageReader;
|
||||||
|
use image::ImageFormat;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Cursor;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
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().unwrap();
|
||||||
|
let bin = PathBuf::from(file!())
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.join("default_icon.bin");
|
||||||
|
println!("{:?}", bin);
|
||||||
|
let mut file = File::create(bin).unwrap();
|
||||||
|
file.write_all(icon.as_bytes()).unwrap();
|
||||||
|
println!("({}, {})", icon.width(), icon.height())
|
||||||
|
}
|
||||||
Binary file not shown.
Reference in new issue
Block a user