mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 07:55:34 +03:00
feat(core): add AppHandle::set_activation_policy (#9842)
This commit is contained in:
parent
d0d974fa5e
commit
5d20530c91
5
.changes/app-handle-set-activation-policy.md
Normal file
5
.changes/app-handle-set-activation-policy.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"tauri": patch:enhance
|
||||||
|
---
|
||||||
|
|
||||||
|
Added `AppHandle::set_activation_policy` for macOS.
|
@ -423,6 +423,26 @@ impl<R: Runtime> AppHandle<R> {
|
|||||||
}
|
}
|
||||||
crate::process::restart(&self.env());
|
crate::process::restart(&self.env());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the activation policy for the application. It is set to `NSApplicationActivationPolicyRegular` by default.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```,no_run
|
||||||
|
/// tauri::Builder::default()
|
||||||
|
/// .setup(move |app| {
|
||||||
|
/// #[cfg(target_os = "macos")]
|
||||||
|
/// app.handle().set_activation_policy(tauri::ActivationPolicy::Accessory);
|
||||||
|
/// Ok(())
|
||||||
|
/// });
|
||||||
|
/// ```
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
|
||||||
|
pub fn set_activation_policy(&self, activation_policy: ActivationPolicy) -> crate::Result<()> {
|
||||||
|
self
|
||||||
|
.runtime_handle
|
||||||
|
.set_activation_policy(activation_policy)
|
||||||
|
.map_err(Into::into)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Runtime> Manager<R> for AppHandle<R> {
|
impl<R: Runtime> Manager<R> for AppHandle<R> {
|
||||||
@ -898,13 +918,12 @@ impl<R: Runtime> App<R> {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```,no_run
|
/// ```,no_run
|
||||||
/// let mut app = tauri::Builder::default()
|
/// tauri::Builder::default()
|
||||||
/// // on an actual app, remove the string argument
|
/// .setup(move |app| {
|
||||||
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
|
/// #[cfg(target_os = "macos")]
|
||||||
/// .expect("error while building tauri application");
|
/// app.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
||||||
/// #[cfg(target_os = "macos")]
|
/// Ok(())
|
||||||
/// app.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
/// });
|
||||||
/// app.run(|_app_handle, _event| {});
|
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
|
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
|
||||||
@ -912,10 +931,7 @@ impl<R: Runtime> App<R> {
|
|||||||
if let Some(runtime) = self.runtime.as_mut() {
|
if let Some(runtime) = self.runtime.as_mut() {
|
||||||
runtime.set_activation_policy(activation_policy);
|
runtime.set_activation_policy(activation_policy);
|
||||||
} else {
|
} else {
|
||||||
let _ = self
|
let _ = self.app_handle().set_activation_policy(activation_policy);
|
||||||
.app_handle()
|
|
||||||
.runtime_handle
|
|
||||||
.set_activation_policy(activation_policy);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user