Skip to content

Commit 1104b4e

Browse files
committed
Fix generated tray icon path on linux to be unique
1 parent c14f3a9 commit 1104b4e

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ tauri-plugin-fs = "2"
3737
tauri-plugin-dialog = "2"
3838
tauri-plugin-shell = "2"
3939
tauri-plugin-notification = "2"
40+
dirs = "6.0.0"
4041

4142
[dependencies.reqwest]
4243
version = "*"

src-tauri/src/tray.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,37 @@ pub const TRAY_ID: &str = "tray";
3131
pub fn create_tray(app: AppHandle) {
3232
let menu = create_menu(&app, "Hide");
3333

34-
#[allow(clippy::single_match)]
35-
TrayIconBuilder::with_id(TRAY_ID)
34+
let builder = TrayIconBuilder::with_id(TRAY_ID)
3635
.icon(app.default_window_icon().unwrap().clone())
3736
.menu(&menu)
3837
.show_menu_on_left_click(false)
39-
.on_tray_icon_event(|tray, event| {
40-
match event {
41-
TrayIconEvent::Click {
42-
button: MouseButton::Left,
43-
button_state: MouseButtonState::Up,
44-
..
45-
} => {
46-
#[cfg(not(target_os = "macos"))]
47-
toggle_main_window(
48-
tray.app_handle(),
49-
tray.app_handle().get_webview_window("main"),
50-
);
51-
}
52-
_ => {}
53-
};
54-
})
55-
.on_menu_event(on_menu_event)
56-
.build(&app)
57-
.ok();
38+
.on_menu_event(on_menu_event);
39+
40+
#[allow(clippy::single_match)]
41+
let builder = builder.on_tray_icon_event(|tray, event| {
42+
match event {
43+
TrayIconEvent::Click {
44+
button: MouseButton::Left,
45+
button_state: MouseButtonState::Up,
46+
..
47+
} => {
48+
#[cfg(not(target_os = "macos"))]
49+
toggle_main_window(
50+
tray.app_handle(),
51+
tray.app_handle().get_webview_window("main"),
52+
);
53+
}
54+
_ => {}
55+
};
56+
});
57+
58+
#[cfg(target_os = "linux")]
59+
let builder = builder.temp_dir_path(dirs::runtime_dir()
60+
.unwrap_or_else(std::env::temp_dir)
61+
.join("tray-icon")
62+
.join(&app.config().identifier));
63+
64+
builder.build(&app).ok();
5865
}
5966

6067
fn create_menu<R>(app: &AppHandle<R>, showhide_text: &str) -> tauri::menu::Menu<R>

0 commit comments

Comments
 (0)