|
@@ -1,3 +1,4 @@
|
|
|
|
+use wry::application::window::Icon;
|
|
use wry::{
|
|
use wry::{
|
|
application::{
|
|
application::{
|
|
event_loop::EventLoop,
|
|
event_loop::EventLoop,
|
|
@@ -13,12 +14,12 @@ pub(crate) type DynEventHandlerFn = dyn Fn(&mut EventLoop<()>, &mut WebView);
|
|
pub struct DesktopConfig {
|
|
pub struct DesktopConfig {
|
|
pub window: WindowBuilder,
|
|
pub window: WindowBuilder,
|
|
pub file_drop_handler: Option<Box<dyn Fn(&Window, FileDropEvent) -> bool>>,
|
|
pub file_drop_handler: Option<Box<dyn Fn(&Window, FileDropEvent) -> bool>>,
|
|
- pub protocos: Vec<WryProtocl>,
|
|
|
|
|
|
+ pub protocols: Vec<WryProtocol>,
|
|
pub(crate) pre_rendered: Option<String>,
|
|
pub(crate) pre_rendered: Option<String>,
|
|
pub(crate) event_handler: Option<Box<DynEventHandlerFn>>,
|
|
pub(crate) event_handler: Option<Box<DynEventHandlerFn>>,
|
|
}
|
|
}
|
|
|
|
|
|
-pub type WryProtocl = (
|
|
|
|
|
|
+pub type WryProtocol = (
|
|
String,
|
|
String,
|
|
Box<dyn Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static>,
|
|
Box<dyn Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static>,
|
|
);
|
|
);
|
|
@@ -31,7 +32,7 @@ impl DesktopConfig {
|
|
Self {
|
|
Self {
|
|
event_handler: None,
|
|
event_handler: None,
|
|
window,
|
|
window,
|
|
- protocos: Vec::new(),
|
|
|
|
|
|
+ protocols: Vec::new(),
|
|
file_drop_handler: None,
|
|
file_drop_handler: None,
|
|
pre_rendered: None,
|
|
pre_rendered: None,
|
|
}
|
|
}
|
|
@@ -75,7 +76,21 @@ impl DesktopConfig {
|
|
where
|
|
where
|
|
F: Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static,
|
|
F: Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static,
|
|
{
|
|
{
|
|
- self.protocos.push((name, Box::new(handler)));
|
|
|
|
|
|
+ self.protocols.push((name, Box::new(handler)));
|
|
|
|
+ self
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn with_icon(&mut self, icon: Icon) -> &mut Self {
|
|
|
|
+ self.window.window.window_icon = Some(icon);
|
|
|
|
+ self
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl DesktopConfig {
|
|
|
|
+ pub(crate) fn with_default_icon(mut self) -> Self {
|
|
|
|
+ let bin: &[u8] = include_bytes!("default_icon.bin");
|
|
|
|
+ let rgba = Icon::from_rgba(bin.to_owned(), 460, 460).expect("image parse failed");
|
|
|
|
+ self.window.window.window_icon = Some(rgba);
|
|
self
|
|
self
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -85,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())
|
|
|
|
+}
|