diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5238be5..72166b0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -138,6 +138,7 @@ dependencies = [ "monitor", "raw-window-handle", "serde", + "serde_with", "tauri", "tauri-build", "windows 0.52.0", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d6dd9ef..e0ca2c1 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -10,6 +10,7 @@ tauri-build = { version = "1.5", features = [] } monitor = { path = "monitor" } raw-window-handle = "0.5" serde = { version = "1.0", features = ["derive"] } +serde_with = { version = "3.0", features = ["base64"] } tauri = { version = "1.5.x", features = ["wry", "window-set-focus", "window-set-position", "window-set-size", "window-show", "window-hide", "system-tray"], default-features = false } windows-version = "0.1" diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs index 1ef631c..7deda68 100644 --- a/src-tauri/src/tray.rs +++ b/src-tauri/src/tray.rs @@ -1,10 +1,13 @@ use serde::{Deserialize, Serialize}; +use serde_with::{base64::Base64, serde_as}; use tauri::{Icon, Manager, Window}; use crate::util::JSResult; +#[serde_as] #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TrayIcon { + #[serde_as(as = "Base64")] rgba: Vec, width: u32, height: u32, diff --git a/src/polyfill.d.ts b/src/polyfill.d.ts index 3911f40..a5d88b9 100644 --- a/src/polyfill.d.ts +++ b/src/polyfill.d.ts @@ -1,3 +1,7 @@ interface Math { clamp(x: number, lower: number, upper: number): number; } + +interface Uint8Array { + toBase64(options?: { alphabet?: "base64" | "base64url" }): string; +} diff --git a/src/polyfill.js b/src/polyfill.js index 1e8596a..52773ac 100644 --- a/src/polyfill.js +++ b/src/polyfill.js @@ -1 +1,2 @@ import "core-js/full/math/clamp"; +import "core-js/full/typed-array/to-base64"; diff --git a/src/wm.ts b/src/wm.ts index d20ae91..dad5a0b 100644 --- a/src/wm.ts +++ b/src/wm.ts @@ -222,7 +222,7 @@ watchEffect(() => { const imageData = ctx.getImageData(0, 0, scaledSize, scaledSize); invoke("set_tray_icon", { icon: { - rgba: Array.from(imageData.data), + rgba: new Uint8Array(imageData.data).toBase64(), width: imageData.width, height: imageData.height, },