refactor: Replace std::sync::Mutex with parking_lot::Mutex for improved performance and consistency in multiple files

This commit is contained in:
Tunglies
2025-07-05 00:33:53 +08:00
parent 764ef48fd1
commit 6d192233d1
3 changed files with 25 additions and 22 deletions

View File

@@ -13,7 +13,8 @@ use crate::{
utils::{resolve, resolve::resolve_scheme, server},
};
use config::Config;
use std::sync::{Mutex, Once};
use parking_lot::Mutex;
use std::sync::Once;
use tauri::AppHandle;
use tauri::Manager;
#[cfg(target_os = "macos")]
@@ -41,14 +42,14 @@ impl AppHandleManager {
/// Initialize the app handle manager with an app handle.
pub fn init(&self, handle: AppHandle) {
self.init.call_once(|| {
let mut app_handle = self.inner.lock().unwrap();
let mut app_handle = self.inner.lock();
*app_handle = Some(handle);
});
}
/// Get the app handle if it has been initialized.
pub fn get(&self) -> Option<AppHandle> {
self.inner.lock().unwrap().clone()
self.inner.lock().clone()
}
/// Get the app handle, panics if it hasn't been initialized.
@@ -59,7 +60,7 @@ impl AppHandleManager {
pub fn set_activation_policy_regular(&self) {
#[cfg(target_os = "macos")]
{
let app_handle = self.inner.lock().unwrap();
let app_handle = self.inner.lock();
let app_handle = app_handle.as_ref().unwrap();
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Regular);
}
@@ -68,7 +69,7 @@ impl AppHandleManager {
pub fn set_activation_policy_accessory(&self) {
#[cfg(target_os = "macos")]
{
let app_handle = self.inner.lock().unwrap();
let app_handle = self.inner.lock();
let app_handle = app_handle.as_ref().unwrap();
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Accessory);
}
@@ -77,7 +78,7 @@ impl AppHandleManager {
pub fn set_activation_policy_prohibited(&self) {
#[cfg(target_os = "macos")]
{
let app_handle = self.inner.lock().unwrap();
let app_handle = self.inner.lock();
let app_handle = app_handle.as_ref().unwrap();
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Prohibited);
}