mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-24 19:25:12 +03:00
refactor!(core): remove Icon
enum and add Image
type (#9011)
* refactor!(core): remove `Icon` enum and add `Image` type * clippy * revert api example config change * Update image.rs * fix build * clippy * change files * add back removed methods as setter functions * simplify error message * Update .changes/runtime-icon-lifetime.md * Update .changes/ico-featrue-flags.md * Update core/tauri/src/image.rs * update api lockfile * update api ref * lint --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
parent
ab060ebb34
commit
d1e77acd8d
5
.changes/ico-featrue-flags.md
Normal file
5
.changes/ico-featrue-flags.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'major:breaking'
|
||||
---
|
||||
|
||||
Renamed `icon-ico` and `icon-png` feature flags to `image-ico` and `image-png` respectively
|
5
.changes/runtime-icon-lifetime.md
Normal file
5
.changes/runtime-icon-lifetime.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri-runtime': 'major:breaking'
|
||||
---
|
||||
|
||||
Add a lifetime parameter for `Icon` type. Also changed `rgba` field to be `Cow<'a, [u8]>`
|
5
.changes/tauri-context-icon-methods.md
Normal file
5
.changes/tauri-context-icon-methods.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'major:breaking'
|
||||
---
|
||||
|
||||
Removed `Context::default_window_icon_mut` and `Context::tray_icon_mut`, use `Context::set_default_window_icon` and `Context::set_tray_icon` instead. Also changed `Context::set_tray_icon` to accept `Option<T>`.
|
5
.changes/tauri-icon-removed.md
Normal file
5
.changes/tauri-icon-removed.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'major:breaking'
|
||||
---
|
||||
|
||||
Removed `Icon` enum, use the new `Image` type instead. All APIs that previously accepted `Icon` have changed to accept `Image` instead.
|
5
.changes/tauri-image-codegen.md
Normal file
5
.changes/tauri-image-codegen.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri-codegen': 'major:breaking'
|
||||
---
|
||||
|
||||
Change the generated context code to use the new `Image` type in tauri.
|
5
.changes/tauri-image.md
Normal file
5
.changes/tauri-image.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'minor:feat'
|
||||
---
|
||||
|
||||
Add `Image` type.
|
262
Cargo.lock
generated
262
Cargo.lock
generated
@ -230,9 +230,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.15.0"
|
||||
version = "3.15.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d32a994c2b3ca201d9b263612a374263f05e7adde37c4707f693dcd375076d1f"
|
||||
checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
@ -251,7 +251,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -338,12 +338,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.83"
|
||||
version = "1.0.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc"
|
||||
|
||||
[[package]]
|
||||
name = "cesu8"
|
||||
@ -400,7 +397,7 @@ dependencies = [
|
||||
"iana-time-zone",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"windows-targets 0.52.0",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -537,9 +534,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.11"
|
||||
version = "0.5.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b"
|
||||
checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
@ -585,17 +582,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.2.6"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30d2b3721e861707777e3195b0158f950ae6dc4a27e4d02ff9f67e3eb3de199e"
|
||||
checksum = "ad291aa74992b9b7a7e88c38acbbf6ad7e107f1d90ee8775b7bc1fc3394f485c"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -609,9 +606,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.6"
|
||||
version = "0.20.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955"
|
||||
checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
@ -619,27 +616,27 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.6"
|
||||
version = "0.20.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855"
|
||||
checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.6"
|
||||
version = "0.20.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be"
|
||||
checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -737,7 +734,7 @@ checksum = "f2b99bf03862d7f545ebc28ddd33a665b50865f4dfd84031a393823879bd4c54"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -808,9 +805,9 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
|
||||
|
||||
[[package]]
|
||||
name = "dyn-clone"
|
||||
version = "1.0.16"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d"
|
||||
checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
|
||||
|
||||
[[package]]
|
||||
name = "embed-resource"
|
||||
@ -941,7 +938,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1015,7 +1012,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1157,15 +1154,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "generator"
|
||||
version = "0.7.5"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"
|
||||
checksum = "b5b25e5b3e733153bcab35ee4671b46604b42516163cae442d1601cb716f2ac5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"log",
|
||||
"rustversion",
|
||||
"windows 0.48.0",
|
||||
"windows 0.53.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1292,7 +1290,7 @@ dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1371,7 +1369,7 @@ dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1413,9 +1411,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.6"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd"
|
||||
checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
@ -1539,7 +1537,7 @@ dependencies = [
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1579,9 +1577,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.24.8"
|
||||
version = "0.24.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "034bbe799d1909622a74d1193aa50147769440040ff36cb2baa947609b0a4e23"
|
||||
checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder",
|
||||
@ -1631,9 +1629,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "insta"
|
||||
version = "1.34.0"
|
||||
version = "1.35.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d64600be34b2fcfc267740a243fa7744441bb4947a619ac4e5bb6507f35fbfc"
|
||||
checksum = "7c985c1bef99cf13c58fade470483d81a2bfe846ebde60ed28cc2dddec2df9e2"
|
||||
dependencies = [
|
||||
"console",
|
||||
"lazy_static",
|
||||
@ -2017,9 +2015,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "muda"
|
||||
version = "0.11.4"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e406691fa7749604bbc7964bde28a300572d52621bb84540f6907c0f8fe08737"
|
||||
checksum = "4c47e7625990fc1af2226ea4f34fb2412b03c12639fcb91868581eb3a6893453"
|
||||
dependencies = [
|
||||
"cocoa",
|
||||
"crossbeam-channel",
|
||||
@ -2201,9 +2199,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.63"
|
||||
version = "0.10.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8"
|
||||
checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f"
|
||||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"cfg-if",
|
||||
@ -2222,7 +2220,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2242,9 +2240,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.99"
|
||||
version = "0.9.101"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae"
|
||||
checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@ -2344,7 +2342,7 @@ dependencies = [
|
||||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2462,7 +2460,7 @@ dependencies = [
|
||||
"phf_shared 0.11.2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3136,22 +3134,22 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.196"
|
||||
version = "1.0.197"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32"
|
||||
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.196"
|
||||
version = "1.0.197"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
|
||||
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3167,9 +3165,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.113"
|
||||
version = "1.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79"
|
||||
checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0"
|
||||
dependencies = [
|
||||
"itoa 1.0.10",
|
||||
"ryu",
|
||||
@ -3184,7 +3182,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3235,7 +3233,7 @@ dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3334,12 +3332,12 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.5.5"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
|
||||
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3488,9 +3486,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.49"
|
||||
version = "2.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "915aea9e586f80826ee59f8453c1101f9d1c4b3964cd2460185ee8e299ada496"
|
||||
checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -3539,9 +3537,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tao"
|
||||
version = "0.26.0"
|
||||
version = "0.26.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29d9325da2dd7ebd48a8a433c64240079b15dbe1249da04c72557611bcd08d1c"
|
||||
checksum = "ccba570365293ca309d60f30fdac2c5271b732dc762e6154e59c85d2c762a0a1"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"cocoa",
|
||||
@ -3590,9 +3588,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "target-lexicon"
|
||||
version = "0.12.13"
|
||||
version = "0.12.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae"
|
||||
checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
|
||||
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
@ -3691,7 +3689,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
"tauri-utils",
|
||||
"thiserror",
|
||||
"time",
|
||||
@ -3718,7 +3716,7 @@ dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
"tauri-codegen",
|
||||
"tauri-utils",
|
||||
]
|
||||
@ -3823,9 +3821,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.10.0"
|
||||
version = "3.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67"
|
||||
checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
@ -3867,14 +3865,14 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.7"
|
||||
version = "1.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
|
||||
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@ -3965,7 +3963,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4086,7 +4084,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4195,9 +4193,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
@ -4356,7 +4354,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@ -4390,7 +4388,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
@ -4532,7 +4530,7 @@ dependencies = [
|
||||
"webview2-com-macros",
|
||||
"webview2-com-sys",
|
||||
"windows 0.52.0",
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
]
|
||||
@ -4545,7 +4543,7 @@ checksum = "ac1345798ecd8122468840bcdf1b95e5dc6d2206c5e4b0eafa078d061f59c9bc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4556,7 +4554,7 @@ checksum = "d6ad85fceee6c42fa3d61239eba5a11401bf38407a849ed5ea1b407df08cca72"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"windows 0.52.0",
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4603,25 +4601,26 @@ dependencies = [
|
||||
"windows-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-targets 0.52.0",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "efc5cf48f83140dcaab716eeaea345f9e93d0018fb81162753a3f76c3397b538"
|
||||
dependencies = [
|
||||
"windows-core 0.53.0",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4630,7 +4629,17 @@ version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcc5b895a6377f1ab9fa55acedab1fd5ac0db66ad1e6c7f47e28a22e446a5dd"
|
||||
dependencies = [
|
||||
"windows-result",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4641,7 +4650,7 @@ checksum = "12168c33176773b86799be25e2a2ba07c7aab9968b37541f1094dbd7a60c8946"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4652,7 +4661,16 @@ checksum = "9d8dc32e0095a7eeccebd0e3f09e9509365ecb3fc6ac4d6f5f14a3f6392942d1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.49",
|
||||
"syn 2.0.51",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd19df78e5168dfb0aedc343d1d1b8d422ab2db6756d2dc3fef75035402a3f64"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4679,7 +4697,7 @@ version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4714,17 +4732,17 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
||||
checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.0",
|
||||
"windows_aarch64_msvc 0.52.0",
|
||||
"windows_i686_gnu 0.52.0",
|
||||
"windows_i686_msvc 0.52.0",
|
||||
"windows_x86_64_gnu 0.52.0",
|
||||
"windows_x86_64_gnullvm 0.52.0",
|
||||
"windows_x86_64_msvc 0.52.0",
|
||||
"windows_aarch64_gnullvm 0.52.3",
|
||||
"windows_aarch64_msvc 0.52.3",
|
||||
"windows_i686_gnu 0.52.3",
|
||||
"windows_i686_msvc 0.52.3",
|
||||
"windows_x86_64_gnu 0.52.3",
|
||||
"windows_x86_64_gnullvm 0.52.3",
|
||||
"windows_x86_64_msvc 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4733,7 +4751,7 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75aa004c988e080ad34aff5739c39d0312f4684699d6d71fc8a198d057b8b9b4"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4750,9 +4768,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
||||
checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
@ -4768,9 +4786,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
||||
checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
@ -4786,9 +4804,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
||||
checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
@ -4804,9 +4822,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
||||
checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
@ -4822,9 +4840,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
||||
checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
@ -4840,9 +4858,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
||||
checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
@ -4858,9 +4876,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
||||
checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
|
@ -278,10 +278,10 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
let ext = tray_icon_icon_path.extension();
|
||||
if ext.map_or(false, |e| e == "ico") {
|
||||
ico_icon(&root, &out_dir, tray_icon_icon_path)
|
||||
.map(|i| quote!(context.set_tray_icon(#i);))?
|
||||
.map(|i| quote!(context.set_tray_icon(Some(#i));))?
|
||||
} else if ext.map_or(false, |e| e == "png") {
|
||||
png_icon(&root, &out_dir, tray_icon_icon_path)
|
||||
.map(|i| quote!(context.set_tray_icon(#i);))?
|
||||
.map(|i| quote!(context.set_tray_icon(Some(#i));))?
|
||||
} else {
|
||||
quote!(compile_error!(
|
||||
"The tray icon extension must be either `.ico` or `.png`."
|
||||
@ -486,11 +486,7 @@ fn ico_icon<P: AsRef<Path>>(
|
||||
})?;
|
||||
|
||||
let icon_file_name = icon_file_name.to_str().unwrap();
|
||||
let icon = quote!(#root::Icon::Rgba {
|
||||
rgba: include_bytes!(concat!(std::env!("OUT_DIR"), "/", #icon_file_name)).to_vec(),
|
||||
width: #width,
|
||||
height: #height
|
||||
});
|
||||
let icon = quote!(#root::Image::new(include_bytes!(concat!(std::env!("OUT_DIR"), "/", #icon_file_name)), #width, #height));
|
||||
Ok(icon)
|
||||
}
|
||||
|
||||
@ -548,11 +544,7 @@ fn png_icon<P: AsRef<Path>>(
|
||||
})?;
|
||||
|
||||
let icon_file_name = icon_file_name.to_str().unwrap();
|
||||
let icon = quote!(#root::Icon::Rgba {
|
||||
rgba: include_bytes!(concat!(std::env!("OUT_DIR"), "/", #icon_file_name)).to_vec(),
|
||||
width: #width,
|
||||
height: #height,
|
||||
});
|
||||
let icon = quote!(#root::Image::new(include_bytes!(concat!(std::env!("OUT_DIR"), "/", #icon_file_name)), #width, #height));
|
||||
Ok(icon)
|
||||
}
|
||||
|
||||
|
@ -22,4 +22,5 @@ mod runtime;
|
||||
pub use build::*;
|
||||
#[cfg(feature = "runtime")]
|
||||
#[cfg_attr(docsrs, doc(feature = "runtime"))]
|
||||
#[allow(unused)]
|
||||
pub use runtime::*;
|
||||
|
@ -418,16 +418,12 @@ impl From<DeviceEventFilter> for DeviceEventFilterWrapper {
|
||||
/// Wrapper around a [`tao::window::Icon`] that can be created from an [`Icon`].
|
||||
pub struct TaoIcon(pub TaoWindowIcon);
|
||||
|
||||
fn icon_err<E: std::error::Error + Send + Sync + 'static>(e: E) -> Error {
|
||||
Error::InvalidIcon(Box::new(e))
|
||||
}
|
||||
|
||||
impl TryFrom<Icon> for TaoIcon {
|
||||
impl TryFrom<Icon<'_>> for TaoIcon {
|
||||
type Error = Error;
|
||||
fn try_from(icon: Icon) -> std::result::Result<Self, Self::Error> {
|
||||
TaoWindowIcon::from_rgba(icon.rgba, icon.width, icon.height)
|
||||
fn try_from(icon: Icon<'_>) -> std::result::Result<Self, Self::Error> {
|
||||
TaoWindowIcon::from_rgba(icon.rgba.to_vec(), icon.width, icon.height)
|
||||
.map(Self)
|
||||
.map_err(icon_err)
|
||||
.map_err(|e| Error::InvalidIcon(Box::new(e)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
use raw_window_handle::DisplayHandle;
|
||||
use serde::Deserialize;
|
||||
use std::{fmt::Debug, sync::mpsc::Sender};
|
||||
use std::{borrow::Cow, fmt::Debug, sync::mpsc::Sender};
|
||||
use tauri_utils::Theme;
|
||||
use url::Url;
|
||||
use webview::{DetachedWebview, PendingWebview};
|
||||
@ -162,9 +162,9 @@ pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Window icon.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Icon {
|
||||
pub struct Icon<'a> {
|
||||
/// RGBA bytes of the icon.
|
||||
pub rgba: Vec<u8>,
|
||||
pub rgba: Cow<'a, [u8]>,
|
||||
/// Icon width.
|
||||
pub width: u32,
|
||||
/// Icon height.
|
||||
|
@ -21,7 +21,7 @@ features = [
|
||||
"custom-protocol",
|
||||
"tray-icon",
|
||||
"devtools",
|
||||
"icon-png",
|
||||
"image-png",
|
||||
"protocol-asset",
|
||||
"test"
|
||||
]
|
||||
@ -156,8 +156,8 @@ webview-data-url = [ "data-url" ]
|
||||
protocol-asset = [ "http-range" ]
|
||||
config-json5 = [ "tauri-macros/config-json5" ]
|
||||
config-toml = [ "tauri-macros/config-toml" ]
|
||||
icon-ico = [ "infer", "ico" ]
|
||||
icon-png = [ "infer", "png" ]
|
||||
image-ico = [ "ico", "infer" ]
|
||||
image-png = [ "png", "infer" ]
|
||||
macos-proxy = [ "tauri-runtime-wry/macos-proxy" ]
|
||||
|
||||
[[example]]
|
||||
|
@ -20,7 +20,7 @@ use crate::{
|
||||
utils::config::Config,
|
||||
utils::{assets::Assets, Env},
|
||||
webview::PageLoadPayload,
|
||||
Context, DeviceEventFilter, EventLoopMessage, Icon, Manager, Monitor, Runtime, Scopes,
|
||||
Context, DeviceEventFilter, EventLoopMessage, Image, Manager, Monitor, Runtime, Scopes,
|
||||
StateManager, Theme, Webview, WebviewWindowBuilder, Window,
|
||||
};
|
||||
|
||||
@ -633,7 +633,7 @@ macro_rules! shared_app_impl {
|
||||
})
|
||||
}
|
||||
/// Returns the default window icon.
|
||||
pub fn default_window_icon(&self) -> Option<&Icon> {
|
||||
pub fn default_window_icon(&self) -> Option<&Image<'_>> {
|
||||
self.manager.window.default_icon.as_ref()
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ pub enum Error {
|
||||
#[error("invalid glob pattern: {0}")]
|
||||
GlobPattern(#[from] glob::PatternError),
|
||||
/// Error decoding PNG image.
|
||||
#[cfg(feature = "icon-png")]
|
||||
#[cfg(feature = "image-png")]
|
||||
#[error("failed to decode PNG: {0}")]
|
||||
PngDecode(#[from] png::DecodingError),
|
||||
/// The Window's raw handle is invalid for the platform.
|
||||
|
204
core/tauri/src/image.rs
Normal file
204
core/tauri/src/image.rs
Normal file
@ -0,0 +1,204 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::io::{Error, ErrorKind};
|
||||
|
||||
/// An RGBA Image in row-major order from top to bottom.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Image<'a> {
|
||||
rgba: Cow<'a, [u8]>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
}
|
||||
|
||||
impl<'a> Image<'a> {
|
||||
/// Creates a new Image using RGBA data, in row-major order from top to bottom, and with specified width and height.
|
||||
pub const fn new(rgba: &'a [u8], width: u32, height: u32) -> Self {
|
||||
Self {
|
||||
rgba: Cow::Borrowed(rgba),
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new image using the provided png bytes.
|
||||
#[cfg(feature = "image-png")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "image-png")))]
|
||||
pub fn from_png_bytes(bytes: &[u8]) -> std::io::Result<Self> {
|
||||
let decoder = png::Decoder::new(std::io::Cursor::new(bytes));
|
||||
let mut reader = decoder.read_info()?;
|
||||
let mut buffer = Vec::new();
|
||||
while let Ok(Some(row)) = reader.next_row() {
|
||||
buffer.extend(row.data());
|
||||
}
|
||||
Ok(Self {
|
||||
rgba: Cow::Owned(buffer),
|
||||
width: reader.info().width,
|
||||
height: reader.info().height,
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a new image using the provided ico bytes.
|
||||
#[cfg(feature = "image-ico")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "image-ico")))]
|
||||
pub fn from_ico_bytes(bytes: &[u8]) -> std::io::Result<Self> {
|
||||
let icon_dir = ico::IconDir::read(std::io::Cursor::new(&bytes))?;
|
||||
let first = icon_dir.entries().first().ok_or_else(|| {
|
||||
Error::new(
|
||||
ErrorKind::NotFound,
|
||||
"Couldn't find any icons inside provided ico bytes",
|
||||
)
|
||||
})?;
|
||||
|
||||
let rgba = first.decode()?.rgba_data().to_vec();
|
||||
|
||||
Ok(Self {
|
||||
rgba: Cow::Owned(rgba),
|
||||
width: first.width(),
|
||||
height: first.height(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a new image using the provided bytes.
|
||||
///
|
||||
/// Only `ico` and `png` are supported (based on activated feature flag).
|
||||
#[cfg(any(feature = "image-ico", feature = "image-png"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "image-ico", feature = "image-png"))))]
|
||||
pub fn from_bytes(bytes: &[u8]) -> std::io::Result<Self> {
|
||||
let extension = infer::get(bytes)
|
||||
.expect("could not determine icon extension")
|
||||
.extension();
|
||||
|
||||
match extension {
|
||||
#[cfg(feature = "image-ico")]
|
||||
"ico" => Self::from_ico_bytes(bytes),
|
||||
#[cfg(feature = "image-png")]
|
||||
"png" => Self::from_png_bytes(bytes),
|
||||
_ => {
|
||||
let supported = [
|
||||
#[cfg(feature = "image-png")]
|
||||
"'png'",
|
||||
#[cfg(feature = "image-ico")]
|
||||
"'ico'",
|
||||
];
|
||||
|
||||
Err(Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!(
|
||||
"Unexpected image format, expected {}, found '{extension}'. Please check the `image-*` Cargo features on the tauri crate to see if Tauri has optional support for this format.",
|
||||
if supported.is_empty() {
|
||||
"''".to_string()
|
||||
} else {
|
||||
supported.join(" or ")
|
||||
}
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new image using the provided path.
|
||||
///
|
||||
/// Only `ico` and `png` are supported (based on activated feature flag).
|
||||
#[cfg(any(feature = "image-ico", feature = "image-png"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "image-ico", feature = "image-png"))))]
|
||||
pub fn from_path<P: AsRef<std::path::Path>>(path: P) -> std::io::Result<Self> {
|
||||
let bytes = std::fs::read(path)?;
|
||||
Self::from_bytes(&bytes)
|
||||
}
|
||||
|
||||
/// Returns the RGBA data for this image, in row-major order from top to bottom.
|
||||
pub fn rgba(&'a self) -> &'a [u8] {
|
||||
&self.rgba
|
||||
}
|
||||
|
||||
/// Returns the width of this image.
|
||||
pub fn width(&self) -> u32 {
|
||||
self.width
|
||||
}
|
||||
|
||||
/// Returns the height of this image.
|
||||
pub fn height(&self) -> u32 {
|
||||
self.height
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Image<'a>> for crate::runtime::Icon<'a> {
|
||||
fn from(img: Image<'a>) -> Self {
|
||||
Self {
|
||||
rgba: img.rgba,
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(desktop)]
|
||||
impl TryFrom<Image<'_>> for muda::Icon {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(img: Image<'_>) -> Result<Self, Self::Error> {
|
||||
muda::Icon::from_rgba(img.rgba.to_vec(), img.width, img.height).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(desktop, feature = "tray-icon"))]
|
||||
impl TryFrom<Image<'_>> for tray_icon::Icon {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(img: Image<'_>) -> Result<Self, Self::Error> {
|
||||
tray_icon::Icon::from_rgba(img.rgba.to_vec(), img.width, img.height).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(desktop)]
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum JsIcon<'a> {
|
||||
Path(std::path::PathBuf),
|
||||
Bytes(&'a [u8]),
|
||||
Rgba {
|
||||
rgba: &'a [u8],
|
||||
width: u32,
|
||||
height: u32,
|
||||
},
|
||||
}
|
||||
|
||||
#[cfg(desktop)]
|
||||
impl<'a> TryFrom<JsIcon<'a>> for Image<'a> {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(img: JsIcon<'a>) -> Result<Self, Self::Error> {
|
||||
match img {
|
||||
#[cfg(any(feature = "image-ico", feature = "image-png"))]
|
||||
JsIcon::Path(path) => Self::from_path(path).map_err(Into::into),
|
||||
|
||||
#[cfg(any(feature = "image-ico", feature = "image-png"))]
|
||||
JsIcon::Bytes(bytes) => Self::from_bytes(bytes).map_err(Into::into),
|
||||
|
||||
JsIcon::Rgba {
|
||||
rgba,
|
||||
width,
|
||||
height,
|
||||
} => Ok(Self::new(rgba, width, height)),
|
||||
|
||||
#[cfg(not(any(feature = "image-ico", feature = "image-png")))]
|
||||
_ => Err(
|
||||
Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!(
|
||||
"expected RGBA image data, found {}",
|
||||
match img {
|
||||
JsIcon::Path(_) => "a file path",
|
||||
JsIcon::Bytes(_) => "raw bytes",
|
||||
_ => unreachable!(),
|
||||
}
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
@ -34,8 +34,8 @@
|
||||
//! - **compression** *(enabled by default): Enables asset compression. You should only disable this if you want faster compile times in release builds - it produces larger binaries.
|
||||
//! - **config-json5**: Adds support to JSON5 format for `tauri.conf.json`.
|
||||
//! - **config-toml**: Adds support to TOML format for the configuration `Tauri.toml`.
|
||||
//! - **icon-ico**: Adds support to set `.ico` window icons. Enables [`Icon::File`] and [`Icon::Raw`] variants.
|
||||
//! - **icon-png**: Adds support to set `.png` window icons. Enables [`Icon::File`] and [`Icon::Raw`] variants.
|
||||
//! - **image-ico**: Adds support to parse `.ico` image, see [`Image`].
|
||||
//! - **image-png**: Adds support to parse `.png` image, see [`Image`].
|
||||
//! - **macos-proxy**: Adds support for [`WebviewBuilder::proxy_url`] on macOS. Requires macOS 14+.
|
||||
//!
|
||||
//! ## Cargo allowlist features
|
||||
@ -94,6 +94,7 @@ mod vibrancy;
|
||||
pub mod webview;
|
||||
pub mod window;
|
||||
use tauri_runtime as runtime;
|
||||
mod image;
|
||||
#[cfg(target_os = "ios")]
|
||||
mod ios;
|
||||
#[cfg(desktop)]
|
||||
@ -188,7 +189,7 @@ pub use tauri_runtime_wry::{tao, wry};
|
||||
/// A task to run on the main thread.
|
||||
pub type SyncTask = Box<dyn FnOnce() + Send>;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::{self, Debug},
|
||||
@ -211,6 +212,7 @@ pub use {
|
||||
self::app::{
|
||||
App, AppHandle, AssetResolver, Builder, CloseRequestApi, RunEvent, WebviewEvent, WindowEvent,
|
||||
},
|
||||
self::image::Image,
|
||||
self::manager::Asset,
|
||||
self::runtime::{
|
||||
webview::WebviewAttributes,
|
||||
@ -331,92 +333,6 @@ macro_rules! tauri_build_context {
|
||||
|
||||
pub use pattern::Pattern;
|
||||
|
||||
/// A icon definition.
|
||||
#[derive(Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum Icon {
|
||||
/// Icon from file path.
|
||||
#[cfg(any(feature = "icon-ico", feature = "icon-png"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
|
||||
File(std::path::PathBuf),
|
||||
/// Icon from raw RGBA bytes. Width and height is parsed at runtime.
|
||||
#[cfg(any(feature = "icon-ico", feature = "icon-png"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "icon-ico", feature = "icon-png"))))]
|
||||
Raw(Vec<u8>),
|
||||
/// Icon from raw RGBA bytes.
|
||||
Rgba {
|
||||
/// RGBA bytes of the icon image.
|
||||
rgba: Vec<u8>,
|
||||
/// Icon width.
|
||||
width: u32,
|
||||
/// Icon height.
|
||||
height: u32,
|
||||
},
|
||||
}
|
||||
|
||||
impl TryFrom<Icon> for runtime::Icon {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(icon: Icon) -> Result<Self> {
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
if let Icon::Rgba {
|
||||
rgba,
|
||||
width,
|
||||
height,
|
||||
} = icon
|
||||
{
|
||||
Ok(Self {
|
||||
rgba,
|
||||
width,
|
||||
height,
|
||||
})
|
||||
} else {
|
||||
#[cfg(not(any(feature = "icon-ico", feature = "icon-png")))]
|
||||
panic!("unexpected Icon variant");
|
||||
#[cfg(any(feature = "icon-ico", feature = "icon-png"))]
|
||||
{
|
||||
let bytes = match icon {
|
||||
Icon::File(p) => std::fs::read(p)?,
|
||||
Icon::Raw(r) => r,
|
||||
Icon::Rgba { .. } => unreachable!(),
|
||||
};
|
||||
let extension = infer::get(&bytes)
|
||||
.expect("could not determine icon extension")
|
||||
.extension();
|
||||
match extension {
|
||||
#[cfg(feature = "icon-ico")]
|
||||
"ico" => {
|
||||
let icon_dir = ico::IconDir::read(std::io::Cursor::new(bytes))?;
|
||||
let entry = &icon_dir.entries()[0];
|
||||
Ok(Self {
|
||||
rgba: entry.decode()?.rgba_data().to_vec(),
|
||||
width: entry.width(),
|
||||
height: entry.height(),
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "icon-png")]
|
||||
"png" => {
|
||||
let decoder = png::Decoder::new(std::io::Cursor::new(bytes));
|
||||
let mut reader = decoder.read_info()?;
|
||||
let mut buffer = Vec::new();
|
||||
while let Ok(Some(row)) = reader.next_row() {
|
||||
buffer.extend(row.data());
|
||||
}
|
||||
Ok(Self {
|
||||
rgba: buffer,
|
||||
width: reader.info().width,
|
||||
height: reader.info().height,
|
||||
})
|
||||
}
|
||||
_ => panic!(
|
||||
"image `{extension}` extension not supported; please file a Tauri feature request. `png` or `ico` icons are supported with the `icon-png` and `icon-ico` feature flags"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// User supplied data required inside of a Tauri application.
|
||||
///
|
||||
/// # Stability
|
||||
@ -425,10 +341,10 @@ impl TryFrom<Icon> for runtime::Icon {
|
||||
pub struct Context<A: Assets> {
|
||||
pub(crate) config: Config,
|
||||
pub(crate) assets: Box<A>,
|
||||
pub(crate) default_window_icon: Option<Icon>,
|
||||
pub(crate) default_window_icon: Option<Image<'static>>,
|
||||
pub(crate) app_icon: Option<Vec<u8>>,
|
||||
#[cfg(all(desktop, feature = "tray-icon"))]
|
||||
pub(crate) tray_icon: Option<Icon>,
|
||||
pub(crate) tray_icon: Option<Image<'static>>,
|
||||
pub(crate) package_info: PackageInfo,
|
||||
pub(crate) _info_plist: (),
|
||||
pub(crate) pattern: Pattern,
|
||||
@ -478,30 +394,30 @@ impl<A: Assets> Context<A> {
|
||||
|
||||
/// The default window icon Tauri should use when creating windows.
|
||||
#[inline(always)]
|
||||
pub fn default_window_icon(&self) -> Option<&Icon> {
|
||||
pub fn default_window_icon(&self) -> Option<&Image<'_>> {
|
||||
self.default_window_icon.as_ref()
|
||||
}
|
||||
|
||||
/// A mutable reference to the default window icon Tauri should use when creating windows.
|
||||
/// Set the default window icon Tauri should use when creating windows.
|
||||
#[inline(always)]
|
||||
pub fn default_window_icon_mut(&mut self) -> &mut Option<Icon> {
|
||||
&mut self.default_window_icon
|
||||
pub fn set_default_window_icon(&mut self, icon: Option<Image<'static>>) {
|
||||
self.default_window_icon = icon;
|
||||
}
|
||||
|
||||
/// The icon to use on the system tray UI.
|
||||
/// The icon to use on the tray icon.
|
||||
#[cfg(all(desktop, feature = "tray-icon"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
|
||||
#[inline(always)]
|
||||
pub fn tray_icon(&self) -> Option<&Icon> {
|
||||
pub fn tray_icon(&self) -> Option<&Image<'_>> {
|
||||
self.tray_icon.as_ref()
|
||||
}
|
||||
|
||||
/// A mutable reference to the icon to use on the tray icon.
|
||||
/// Set the icon to use on the tray icon.
|
||||
#[cfg(all(desktop, feature = "tray-icon"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
|
||||
#[inline(always)]
|
||||
pub fn tray_icon_mut(&mut self) -> &mut Option<Icon> {
|
||||
&mut self.tray_icon
|
||||
pub fn set_tray_icon(&mut self, icon: Option<Image<'static>>) {
|
||||
self.tray_icon = icon;
|
||||
}
|
||||
|
||||
/// Package information.
|
||||
@ -539,7 +455,7 @@ impl<A: Assets> Context<A> {
|
||||
pub fn new(
|
||||
config: Config,
|
||||
assets: Box<A>,
|
||||
default_window_icon: Option<Icon>,
|
||||
default_window_icon: Option<Image<'static>>,
|
||||
app_icon: Option<Vec<u8>>,
|
||||
package_info: PackageInfo,
|
||||
info_plist: (),
|
||||
@ -560,14 +476,6 @@ impl<A: Assets> Context<A> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the app tray icon.
|
||||
#[cfg(all(desktop, feature = "tray-icon"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(all(desktop, feature = "tray-icon"))))]
|
||||
#[inline(always)]
|
||||
pub fn set_tray_icon(&mut self, icon: Icon) {
|
||||
self.tray_icon.replace(icon);
|
||||
}
|
||||
|
||||
/// Sets the app shell scope.
|
||||
#[cfg(shell_scope)]
|
||||
#[inline(always)]
|
||||
@ -1017,40 +925,6 @@ pub(crate) mod sealed {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub(crate) enum IconDto {
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
File(std::path::PathBuf),
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
Raw(Vec<u8>),
|
||||
Rgba {
|
||||
rgba: Vec<u8>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<IconDto> for Icon {
|
||||
fn from(icon: IconDto) -> Self {
|
||||
match icon {
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
IconDto::File(path) => Self::File(path),
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
IconDto::Raw(raw) => Self::Raw(raw),
|
||||
IconDto::Rgba {
|
||||
rgba,
|
||||
width,
|
||||
height,
|
||||
} => Self::Rgba {
|
||||
rgba,
|
||||
width,
|
||||
height,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
macro_rules! run_main_thread {
|
||||
($handle:ident, $ex:expr) => {{
|
||||
|
@ -7,11 +7,11 @@ use std::{collections::HashMap, fmt, sync::Mutex};
|
||||
use crate::{
|
||||
app::GlobalTrayIconEventListener,
|
||||
tray::{TrayIcon, TrayIconId},
|
||||
AppHandle, Icon, Runtime,
|
||||
AppHandle, Image, Runtime,
|
||||
};
|
||||
|
||||
pub struct TrayManager<R: Runtime> {
|
||||
pub(crate) icon: Option<Icon>,
|
||||
pub(crate) icon: Option<Image<'static>>,
|
||||
/// Tray icons
|
||||
pub(crate) icons: Mutex<Vec<TrayIcon<R>>>,
|
||||
/// Global Tray icon event listeners.
|
||||
|
@ -20,7 +20,7 @@ use tauri_runtime::{
|
||||
|
||||
use crate::{
|
||||
app::GlobalWindowEventListener, sealed::ManagerBase, AppHandle, EventLoopMessage, EventTarget,
|
||||
Icon, Manager, Runtime, Scopes, Window, WindowEvent,
|
||||
Image, Manager, Runtime, Scopes, Window, WindowEvent,
|
||||
};
|
||||
|
||||
const WINDOW_RESIZED_EVENT: &str = "tauri://resize";
|
||||
@ -37,7 +37,7 @@ pub const DROP_CANCELLED_EVENT: &str = "tauri://file-drop-cancelled";
|
||||
|
||||
pub struct WindowManager<R: Runtime> {
|
||||
pub windows: Mutex<HashMap<String, Window<R>>>,
|
||||
pub default_icon: Option<Icon>,
|
||||
pub default_icon: Option<Image<'static>>,
|
||||
/// Window event listeners to all windows.
|
||||
pub event_listeners: Arc<Vec<GlobalWindowEventListener<R>>>,
|
||||
}
|
||||
@ -66,9 +66,7 @@ impl<R: Runtime> WindowManager<R> {
|
||||
|
||||
if !pending.window_builder.has_icon() {
|
||||
if let Some(default_window_icon) = self.default_icon.clone() {
|
||||
pending.window_builder = pending
|
||||
.window_builder
|
||||
.icon(default_window_icon.try_into()?)?;
|
||||
pending.window_builder = pending.window_builder.icon(default_window_icon.into())?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,20 +4,20 @@
|
||||
|
||||
use crate::{
|
||||
menu::{IconMenuItem, MenuId, NativeIcon},
|
||||
Icon, Manager, Runtime,
|
||||
Image, Manager, Runtime,
|
||||
};
|
||||
|
||||
/// A builder type for [`IconMenuItem`]
|
||||
pub struct IconMenuItemBuilder {
|
||||
pub struct IconMenuItemBuilder<'a> {
|
||||
id: Option<MenuId>,
|
||||
text: String,
|
||||
enabled: bool,
|
||||
icon: Option<Icon>,
|
||||
icon: Option<Image<'a>>,
|
||||
native_icon: Option<NativeIcon>,
|
||||
accelerator: Option<String>,
|
||||
}
|
||||
|
||||
impl IconMenuItemBuilder {
|
||||
impl<'a> IconMenuItemBuilder<'a> {
|
||||
/// Create a new menu item builder.
|
||||
///
|
||||
/// - `text` could optionally contain an `&` before a character to assign this character as the mnemonic
|
||||
@ -70,7 +70,7 @@ impl IconMenuItemBuilder {
|
||||
///
|
||||
/// **Note:** This method conflicts with [`Self::native_icon`]
|
||||
/// so calling one of them, will reset the other.
|
||||
pub fn icon(mut self, icon: Icon) -> Self {
|
||||
pub fn icon(mut self, icon: Image<'a>) -> Self {
|
||||
self.icon.replace(icon);
|
||||
self.native_icon = None;
|
||||
self
|
||||
|
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use crate::{menu::*, Icon, Manager, Runtime};
|
||||
use crate::{menu::*, Image, Manager, Runtime};
|
||||
|
||||
/// A builder type for [`Menu`]
|
||||
///
|
||||
@ -13,11 +13,7 @@ use crate::{menu::*, Icon, Manager, Runtime};
|
||||
/// tauri::Builder::default()
|
||||
/// .setup(move |app| {
|
||||
/// let handle = app.handle();
|
||||
/// # let icon1 = tauri::Icon::Rgba {
|
||||
/// # rgba: Vec::new(),
|
||||
/// # width: 0,
|
||||
/// # height: 0,
|
||||
/// # };
|
||||
/// # let icon1 = tauri::Image::new(&[], 0, 0);
|
||||
/// let menu = MenuBuilder::new(handle)
|
||||
/// .item(&MenuItem::new(handle, "MenuItem 1", true, None::<&str>)?)
|
||||
/// .items(&[
|
||||
@ -99,7 +95,7 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
|
||||
}
|
||||
|
||||
/// Add an [IconMenuItem] to the menu.
|
||||
pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Icon) -> Self {
|
||||
pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Image<'_>) -> Self {
|
||||
self.items.push(
|
||||
IconMenuItem::with_id(self.manager, id, text, true, Some(icon), None::<&str>)
|
||||
.map(|i| i.kind()),
|
||||
@ -285,7 +281,7 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
|
||||
}
|
||||
|
||||
/// Add About app menu item to the menu.
|
||||
pub fn about(mut self, metadata: Option<AboutMetadata>) -> Self {
|
||||
pub fn about(mut self, metadata: Option<AboutMetadata<'_>>) -> Self {
|
||||
self
|
||||
.items
|
||||
.push(PredefinedMenuItem::about(self.manager, None, metadata).map(|i| i.kind()));
|
||||
|
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use crate::{menu::*, Icon, Manager, Runtime};
|
||||
use crate::{menu::*, Image, Manager, Runtime};
|
||||
|
||||
/// A builder type for [`Submenu`]
|
||||
///
|
||||
@ -13,11 +13,7 @@ use crate::{menu::*, Icon, Manager, Runtime};
|
||||
/// tauri::Builder::default()
|
||||
/// .setup(move |app| {
|
||||
/// let handle = app.handle();
|
||||
/// # let icon1 = tauri::Icon::Rgba {
|
||||
/// # rgba: Vec::new(),
|
||||
/// # width: 0,
|
||||
/// # height: 0,
|
||||
/// # };
|
||||
/// # let icon1 = tauri::Image::new(&[], 0, 0);
|
||||
/// # let icon2 = icon1.clone();
|
||||
/// let menu = Menu::new(handle)?;
|
||||
/// let submenu = SubmenuBuilder::new(handle, "File")
|
||||
@ -120,7 +116,7 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
|
||||
}
|
||||
|
||||
/// Add an [IconMenuItem] to the submenu.
|
||||
pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Icon) -> Self {
|
||||
pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Image<'_>) -> Self {
|
||||
self.items.push(
|
||||
IconMenuItem::with_id(self.manager, id, text, true, Some(icon), None::<&str>)
|
||||
.map(|i| i.kind()),
|
||||
@ -306,7 +302,7 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
|
||||
}
|
||||
|
||||
/// Add About app menu item to the submenu.
|
||||
pub fn about(mut self, metadata: Option<AboutMetadata>) -> Self {
|
||||
pub fn about(mut self, metadata: Option<AboutMetadata<'_>>) -> Self {
|
||||
self
|
||||
.items
|
||||
.push(PredefinedMenuItem::about(self.manager, None, metadata).map(|i| i.kind()));
|
||||
|
@ -8,7 +8,7 @@ use super::run_item_main_thread;
|
||||
use super::{IconMenuItem, NativeIcon};
|
||||
use crate::menu::IconMenuItemInner;
|
||||
use crate::run_main_thread;
|
||||
use crate::{menu::MenuId, AppHandle, Icon, Manager, Runtime};
|
||||
use crate::{menu::MenuId, AppHandle, Image, Manager, Runtime};
|
||||
|
||||
impl<R: Runtime> IconMenuItem<R> {
|
||||
/// Create a new menu item.
|
||||
@ -19,7 +19,7 @@ impl<R: Runtime> IconMenuItem<R> {
|
||||
manager: &M,
|
||||
text: T,
|
||||
enabled: bool,
|
||||
icon: Option<Icon>,
|
||||
icon: Option<Image<'_>>,
|
||||
accelerator: Option<A>,
|
||||
) -> crate::Result<Self>
|
||||
where
|
||||
@ -31,8 +31,11 @@ impl<R: Runtime> IconMenuItem<R> {
|
||||
let app_handle = handle.clone();
|
||||
|
||||
let text = text.as_ref().to_owned();
|
||||
let icon = icon.and_then(|i| i.try_into().ok());
|
||||
let accelerator = accelerator.and_then(|s| s.as_ref().parse().ok());
|
||||
let icon = match icon {
|
||||
Some(i) => Some(i.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let item = run_main_thread!(handle, || {
|
||||
let item = muda::IconMenuItem::new(text, enabled, icon, accelerator);
|
||||
@ -55,7 +58,7 @@ impl<R: Runtime> IconMenuItem<R> {
|
||||
id: I,
|
||||
text: T,
|
||||
enabled: bool,
|
||||
icon: Option<Icon>,
|
||||
icon: Option<Image<'_>>,
|
||||
accelerator: Option<A>,
|
||||
) -> crate::Result<Self>
|
||||
where
|
||||
@ -69,8 +72,11 @@ impl<R: Runtime> IconMenuItem<R> {
|
||||
|
||||
let id = id.into();
|
||||
let text = text.as_ref().to_owned();
|
||||
let icon = icon.and_then(|i| i.try_into().ok());
|
||||
let accelerator = accelerator.and_then(|s| s.as_ref().parse().ok());
|
||||
let icon = match icon {
|
||||
Some(i) => Some(i.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let item = run_main_thread!(handle, || {
|
||||
let item = muda::IconMenuItem::with_id(id.clone(), text, enabled, icon, accelerator);
|
||||
@ -207,10 +213,12 @@ impl<R: Runtime> IconMenuItem<R> {
|
||||
}
|
||||
|
||||
/// Change this menu item icon or remove it.
|
||||
pub fn set_icon(&self, icon: Option<Icon>) -> crate::Result<()> {
|
||||
run_item_main_thread!(self, |self_: Self| (*self_.0)
|
||||
.as_ref()
|
||||
.set_icon(icon.and_then(|i| i.try_into().ok())))
|
||||
pub fn set_icon(&self, icon: Option<Image<'_>>) -> crate::Result<()> {
|
||||
let icon = match icon {
|
||||
Some(i) => Some(i.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
run_item_main_thread!(self, |self_: Self| (*self_.0).as_ref().set_icon(icon))
|
||||
}
|
||||
|
||||
/// Change this menu item icon to a native image or remove it.
|
||||
|
@ -21,7 +21,7 @@ pub use builders::*;
|
||||
pub use menu::{HELP_SUBMENU_ID, WINDOW_SUBMENU_ID};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{AppHandle, Icon, Runtime};
|
||||
use crate::{AppHandle, Image, Runtime};
|
||||
pub use muda::MenuId;
|
||||
|
||||
macro_rules! run_item_main_thread {
|
||||
@ -166,7 +166,7 @@ gen_wrappers!(
|
||||
|
||||
/// Application metadata for the [`PredefinedMenuItem::about`].
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct AboutMetadata {
|
||||
pub struct AboutMetadata<'a> {
|
||||
/// Sets the application name.
|
||||
pub name: Option<String>,
|
||||
/// The application version.
|
||||
@ -220,14 +220,14 @@ pub struct AboutMetadata {
|
||||
/// ## Platform-specific
|
||||
///
|
||||
/// - **Windows:** Unsupported.
|
||||
pub icon: Option<Icon>,
|
||||
pub icon: Option<Image<'a>>,
|
||||
}
|
||||
|
||||
/// A builder type for [`AboutMetadata`].
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct AboutMetadataBuilder(AboutMetadata);
|
||||
pub struct AboutMetadataBuilder<'a>(AboutMetadata<'a>);
|
||||
|
||||
impl AboutMetadataBuilder {
|
||||
impl<'a> AboutMetadataBuilder<'a> {
|
||||
/// Create a new about metdata builder.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
@ -316,20 +316,27 @@ impl AboutMetadataBuilder {
|
||||
/// ## Platform-specific
|
||||
///
|
||||
/// - **Windows:** Unsupported.
|
||||
pub fn icon(mut self, icon: Option<Icon>) -> Self {
|
||||
pub fn icon(mut self, icon: Option<Image<'a>>) -> Self {
|
||||
self.0.icon = icon;
|
||||
self
|
||||
}
|
||||
|
||||
/// Construct the final [`AboutMetadata`]
|
||||
pub fn build(self) -> AboutMetadata {
|
||||
pub fn build(self) -> AboutMetadata<'a> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AboutMetadata> for muda::AboutMetadata {
|
||||
fn from(value: AboutMetadata) -> Self {
|
||||
Self {
|
||||
impl TryFrom<AboutMetadata<'_>> for muda::AboutMetadata {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: AboutMetadata<'_>) -> Result<Self, Self::Error> {
|
||||
let icon = match value.icon {
|
||||
Some(i) => Some(i.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
authors: value.authors,
|
||||
name: value.name,
|
||||
version: value.version,
|
||||
@ -340,8 +347,8 @@ impl From<AboutMetadata> for muda::AboutMetadata {
|
||||
website: value.website,
|
||||
website_label: value.website_label,
|
||||
credits: value.credits,
|
||||
icon: value.icon.and_then(|i| i.try_into().ok()),
|
||||
}
|
||||
icon,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -756,15 +763,6 @@ pub(crate) mod sealed {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::Icon> for muda::Icon {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: crate::Icon) -> Result<Self, Self::Error> {
|
||||
let value: crate::runtime::Icon = value.try_into()?;
|
||||
muda::Icon::from_rgba(value.rgba, value.width, value.height).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn into_logical_position<P: crate::Pixel>(
|
||||
p: crate::LogicalPosition<P>,
|
||||
) -> muda::LogicalPosition<P> {
|
||||
|
@ -13,11 +13,12 @@ use tauri_runtime::window::dpi::Position;
|
||||
use super::{sealed::ContextMenuBase, *};
|
||||
use crate::{
|
||||
command,
|
||||
image::JsIcon,
|
||||
ipc::{channel::JavaScriptChannelId, Channel},
|
||||
plugin::{Builder, TauriPlugin},
|
||||
resources::{ResourceId, ResourceTable},
|
||||
sealed::ManagerBase,
|
||||
AppHandle, IconDto, Manager, RunEvent, Runtime, State, Webview, Window,
|
||||
AppHandle, Manager, RunEvent, Runtime, State, Webview, Window,
|
||||
};
|
||||
use tauri_macros::do_menu_item;
|
||||
|
||||
@ -33,7 +34,7 @@ pub(crate) enum ItemKind {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct AboutMetadata {
|
||||
pub(crate) struct AboutMetadata<'a> {
|
||||
pub name: Option<String>,
|
||||
pub version: Option<String>,
|
||||
pub short_version: Option<String>,
|
||||
@ -44,12 +45,20 @@ pub(crate) struct AboutMetadata {
|
||||
pub website: Option<String>,
|
||||
pub website_label: Option<String>,
|
||||
pub credits: Option<String>,
|
||||
pub icon: Option<IconDto>,
|
||||
#[serde(borrow)]
|
||||
pub icon: Option<JsIcon<'a>>,
|
||||
}
|
||||
|
||||
impl From<AboutMetadata> for super::AboutMetadata {
|
||||
fn from(value: AboutMetadata) -> Self {
|
||||
Self {
|
||||
impl<'a> TryFrom<AboutMetadata<'a>> for super::AboutMetadata<'a> {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: AboutMetadata<'a>) -> Result<Self, Self::Error> {
|
||||
let icon = match value.icon {
|
||||
Some(i) => Some(i.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
name: value.name,
|
||||
version: value.version,
|
||||
short_version: value.short_version,
|
||||
@ -60,14 +69,14 @@ impl From<AboutMetadata> for super::AboutMetadata {
|
||||
website: value.website,
|
||||
website_label: value.website_label,
|
||||
credits: value.credits,
|
||||
icon: value.icon.map(Into::into),
|
||||
}
|
||||
icon,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Deserialize)]
|
||||
enum Predefined {
|
||||
enum Predefined<'a> {
|
||||
Separator,
|
||||
Copy,
|
||||
Cut,
|
||||
@ -83,19 +92,21 @@ enum Predefined {
|
||||
ShowAll,
|
||||
CloseWindow,
|
||||
Quit,
|
||||
About(Option<AboutMetadata>),
|
||||
#[serde(borrow)]
|
||||
About(Option<AboutMetadata<'a>>),
|
||||
Services,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SubmenuPayload {
|
||||
struct SubmenuPayload<'a> {
|
||||
id: Option<MenuId>,
|
||||
text: String,
|
||||
enabled: Option<bool>,
|
||||
items: Vec<MenuItemPayloadKind>,
|
||||
#[serde(borrow)]
|
||||
items: Vec<MenuItemPayloadKind<'a>>,
|
||||
}
|
||||
|
||||
impl SubmenuPayload {
|
||||
impl<'a> SubmenuPayload<'a> {
|
||||
pub fn create_item<R: Runtime>(
|
||||
self,
|
||||
webview: &Webview<R>,
|
||||
@ -159,23 +170,25 @@ impl CheckMenuItemPayload {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Icon {
|
||||
enum Icon<'a> {
|
||||
Native(NativeIcon),
|
||||
Icon(IconDto),
|
||||
#[serde(borrow)]
|
||||
Icon(JsIcon<'a>),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct IconMenuItemPayload {
|
||||
struct IconMenuItemPayload<'a> {
|
||||
handler: Option<JavaScriptChannelId>,
|
||||
id: Option<MenuId>,
|
||||
text: String,
|
||||
icon: Icon,
|
||||
#[serde(borrow)]
|
||||
icon: Icon<'a>,
|
||||
enabled: Option<bool>,
|
||||
accelerator: Option<String>,
|
||||
}
|
||||
|
||||
impl IconMenuItemPayload {
|
||||
impl<'a> IconMenuItemPayload<'a> {
|
||||
pub fn create_item<R: Runtime>(self, webview: &Webview<R>) -> crate::Result<IconMenuItem<R>> {
|
||||
let mut builder = if let Some(id) = self.id {
|
||||
IconMenuItemBuilder::with_id(id, self.text)
|
||||
@ -190,7 +203,7 @@ impl IconMenuItemPayload {
|
||||
}
|
||||
builder = match self.icon {
|
||||
Icon::Native(native_icon) => builder.native_icon(native_icon),
|
||||
Icon::Icon(icon) => builder.icon(icon.into()),
|
||||
Icon::Icon(icon) => builder.icon(icon.try_into()?),
|
||||
};
|
||||
|
||||
let item = builder.build(webview)?;
|
||||
@ -249,12 +262,13 @@ impl MenuItemPayload {
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PredefinedMenuItemPayload {
|
||||
item: Predefined,
|
||||
struct PredefinedMenuItemPayload<'a> {
|
||||
#[serde(borrow)]
|
||||
item: Predefined<'a>,
|
||||
text: Option<String>,
|
||||
}
|
||||
|
||||
impl PredefinedMenuItemPayload {
|
||||
impl<'a> PredefinedMenuItemPayload<'a> {
|
||||
pub fn create_item<R: Runtime>(
|
||||
self,
|
||||
webview: &Webview<R>,
|
||||
@ -276,7 +290,11 @@ impl PredefinedMenuItemPayload {
|
||||
Predefined::CloseWindow => PredefinedMenuItem::close_window(webview, self.text.as_deref()),
|
||||
Predefined::Quit => PredefinedMenuItem::quit(webview, self.text.as_deref()),
|
||||
Predefined::About(metadata) => {
|
||||
PredefinedMenuItem::about(webview, self.text.as_deref(), metadata.map(Into::into))
|
||||
let metadata = match metadata {
|
||||
Some(m) => Some(m.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
PredefinedMenuItem::about(webview, self.text.as_deref(), metadata)
|
||||
}
|
||||
Predefined::Services => PredefinedMenuItem::services(webview, self.text.as_deref()),
|
||||
}
|
||||
@ -285,16 +303,19 @@ impl PredefinedMenuItemPayload {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum MenuItemPayloadKind {
|
||||
enum MenuItemPayloadKind<'a> {
|
||||
ExistingItem((ResourceId, ItemKind)),
|
||||
Predefined(PredefinedMenuItemPayload),
|
||||
#[serde(borrow)]
|
||||
Predefined(PredefinedMenuItemPayload<'a>),
|
||||
Check(CheckMenuItemPayload),
|
||||
Submenu(SubmenuPayload),
|
||||
Icon(IconMenuItemPayload),
|
||||
#[serde(borrow)]
|
||||
Submenu(SubmenuPayload<'a>),
|
||||
#[serde(borrow)]
|
||||
Icon(IconMenuItemPayload<'a>),
|
||||
MenuItem(MenuItemPayload),
|
||||
}
|
||||
|
||||
impl MenuItemPayloadKind {
|
||||
impl<'a> MenuItemPayloadKind<'a> {
|
||||
pub fn with_item<T, R: Runtime, F: FnOnce(&dyn IsMenuItem<R>) -> crate::Result<T>>(
|
||||
self,
|
||||
webview: &Webview<R>,
|
||||
@ -316,16 +337,18 @@ impl MenuItemPayloadKind {
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct NewOptions {
|
||||
struct NewOptions<'a> {
|
||||
id: Option<MenuId>,
|
||||
text: Option<String>,
|
||||
enabled: Option<bool>,
|
||||
checked: Option<bool>,
|
||||
accelerator: Option<String>,
|
||||
#[serde(rename = "item")]
|
||||
predefined_item: Option<Predefined>,
|
||||
icon: Option<Icon>,
|
||||
items: Option<Vec<MenuItemPayloadKind>>,
|
||||
#[serde(borrow, rename = "item")]
|
||||
predefined_item: Option<Predefined<'a>>,
|
||||
#[serde(borrow)]
|
||||
icon: Option<Icon<'a>>,
|
||||
#[serde(borrow)]
|
||||
items: Option<Vec<MenuItemPayloadKind<'a>>>,
|
||||
}
|
||||
|
||||
#[command(root = "crate")]
|
||||
@ -333,7 +356,7 @@ fn new<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
webview: Webview<R>,
|
||||
kind: ItemKind,
|
||||
options: Option<NewOptions>,
|
||||
options: Option<NewOptions<'_>>,
|
||||
channels: State<'_, MenuChannels>,
|
||||
handler: Channel,
|
||||
) -> crate::Result<(ResourceId, MenuId)> {
|
||||
@ -441,7 +464,7 @@ fn append<R: Runtime>(
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
kind: ItemKind,
|
||||
items: Vec<MenuItemPayloadKind>,
|
||||
items: Vec<MenuItemPayloadKind<'_>>,
|
||||
) -> crate::Result<()> {
|
||||
let resources_table = webview.resources_table();
|
||||
match kind {
|
||||
@ -468,7 +491,7 @@ fn prepend<R: Runtime>(
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
kind: ItemKind,
|
||||
items: Vec<MenuItemPayloadKind>,
|
||||
items: Vec<MenuItemPayloadKind<'_>>,
|
||||
) -> crate::Result<()> {
|
||||
let resources_table = webview.resources_table();
|
||||
match kind {
|
||||
@ -495,7 +518,7 @@ fn insert<R: Runtime>(
|
||||
webview: Webview<R>,
|
||||
rid: ResourceId,
|
||||
kind: ItemKind,
|
||||
items: Vec<MenuItemPayloadKind>,
|
||||
items: Vec<MenuItemPayloadKind<'_>>,
|
||||
mut position: usize,
|
||||
) -> crate::Result<()> {
|
||||
let resources_table = webview.resources_table();
|
||||
@ -822,13 +845,14 @@ fn set_checked<R: Runtime>(app: AppHandle<R>, rid: ResourceId, checked: bool) ->
|
||||
fn set_icon<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
rid: ResourceId,
|
||||
icon: Option<Icon>,
|
||||
icon: Option<Icon<'_>>,
|
||||
) -> crate::Result<()> {
|
||||
let resources_table = app.resources_table();
|
||||
let icon_item = resources_table.get::<IconMenuItem<R>>(rid)?;
|
||||
|
||||
match icon {
|
||||
Some(Icon::Native(icon)) => icon_item.set_native_icon(Some(icon)),
|
||||
Some(Icon::Icon(icon)) => icon_item.set_icon(Some(icon.into())),
|
||||
Some(Icon::Icon(icon)) => icon_item.set_icon(Some(icon.try_into()?)),
|
||||
None => {
|
||||
icon_item.set_icon(None)?;
|
||||
icon_item.set_native_icon(None)?;
|
||||
|
@ -337,15 +337,20 @@ impl<R: Runtime> PredefinedMenuItem<R> {
|
||||
pub fn about<M: Manager<R>>(
|
||||
manager: &M,
|
||||
text: Option<&str>,
|
||||
metadata: Option<AboutMetadata>,
|
||||
metadata: Option<AboutMetadata<'_>>,
|
||||
) -> crate::Result<Self> {
|
||||
let handle = manager.app_handle();
|
||||
let app_handle = handle.clone();
|
||||
|
||||
let text = text.map(|t| t.to_owned());
|
||||
|
||||
let metadata = match metadata {
|
||||
Some(m) => Some(m.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let item = run_main_thread!(handle, || {
|
||||
let item = muda::PredefinedMenuItem::about(text.as_deref(), metadata.map(Into::into));
|
||||
let item = muda::PredefinedMenuItem::about(text.as_deref(), metadata);
|
||||
PredefinedMenuItemInner {
|
||||
id: item.id().clone(),
|
||||
inner: Some(item),
|
||||
|
@ -391,7 +391,7 @@ impl WindowBuilder for MockWindowBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
fn icon(self, icon: Icon) -> Result<Self> {
|
||||
fn icon(self, icon: Icon<'_>) -> Result<Self> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
@ -869,7 +869,7 @@ impl<T: UserEvent> WindowDispatch<T> for MockWindowDispatcher {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_icon(&self, icon: Icon) -> Result<()> {
|
||||
fn set_icon(&self, icon: Icon<'_>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ use crate::app::{GlobalMenuEventListener, GlobalTrayIconEventListener};
|
||||
use crate::menu::ContextMenu;
|
||||
use crate::menu::MenuEvent;
|
||||
use crate::resources::Resource;
|
||||
use crate::{menu::run_item_main_thread, AppHandle, Icon, Manager, Runtime};
|
||||
use crate::{menu::run_item_main_thread, AppHandle, Image, Manager, Runtime};
|
||||
use serde::Serialize;
|
||||
use std::path::Path;
|
||||
pub use tray_icon::TrayIconId;
|
||||
@ -159,7 +159,7 @@ impl<R: Runtime> TrayIconBuilder<R> {
|
||||
///
|
||||
/// - **Linux:** Sometimes the icon won't be visible unless a menu is set.
|
||||
/// Setting an empty [`Menu`](crate::menu::Menu) is enough.
|
||||
pub fn icon(mut self, icon: Icon) -> Self {
|
||||
pub fn icon(mut self, icon: Image<'_>) -> Self {
|
||||
let icon = icon.try_into().ok();
|
||||
if let Some(icon) = icon {
|
||||
self.inner = self.inner.with_icon(icon);
|
||||
@ -364,8 +364,11 @@ impl<R: Runtime> TrayIcon<R> {
|
||||
}
|
||||
|
||||
/// Sets a new tray icon. If `None` is provided, it will remove the icon.
|
||||
pub fn set_icon(&self, icon: Option<Icon>) -> crate::Result<()> {
|
||||
let icon = icon.and_then(|i| i.try_into().ok());
|
||||
pub fn set_icon(&self, icon: Option<Image<'_>>) -> crate::Result<()> {
|
||||
let icon = match icon {
|
||||
Some(i) => Some(i.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
run_item_main_thread!(self, |self_: Self| self_.inner.set_icon(icon))?.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -441,15 +444,6 @@ impl<R: Runtime> TrayIcon<R> {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Icon> for tray_icon::Icon {
|
||||
type Error = crate::Error;
|
||||
|
||||
fn try_from(value: Icon) -> Result<Self, Self::Error> {
|
||||
let value: crate::runtime::Icon = value.try_into()?;
|
||||
tray_icon::Icon::from_rgba(value.rgba, value.width, value.height).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> Resource for TrayIcon<R> {
|
||||
fn close(self: std::sync::Arc<Self>) {
|
||||
self.app_handle.remove_tray_by_id(&self.id);
|
||||
|
@ -8,22 +8,24 @@ use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
command,
|
||||
image::JsIcon,
|
||||
ipc::Channel,
|
||||
menu::{plugin::ItemKind, Menu, Submenu},
|
||||
plugin::{Builder, TauriPlugin},
|
||||
resources::ResourceId,
|
||||
tray::TrayIconBuilder,
|
||||
AppHandle, IconDto, Manager, Runtime,
|
||||
AppHandle, Manager, Runtime,
|
||||
};
|
||||
|
||||
use super::TrayIcon;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct TrayIconOptions {
|
||||
struct TrayIconOptions<'a> {
|
||||
id: Option<String>,
|
||||
menu: Option<(ResourceId, ItemKind)>,
|
||||
icon: Option<IconDto>,
|
||||
#[serde(borrow)]
|
||||
icon: Option<JsIcon<'a>>,
|
||||
tooltip: Option<String>,
|
||||
title: Option<String>,
|
||||
temp_dir_path: Option<PathBuf>,
|
||||
@ -34,7 +36,7 @@ struct TrayIconOptions {
|
||||
#[command(root = "crate")]
|
||||
fn new<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
options: TrayIconOptions,
|
||||
options: TrayIconOptions<'_>,
|
||||
handler: Channel,
|
||||
) -> crate::Result<(ResourceId, String)> {
|
||||
let mut builder = if let Some(id) = options.id {
|
||||
@ -63,7 +65,7 @@ fn new<R: Runtime>(
|
||||
};
|
||||
}
|
||||
if let Some(icon) = options.icon {
|
||||
builder = builder.icon(icon.into());
|
||||
builder = builder.icon(icon.try_into()?);
|
||||
}
|
||||
if let Some(tooltip) = options.tooltip {
|
||||
builder = builder.tooltip(tooltip);
|
||||
@ -92,11 +94,15 @@ fn new<R: Runtime>(
|
||||
fn set_icon<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
rid: ResourceId,
|
||||
icon: Option<IconDto>,
|
||||
icon: Option<JsIcon<'_>>,
|
||||
) -> crate::Result<()> {
|
||||
let resources_table = app.resources_table();
|
||||
let tray = resources_table.get::<TrayIcon<R>>(rid)?;
|
||||
tray.set_icon(icon.map(Into::into))
|
||||
let icon = match icon {
|
||||
Some(i) => Some(i.try_into()?),
|
||||
None => None,
|
||||
};
|
||||
tray.set_icon(icon)
|
||||
}
|
||||
|
||||
#[command(root = "crate")]
|
||||
|
@ -21,7 +21,7 @@ use crate::{
|
||||
},
|
||||
UserAttentionType,
|
||||
},
|
||||
Icon,
|
||||
Image,
|
||||
};
|
||||
use tauri_utils::config::{WebviewUrl, WindowConfig};
|
||||
use url::Url;
|
||||
@ -529,7 +529,7 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
|
||||
}
|
||||
|
||||
/// Sets the window icon.
|
||||
pub fn icon(mut self, icon: crate::Icon) -> crate::Result<Self> {
|
||||
pub fn icon(mut self, icon: Image<'a>) -> crate::Result<Self> {
|
||||
self.window_builder = self.window_builder.icon(icon)?;
|
||||
Ok(self)
|
||||
}
|
||||
@ -1420,7 +1420,7 @@ impl<R: Runtime> WebviewWindow<R> {
|
||||
}
|
||||
|
||||
/// Sets this window' icon.
|
||||
pub fn set_icon(&self, icon: Icon) -> crate::Result<()> {
|
||||
pub fn set_icon(&self, icon: Image<'_>) -> crate::Result<()> {
|
||||
self.webview.window().set_icon(icon)
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ use crate::{
|
||||
window::dpi::{Position, Size},
|
||||
UserAttentionType,
|
||||
},
|
||||
CursorIcon, Icon,
|
||||
CursorIcon, Image,
|
||||
};
|
||||
|
||||
use serde::Serialize;
|
||||
@ -632,8 +632,8 @@ impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M> {
|
||||
}
|
||||
|
||||
/// Sets the window icon.
|
||||
pub fn icon(mut self, icon: Icon) -> crate::Result<Self> {
|
||||
self.window_builder = self.window_builder.icon(icon.try_into()?)?;
|
||||
pub fn icon(mut self, icon: Image<'a>) -> crate::Result<Self> {
|
||||
self.window_builder = self.window_builder.icon(icon.into())?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
@ -1819,11 +1819,11 @@ tauri::Builder::default()
|
||||
}
|
||||
|
||||
/// Sets this window' icon.
|
||||
pub fn set_icon(&self, icon: Icon) -> crate::Result<()> {
|
||||
pub fn set_icon(&self, icon: Image<'_>) -> crate::Result<()> {
|
||||
self
|
||||
.window
|
||||
.dispatcher
|
||||
.set_icon(icon.try_into()?)
|
||||
.set_icon(icon.into())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ use crate::{
|
||||
|
||||
#[cfg(desktop)]
|
||||
mod desktop_commands {
|
||||
use serde::Deserialize;
|
||||
use tauri_runtime::ResizeDirection;
|
||||
|
||||
use super::*;
|
||||
@ -20,44 +19,10 @@ mod desktop_commands {
|
||||
sealed::ManagerBase,
|
||||
utils::config::{WindowConfig, WindowEffectsConfig},
|
||||
window::{ProgressBarState, WindowBuilder},
|
||||
AppHandle, CursorIcon, Icon, Monitor, PhysicalPosition, PhysicalSize, Position, Size, Theme,
|
||||
AppHandle, CursorIcon, Monitor, PhysicalPosition, PhysicalSize, Position, Size, Theme,
|
||||
UserAttentionType, Window,
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum IconDto {
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
File(std::path::PathBuf),
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
Raw(Vec<u8>),
|
||||
Rgba {
|
||||
rgba: Vec<u8>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<IconDto> for Icon {
|
||||
fn from(icon: IconDto) -> Self {
|
||||
match icon {
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
IconDto::File(path) => Self::File(path),
|
||||
#[cfg(any(feature = "icon-png", feature = "icon-ico"))]
|
||||
IconDto::Raw(raw) => Self::Raw(raw),
|
||||
IconDto::Rgba {
|
||||
rgba,
|
||||
width,
|
||||
height,
|
||||
} => Self::Rgba {
|
||||
rgba,
|
||||
width,
|
||||
height,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[command(root = "crate")]
|
||||
pub async fn create<R: Runtime>(app: AppHandle<R>, options: WindowConfig) -> crate::Result<()> {
|
||||
WindowBuilder::from_config(&app, &options)?.build()?;
|
||||
@ -169,10 +134,10 @@ mod desktop_commands {
|
||||
pub async fn set_icon<R: Runtime>(
|
||||
window: Window<R>,
|
||||
label: Option<String>,
|
||||
value: IconDto,
|
||||
value: crate::image::JsIcon<'_>,
|
||||
) -> crate::Result<()> {
|
||||
get_window(window, label)?
|
||||
.set_icon(value.into())
|
||||
.set_icon(value.try_into()?)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
|
167
examples/api/src-tauri/Cargo.lock
generated
167
examples/api/src-tauri/Cargo.lock
generated
@ -246,7 +246,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -392,7 +392,7 @@ dependencies = [
|
||||
"iana-time-zone",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"windows-targets 0.52.3",
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -523,9 +523,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.11"
|
||||
version = "0.5.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b"
|
||||
checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
@ -571,7 +571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -581,7 +581,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad291aa74992b9b7a7e88c38acbbf6ad7e107f1d90ee8775b7bc1fc3394f485c"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -614,7 +614,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -625,7 +625,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -717,7 +717,7 @@ checksum = "f2b99bf03862d7f545ebc28ddd33a665b50865f4dfd84031a393823879bd4c54"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -896,7 +896,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -964,7 +964,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1106,15 +1106,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "generator"
|
||||
version = "0.7.5"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"
|
||||
checksum = "b5b25e5b3e733153bcab35ee4671b46604b42516163cae442d1601cb716f2ac5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"log",
|
||||
"rustversion",
|
||||
"windows 0.48.0",
|
||||
"windows 0.53.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1241,7 +1242,7 @@ dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1320,7 +1321,7 @@ dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1461,7 +1462,7 @@ dependencies = [
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2210,7 +2211,7 @@ dependencies = [
|
||||
"phf_shared 0.11.2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2726,7 +2727,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2759,7 +2760,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2810,7 +2811,7 @@ dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3042,9 +3043,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.51"
|
||||
version = "2.0.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c"
|
||||
checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -3093,9 +3094,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tao"
|
||||
version = "0.26.0"
|
||||
version = "0.26.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29d9325da2dd7ebd48a8a433c64240079b15dbe1249da04c72557611bcd08d1c"
|
||||
checksum = "ccba570365293ca309d60f30fdac2c5271b732dc762e6154e59c85d2c762a0a1"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"cocoa",
|
||||
@ -3237,7 +3238,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
"tauri-utils",
|
||||
"thiserror",
|
||||
"time",
|
||||
@ -3253,7 +3254,7 @@ dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
"tauri-codegen",
|
||||
"tauri-utils",
|
||||
]
|
||||
@ -3399,7 +3400,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3597,7 +3598,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3834,7 +3835,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@ -3868,7 +3869,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
@ -4004,7 +4005,7 @@ dependencies = [
|
||||
"webview2-com-macros",
|
||||
"webview2-com-sys",
|
||||
"windows 0.52.0",
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
]
|
||||
@ -4017,7 +4018,7 @@ checksum = "ac1345798ecd8122468840bcdf1b95e5dc6d2206c5e4b0eafa078d061f59c9bc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4028,7 +4029,7 @@ checksum = "d6ad85fceee6c42fa3d61239eba5a11401bf38407a849ed5ea1b407df08cca72"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"windows 0.52.0",
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4075,25 +4076,26 @@ dependencies = [
|
||||
"windows-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-core 0.52.0",
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-targets 0.52.3",
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "efc5cf48f83140dcaab716eeaea345f9e93d0018fb81162753a3f76c3397b538"
|
||||
dependencies = [
|
||||
"windows-core 0.53.0",
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4102,7 +4104,17 @@ version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.3",
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcc5b895a6377f1ab9fa55acedab1fd5ac0db66ad1e6c7f47e28a22e446a5dd"
|
||||
dependencies = [
|
||||
"windows-result",
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4113,7 +4125,7 @@ checksum = "12168c33176773b86799be25e2a2ba07c7aab9968b37541f1094dbd7a60c8946"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4124,7 +4136,16 @@ checksum = "9d8dc32e0095a7eeccebd0e3f09e9509365ecb3fc6ac4d6f5f14a3f6392942d1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.51",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd19df78e5168dfb0aedc343d1d1b8d422ab2db6756d2dc3fef75035402a3f64"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4151,7 +4172,7 @@ version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.3",
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4186,17 +4207,17 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f"
|
||||
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.3",
|
||||
"windows_aarch64_msvc 0.52.3",
|
||||
"windows_i686_gnu 0.52.3",
|
||||
"windows_i686_msvc 0.52.3",
|
||||
"windows_x86_64_gnu 0.52.3",
|
||||
"windows_x86_64_gnullvm 0.52.3",
|
||||
"windows_x86_64_msvc 0.52.3",
|
||||
"windows_aarch64_gnullvm 0.52.4",
|
||||
"windows_aarch64_msvc 0.52.4",
|
||||
"windows_i686_gnu 0.52.4",
|
||||
"windows_i686_msvc 0.52.4",
|
||||
"windows_x86_64_gnu 0.52.4",
|
||||
"windows_x86_64_gnullvm 0.52.4",
|
||||
"windows_x86_64_msvc 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4205,7 +4226,7 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75aa004c988e080ad34aff5739c39d0312f4684699d6d71fc8a198d057b8b9b4"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.3",
|
||||
"windows-targets 0.52.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4222,9 +4243,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6"
|
||||
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
@ -4240,9 +4261,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f"
|
||||
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
@ -4258,9 +4279,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb"
|
||||
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
@ -4276,9 +4297,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58"
|
||||
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
@ -4294,9 +4315,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614"
|
||||
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
@ -4312,9 +4333,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c"
|
||||
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
@ -4330,9 +4351,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.3"
|
||||
version = "0.52.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6"
|
||||
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
|
@ -24,8 +24,8 @@ tauri-plugin-sample = { path = "./tauri-plugin-sample/" }
|
||||
path = "../../../core/tauri"
|
||||
features = [
|
||||
"protocol-asset",
|
||||
"icon-ico",
|
||||
"icon-png",
|
||||
"image-ico",
|
||||
"image-png",
|
||||
"isolation",
|
||||
"macos-private-api",
|
||||
"tray-icon"
|
||||
|
@ -81,11 +81,14 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
|
||||
}
|
||||
i @ "icon-1" | i @ "icon-2" => {
|
||||
if let Some(tray) = app.tray_by_id("tray-1") {
|
||||
let _ = tray.set_icon(Some(tauri::Icon::Raw(if i == "icon-1" {
|
||||
include_bytes!("../../../.icons/icon.ico").to_vec()
|
||||
let icon = if i == "icon-1" {
|
||||
tauri::Image::from_bytes(include_bytes!("../../../.icons/icon.ico"))
|
||||
} else {
|
||||
include_bytes!("../../../.icons/tray_icon_with_transparency.png").to_vec()
|
||||
})));
|
||||
tauri::Image::from_bytes(include_bytes!(
|
||||
"../../../.icons/tray_icon_with_transparency.png"
|
||||
))
|
||||
};
|
||||
let _ = tray.set_icon(Some(icon.unwrap()));
|
||||
}
|
||||
}
|
||||
"switch-menu" => {
|
||||
|
@ -51,11 +51,11 @@ export interface TrayIconOptions {
|
||||
/**
|
||||
* The tray icon which could be icon bytes or path to the icon file.
|
||||
*
|
||||
* Note that you need the `icon-ico` or `icon-png` Cargo features to use this API.
|
||||
* Note that you need the `image-ico` or `image-png` Cargo features to use this API.
|
||||
* To enable it, change your Cargo.toml file:
|
||||
* ```toml
|
||||
* [dependencies]
|
||||
* tauri = { version = "...", features = ["...", "icon-png"] }
|
||||
* tauri = { version = "...", features = ["...", "image-png"] }
|
||||
* ```
|
||||
*/
|
||||
icon?: string | Uint8Array | number[]
|
||||
|
@ -1383,11 +1383,11 @@ class Window {
|
||||
* await getCurrent().setIcon('/tauri/awesome.png');
|
||||
* ```
|
||||
*
|
||||
* Note that you need the `icon-ico` or `icon-png` Cargo features to use this API.
|
||||
* Note that you need the `image-ico` or `image-png` Cargo features to use this API.
|
||||
* To enable it, change your Cargo.toml file:
|
||||
* ```toml
|
||||
* [dependencies]
|
||||
* tauri = { version = "...", features = ["...", "icon-png"] }
|
||||
* tauri = { version = "...", features = ["...", "image-png"] }
|
||||
* ```
|
||||
*
|
||||
* @param icon Icon bytes or path to the icon file.
|
||||
|
Loading…
Reference in New Issue
Block a user