Skip to content

Commit 92fb26a

Browse files
committed
Add linux-ksni feature and update docs
1 parent b0d7527 commit 92fb26a

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ opt-level = "s"
7070
[patch.crates-io]
7171
schemars_derive = { git = 'https://github.com/tauri-apps/schemars.git', branch = 'feat/preserve-description-newlines' }
7272
tauri = { path = "./crates/tauri" }
73+
tray-icon = { git = "https://github.com/dfaust/tray-icon", branch = "ksni" }
74+
muda = { git = "https://github.com/dfaust/muda", branch = "ksni" }

crates/tauri/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ features = [
2525
"protocol-asset",
2626
"test",
2727
"specta",
28+
"linux-ksni",
2829
]
2930
rustc-args = ["--cfg", "docsrs"]
3031
rustdoc-args = ["--cfg", "docsrs"]
@@ -175,7 +176,7 @@ test = []
175176
compression = ["tauri-macros/compression", "tauri-utils/compression"]
176177
wry = ["tauri-runtime-wry"]
177178
objc-exception = ["tauri-runtime-wry/objc-exception"]
178-
linux-libxdo = ["tray-icon/libxdo", "muda/libxdo"]
179+
linux-libxdo = ["muda/libxdo"]
179180
isolation = ["tauri-utils/isolation", "tauri-macros/isolation", "uuid"]
180181
custom-protocol = ["tauri-macros/custom-protocol"]
181182
native-tls = ["reqwest/native-tls"]
@@ -197,6 +198,7 @@ image-ico = ["image/ico"]
197198
image-png = ["image/png"]
198199
macos-proxy = ["tauri-runtime-wry/macos-proxy"]
199200
specta = ["dep:specta", "dep:specta-util"]
201+
linux-ksni = ["tray-icon?/linux-ksni"]
200202

201203
[[example]]
202204
name = "commands"

crates/tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
//! - **image-png**: Adds support to parse `.png` image, see [`Image`].
3636
//! - **macos-proxy**: Adds support for [`WebviewBuilder::proxy_url`] on macOS. Requires macOS 14+.
3737
//! - **specta**: Add support for [`specta::specta`](https://docs.rs/specta/%5E2.0.0-rc.9/specta/attr.specta.html) with Tauri arguments such as [`State`](crate::State), [`Window`](crate::Window) and [`AppHandle`](crate::AppHandle)
38+
//! - **linux-ksni**: Enables the experimental `linux-ksni` feature of the `tray-icon` crate, which uses the xdg standard for system tray icons on Linux.
3839
//!
3940
//! ## Cargo allowlist features
4041
//!

crates/tauri/src/tray/mod.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,6 @@ pub struct TrayIconBuilder<R: Runtime> {
218218

219219
impl<R: Runtime> TrayIconBuilder<R> {
220220
/// Creates a new tray icon builder.
221-
///
222-
/// ## Platform-specific:
223-
///
224-
/// - **Linux:** Sometimes the icon won't be visible unless a menu is set.
225-
/// Setting an empty [`Menu`](crate::menu::Menu) is enough.
226221
pub fn new() -> Self {
227222
Self {
228223
inner: tray_icon::TrayIconBuilder::new(),
@@ -232,11 +227,6 @@ impl<R: Runtime> TrayIconBuilder<R> {
232227
}
233228

234229
/// Creates a new tray icon builder with the specified id.
235-
///
236-
/// ## Platform-specific:
237-
///
238-
/// - **Linux:** Sometimes the icon won't be visible unless a menu is set.
239-
/// Setting an empty [`Menu`](crate::menu::Menu) is enough.
240230
pub fn with_id<I: Into<TrayIconId>>(id: I) -> Self {
241231
let mut builder = Self::new();
242232
builder.inner = builder.inner.with_id(id);
@@ -259,6 +249,7 @@ impl<R: Runtime> TrayIconBuilder<R> {
259249
///
260250
/// - **Linux:** Sometimes the icon won't be visible unless a menu is set.
261251
/// Setting an empty [`Menu`](crate::menu::Menu) is enough.
252+
/// Works with feature `linux-ksni`.
262253
pub fn icon(mut self, icon: Image<'_>) -> Self {
263254
let icon = icon.try_into().ok();
264255
if let Some(icon) = icon {
@@ -271,7 +262,7 @@ impl<R: Runtime> TrayIconBuilder<R> {
271262
///
272263
/// ## Platform-specific:
273264
///
274-
/// - **Linux:** Unsupported.
265+
/// - **Linux:** Unsupported. Works with feature `linux-ksni`.
275266
pub fn tooltip<S: AsRef<str>>(mut self, s: S) -> Self {
276267
self.inner = self.inner.with_tooltip(s);
277268
self
@@ -286,16 +277,20 @@ impl<R: Runtime> TrayIconBuilder<R> {
286277
/// updated information. In general, it shouldn't be shown unless a
287278
/// user requests it as it can take up a significant amount of space
288279
/// on the user's panel. This may not be shown in all visualizations.
280+
/// Works with feature `linux-ksni`.
289281
/// - **Windows:** Unsupported.
290282
pub fn title<S: AsRef<str>>(mut self, title: S) -> Self {
291283
self.inner = self.inner.with_title(title);
292284
self
293285
}
294286

295287
/// Set tray icon temp dir path. **Linux only**.
288+
///
289+
/// Not availabe with feature `linux-ksni`.
296290
///
297291
/// On Linux, we need to write the icon to the disk and usually it will
298292
/// be `$XDG_RUNTIME_DIR/tray-icon` or `$TEMP/tray-icon`.
293+
#[cfg(not(feature = "linux-ksni"))]
299294
pub fn temp_dir_path<P: AsRef<Path>>(mut self, s: P) -> Self {
300295
self.inner = self.inner.with_temp_dir_path(s);
301296
self
@@ -509,7 +504,7 @@ impl<R: Runtime> TrayIcon<R> {
509504
///
510505
/// ## Platform-specific:
511506
///
512-
/// - **Linux**: once a menu is set it cannot be removed so `None` has no effect
507+
/// - **Linux**: Once a menu is set it cannot be removed so `None` has no effect. Works with feature `linux-ksni`.
513508
pub fn set_menu<M: ContextMenu + 'static>(&self, menu: Option<M>) -> crate::Result<()> {
514509
run_item_main_thread!(self, |self_: Self| {
515510
self_.inner.set_menu(menu.map(|m| m.inner_context_owned()))
@@ -520,7 +515,7 @@ impl<R: Runtime> TrayIcon<R> {
520515
///
521516
/// ## Platform-specific:
522517
///
523-
/// - **Linux:** Unsupported
518+
/// - **Linux:** Unsupported. Works with feature `linux-ksni`.
524519
pub fn set_tooltip<S: AsRef<str>>(&self, tooltip: Option<S>) -> crate::Result<()> {
525520
let s = tooltip.map(|s| s.as_ref().to_string());
526521
run_item_main_thread!(self, |self_: Self| self_.inner.set_tooltip(s))?.map_err(Into::into)
@@ -535,6 +530,7 @@ impl<R: Runtime> TrayIcon<R> {
535530
/// updated information. In general, it shouldn't be shown unless a
536531
/// user requests it as it can take up a significant amount of space
537532
/// on the user's panel. This may not be shown in all visualizations.
533+
/// Works with feature `linux-ksni`.
538534
/// - **Windows:** Unsupported
539535
pub fn set_title<S: AsRef<str>>(&self, title: Option<S>) -> crate::Result<()> {
540536
let s = title.map(|s| s.as_ref().to_string());
@@ -547,9 +543,12 @@ impl<R: Runtime> TrayIcon<R> {
547543
}
548544

549545
/// Sets the tray icon temp dir path. **Linux only**.
546+
///
547+
/// Not availabe with feature `linux-ksni`.
550548
///
551549
/// On Linux, we need to write the icon to the disk and usually it will
552550
/// be `$XDG_RUNTIME_DIR/tray-icon` or `$TEMP/tray-icon`.
551+
#[cfg(not(feature = "linux-ksni"))]
553552
pub fn set_temp_dir_path<P: AsRef<Path>>(&self, path: Option<P>) -> crate::Result<()> {
554553
#[allow(unused)]
555554
let p = path.map(|p| p.as_ref().to_path_buf());

crates/tauri/src/tray/plugin.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fn new<R: Runtime>(
7373
if let Some(title) = options.title {
7474
builder = builder.title(title);
7575
}
76+
#[cfg(not(feature = "linux-ksni"))]
7677
if let Some(temp_dir_path) = options.temp_dir_path {
7778
builder = builder.temp_dir_path(temp_dir_path);
7879
}
@@ -191,6 +192,7 @@ fn set_visible<R: Runtime>(
191192
tray.set_visible(visible)
192193
}
193194

195+
#[cfg(not(feature = "linux-ksni"))]
194196
#[command(root = "crate")]
195197
fn set_temp_dir_path<R: Runtime>(
196198
webview: Webview<R>,
@@ -235,6 +237,7 @@ pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {
235237
set_tooltip,
236238
set_title,
237239
set_visible,
240+
#[cfg(not(feature = "linux-ksni"))]
238241
set_temp_dir_path,
239242
set_icon_as_template,
240243
set_show_menu_on_left_click,

0 commit comments

Comments
 (0)