How to remove the dock icon on Mac Tauri? #8506
-
I am trying to remove the dock icon, close the window, and let the app run in the background using Tauri. I am able to close the window, but I don't know how to remove the app icon after the window is closed. // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello ->, {}!", name)
}
fn main() {
tauri::Builder::default()
.setup(|app| {
// #[cfg(target_os = "macos")]
// app.set_activation_policy(tauri::ActivationPolicy::Accessory); // this removes the dock icon by default
Ok(())
})
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(|_app_handle, event| match event {
// dock icon should be removed here, but I don't know how, share the app state?
tauri::RunEvent::ExitRequested { api, .. } => {
api.prevent_exit();
}
_ => {}
})
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Copy pasting the answer from stackoverflow for visibility:
use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicy::*};
unsafe {
let app = NSApp();
app.setActivationPolicy_(NSApplicationActivationPolicyAccessory);
}
|
Beta Was this translation helpful? Give feedback.
Copy pasting the answer from stackoverflow for visibility: