fixed macos dock icon visibility issue
This commit is contained in:
+16
-8
@@ -50,7 +50,7 @@ pub fn run() {
|
||||
#[cfg(target_os = "macos")]
|
||||
let builder = builder.plugin(ui::activation_policy::ActivationPolicy::default());
|
||||
|
||||
builder
|
||||
let app = builder
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
|
||||
@@ -74,14 +74,22 @@ pub fn run() {
|
||||
Ok(())
|
||||
})
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while running tauri application")
|
||||
.run(|_, e| {
|
||||
if let tauri::RunEvent::ExitRequested { code, api, .. } = e {
|
||||
if code.is_none() {
|
||||
api.prevent_exit();
|
||||
}
|
||||
.expect("error while building tauri application");
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let app = {
|
||||
let mut app = app;
|
||||
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
||||
app
|
||||
};
|
||||
|
||||
app.run(|_, e| {
|
||||
if let tauri::RunEvent::ExitRequested { code, api, .. } = e {
|
||||
if code.is_none() {
|
||||
api.prevent_exit();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn specta_builder() -> tauri_specta::Builder<tauri::Wry> {
|
||||
|
||||
@@ -6,7 +6,8 @@ use tauri::{AppHandle, Manager, RunEvent, Window, WindowEvent, Wry, plugin::Plug
|
||||
#[derive(Default)]
|
||||
pub struct ActivationPolicy {
|
||||
windows: HashSet<String>,
|
||||
applied_regular: Option<bool>,
|
||||
/// `lib::run` establishes Accessory before the event loop starts.
|
||||
applied_regular: bool,
|
||||
}
|
||||
|
||||
impl ActivationPolicy {
|
||||
@@ -23,13 +24,13 @@ impl ActivationPolicy {
|
||||
|
||||
fn reconcile(&mut self, app: &AppHandle) -> tauri::Result<()> {
|
||||
let regular = !self.windows.is_empty();
|
||||
if self.applied_regular != Some(regular) {
|
||||
if self.applied_regular != regular {
|
||||
app.set_activation_policy(if regular {
|
||||
tauri::ActivationPolicy::Regular
|
||||
} else {
|
||||
tauri::ActivationPolicy::Accessory
|
||||
})?;
|
||||
self.applied_regular = Some(regular);
|
||||
self.applied_regular = regular;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -40,15 +41,6 @@ impl Plugin<Wry> for ActivationPolicy {
|
||||
"activation-policy"
|
||||
}
|
||||
|
||||
fn initialize(
|
||||
&mut self,
|
||||
app: &AppHandle,
|
||||
_config: serde_json::Value,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
self.reconcile(app)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn window_created(&mut self, window: Window) {
|
||||
self.record_window(window.label(), true);
|
||||
if let Err(error) = self.reconcile(window.app_handle()) {
|
||||
|
||||
Reference in New Issue
Block a user