|
@@ -16,8 +16,8 @@ use tauri_runtime::{
|
|
|
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
|
|
|
DetachedWindow, JsEventListenerKey, PendingWindow, WindowEvent,
|
|
|
},
|
|
|
- ClipboardManager, Dispatch, Error, ExitRequestedEventAction, GlobalShortcutManager, Icon, Result,
|
|
|
- RunEvent, RunIteration, Runtime, RuntimeHandle, UserAttentionType,
|
|
|
+ ClipboardManager, Dispatch, Error, ExitRequestedEventAction, GlobalShortcutManager, Result,
|
|
|
+ RunEvent, RunIteration, Runtime, RuntimeHandle, UserAttentionType, WindowIcon,
|
|
|
};
|
|
|
|
|
|
use tauri_runtime::window::MenuEvent;
|
|
@@ -56,7 +56,7 @@ use wry::{
|
|
|
MenuItemAttributes as WryMenuItemAttributes, MenuType,
|
|
|
},
|
|
|
monitor::MonitorHandle,
|
|
|
- window::{Fullscreen, Icon as WindowIcon, UserAttentionType as WryUserAttentionType},
|
|
|
+ window::{Fullscreen, Icon as WryWindowIcon, UserAttentionType as WryUserAttentionType},
|
|
|
},
|
|
|
http::{
|
|
|
Request as WryHttpRequest, RequestParts as WryRequestParts, Response as WryHttpResponse,
|
|
@@ -84,7 +84,6 @@ use std::{
|
|
|
HashMap, HashSet,
|
|
|
},
|
|
|
fmt,
|
|
|
- fs::read,
|
|
|
ops::Deref,
|
|
|
path::PathBuf,
|
|
|
sync::{
|
|
@@ -482,52 +481,18 @@ impl ClipboardManager for ClipboardManagerWrapper {
|
|
|
}
|
|
|
|
|
|
/// Wrapper around a [`wry::application::window::Icon`] that can be created from an [`Icon`].
|
|
|
-pub struct WryIcon(WindowIcon);
|
|
|
+pub struct WryIcon(WryWindowIcon);
|
|
|
|
|
|
fn icon_err<E: std::error::Error + Send + 'static>(e: E) -> Error {
|
|
|
Error::InvalidIcon(Box::new(e))
|
|
|
}
|
|
|
|
|
|
-impl TryFrom<Icon> for WryIcon {
|
|
|
+impl TryFrom<WindowIcon> for WryIcon {
|
|
|
type Error = Error;
|
|
|
- fn try_from(icon: Icon) -> std::result::Result<Self, Self::Error> {
|
|
|
- let image_bytes = match icon {
|
|
|
- Icon::File(path) => read(path).map_err(icon_err)?,
|
|
|
- Icon::Raw(raw) => raw,
|
|
|
- _ => unimplemented!(),
|
|
|
- };
|
|
|
- let extension = infer::get(&image_bytes)
|
|
|
- .expect("could not determine icon extension")
|
|
|
- .extension();
|
|
|
- match extension {
|
|
|
- #[cfg(windows)]
|
|
|
- "ico" => {
|
|
|
- let icon_dir = ico::IconDir::read(std::io::Cursor::new(image_bytes)).map_err(icon_err)?;
|
|
|
- let entry = &icon_dir.entries()[0];
|
|
|
- let icon = WindowIcon::from_rgba(
|
|
|
- entry.decode().map_err(icon_err)?.rgba_data().to_vec(),
|
|
|
- entry.width(),
|
|
|
- entry.height(),
|
|
|
- )
|
|
|
- .map_err(icon_err)?;
|
|
|
- Ok(Self(icon))
|
|
|
- }
|
|
|
- #[cfg(target_os = "linux")]
|
|
|
- "png" => {
|
|
|
- let decoder = png::Decoder::new(std::io::Cursor::new(image_bytes));
|
|
|
- let (info, mut reader) = decoder.read_info().map_err(icon_err)?;
|
|
|
- let mut buffer = Vec::new();
|
|
|
- while let Ok(Some(row)) = reader.next_row() {
|
|
|
- buffer.extend(row);
|
|
|
- }
|
|
|
- let icon = WindowIcon::from_rgba(buffer, info.width, info.height).map_err(icon_err)?;
|
|
|
- Ok(Self(icon))
|
|
|
- }
|
|
|
- _ => panic!(
|
|
|
- "image `{}` extension not supported; please file a Tauri feature request",
|
|
|
- extension
|
|
|
- ),
|
|
|
- }
|
|
|
+ fn try_from(icon: WindowIcon) -> std::result::Result<Self, Self::Error> {
|
|
|
+ WryWindowIcon::from_rgba(icon.rgba, icon.width, icon.height)
|
|
|
+ .map(Self)
|
|
|
+ .map_err(icon_err)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -851,7 +816,7 @@ impl WindowBuilder for WindowBuilderWrapper {
|
|
|
self
|
|
|
}
|
|
|
|
|
|
- fn icon(mut self, icon: Icon) -> Result<Self> {
|
|
|
+ fn icon(mut self, icon: WindowIcon) -> Result<Self> {
|
|
|
self.inner = self
|
|
|
.inner
|
|
|
.with_window_icon(Some(WryIcon::try_from(icon)?.0));
|
|
@@ -975,7 +940,7 @@ pub enum WindowMessage {
|
|
|
SetPosition(Position),
|
|
|
SetFullscreen(bool),
|
|
|
SetFocus,
|
|
|
- SetIcon(WindowIcon),
|
|
|
+ SetIcon(WryWindowIcon),
|
|
|
SetSkipTaskbar(bool),
|
|
|
DragWindow,
|
|
|
UpdateMenuItem(u16, MenuUpdate),
|
|
@@ -1001,7 +966,7 @@ pub enum WebviewEvent {
|
|
|
pub enum TrayMessage {
|
|
|
UpdateItem(u16, MenuUpdate),
|
|
|
UpdateMenu(SystemTrayMenu),
|
|
|
- UpdateIcon(Icon),
|
|
|
+ UpdateIcon(TrayIcon),
|
|
|
#[cfg(target_os = "macos")]
|
|
|
UpdateIconAsTemplate(bool),
|
|
|
Close,
|
|
@@ -1392,7 +1357,7 @@ impl Dispatch for WryDispatcher {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- fn set_icon(&self, icon: Icon) -> Result<()> {
|
|
|
+ fn set_icon(&self, icon: WindowIcon) -> Result<()> {
|
|
|
send_user_message(
|
|
|
&self.context,
|
|
|
Message::Window(
|
|
@@ -1790,7 +1755,7 @@ impl Runtime for Wry {
|
|
|
let icon = system_tray
|
|
|
.icon
|
|
|
.expect("tray icon not set")
|
|
|
- .into_tray_icon();
|
|
|
+ .into_platform_icon();
|
|
|
|
|
|
let mut items = HashMap::new();
|
|
|
|
|
@@ -2208,7 +2173,7 @@ fn handle_user_message(
|
|
|
}
|
|
|
TrayMessage::UpdateIcon(icon) => {
|
|
|
if let Some(tray) = &*tray_context.tray.lock().unwrap() {
|
|
|
- tray.lock().unwrap().set_icon(icon.into_tray_icon());
|
|
|
+ tray.lock().unwrap().set_icon(icon.into_platform_icon());
|
|
|
}
|
|
|
}
|
|
|
#[cfg(target_os = "macos")]
|