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