Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
use base64 to pass icon
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Dec 9, 2023
1 parent c225c09 commit eb92f64
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
width: u32,
height: u32,
Expand Down
4 changes: 4 additions & 0 deletions src/polyfill.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
interface Math {
clamp(x: number, lower: number, upper: number): number;
}

interface Uint8Array {
toBase64(options?: { alphabet?: "base64" | "base64url" }): string;
}
1 change: 1 addition & 0 deletions src/polyfill.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import "core-js/full/math/clamp";
import "core-js/full/typed-array/to-base64";
2 changes: 1 addition & 1 deletion src/wm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit eb92f64

Please sign in to comment.