mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:33:45 +08:00
fix: macos dock display icon and text (#2818)
This commit is contained in:
parent
8fb66ea32c
commit
41c42bba32
@ -2,6 +2,12 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>CFBundleIconFile</key>
|
||||||
|
<string>icon.icns</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>Clash Verge</string>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>Clash Verge</string>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
<key>com.apple.security.app-sandbox</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>com.apple.security.application-groups</key>
|
<key>com.apple.security.application-groups</key>
|
||||||
@ -10,5 +16,11 @@
|
|||||||
</array>
|
</array>
|
||||||
<key>com.apple.security.inherit</key>
|
<key>com.apple.security.inherit</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>LSUIElement</key>
|
||||||
|
<false/>
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true/>
|
||||||
|
<key>NSRequiresAquaSystemAppearance</key>
|
||||||
|
<false/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
@ -9,6 +9,70 @@ use crate::utils::{resolve, resolve::resolve_scheme, server};
|
|||||||
use config::Config;
|
use config::Config;
|
||||||
use tauri_plugin_autostart::MacosLauncher;
|
use tauri_plugin_autostart::MacosLauncher;
|
||||||
use tauri_plugin_deep_link::DeepLinkExt;
|
use tauri_plugin_deep_link::DeepLinkExt;
|
||||||
|
use std::{sync::{Mutex, Once}};
|
||||||
|
use tauri::AppHandle;
|
||||||
|
|
||||||
|
/// A global singleton handle to the application.
|
||||||
|
pub struct AppHandleManager {
|
||||||
|
inner: Mutex<Option<AppHandle>>,
|
||||||
|
init: Once,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppHandleManager {
|
||||||
|
/// Get the global instance of the app handle manager.
|
||||||
|
pub fn global() -> &'static Self {
|
||||||
|
static INSTANCE: AppHandleManager = AppHandleManager {
|
||||||
|
inner: Mutex::new(None),
|
||||||
|
init: Once::new(),
|
||||||
|
};
|
||||||
|
&INSTANCE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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();
|
||||||
|
*app_handle = Some(handle);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the app handle if it has been initialized.
|
||||||
|
pub fn get(&self) -> Option<AppHandle> {
|
||||||
|
self.inner.lock().unwrap().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the app handle, panics if it hasn't been initialized.
|
||||||
|
pub fn get_handle(&self) -> AppHandle {
|
||||||
|
self.get().expect("AppHandle not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_activation_policy_regular(&self) {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
let app_handle = self.inner.lock().unwrap();
|
||||||
|
let app_handle = app_handle.as_ref().unwrap();
|
||||||
|
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Regular);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_activation_policy_accessory(&self) {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
let app_handle = self.inner.lock().unwrap();
|
||||||
|
let app_handle = app_handle.as_ref().unwrap();
|
||||||
|
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_activation_policy_prohibited(&self) {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
let app_handle = self.inner.lock().unwrap();
|
||||||
|
let app_handle = app_handle.as_ref().unwrap();
|
||||||
|
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Prohibited);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
// 单例检测
|
// 单例检测
|
||||||
@ -136,7 +200,16 @@ pub fn run() {
|
|||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|
||||||
app.run(|_, e| match e {
|
app.run(|app_handle, e| match e {
|
||||||
|
tauri::RunEvent::Ready | tauri::RunEvent::Resumed => {
|
||||||
|
AppHandleManager::global().init(app_handle.clone());
|
||||||
|
}
|
||||||
|
tauri::RunEvent::Reopen { has_visible_windows, .. } => {
|
||||||
|
if !has_visible_windows {
|
||||||
|
AppHandleManager::global().set_activation_policy_regular();
|
||||||
|
}
|
||||||
|
AppHandleManager::global().init(app_handle.clone());
|
||||||
|
}
|
||||||
tauri::RunEvent::ExitRequested { api, code, .. } => {
|
tauri::RunEvent::ExitRequested { api, code, .. } => {
|
||||||
if code.is_none() {
|
if code.is_none() {
|
||||||
api.prevent_exit();
|
api.prevent_exit();
|
||||||
@ -146,6 +219,7 @@ pub fn run() {
|
|||||||
if label == "main" {
|
if label == "main" {
|
||||||
match event {
|
match event {
|
||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||||
|
AppHandleManager::global().set_activation_policy_accessory();
|
||||||
if core::handle::Handle::global().is_exiting() {
|
if core::handle::Handle::global().is_exiting() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::config::IVerge;
|
use crate::config::IVerge;
|
||||||
use crate::utils::error;
|
use crate::utils::error;
|
||||||
use crate::{config::Config, config::PrfItem, core::*, utils::init, utils::server};
|
use crate::{config::Config, config::PrfItem, core::*, utils::init, utils::server};
|
||||||
use crate::{log_err, wrap_err};
|
use crate::{log_err, wrap_err, AppHandleManager};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use percent_encoding::percent_decode_str;
|
use percent_encoding::percent_decode_str;
|
||||||
@ -37,7 +37,10 @@ pub fn find_unused_port() -> Result<u16> {
|
|||||||
pub async fn resolve_setup(app: &mut App) {
|
pub async fn resolve_setup(app: &mut App) {
|
||||||
error::redirect_panic_to_log();
|
error::redirect_panic_to_log();
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
{
|
||||||
|
AppHandleManager::global().init(app.app_handle().clone());
|
||||||
|
AppHandleManager::global().set_activation_policy_accessory();
|
||||||
|
}
|
||||||
let version = app.package_info().version.to_string();
|
let version = app.package_info().version.to_string();
|
||||||
|
|
||||||
handle::Handle::global().init(app.app_handle());
|
handle::Handle::global().init(app.app_handle());
|
||||||
@ -130,6 +133,7 @@ pub fn create_window() {
|
|||||||
log::info!(target: "app", "Starting to create window");
|
log::info!(target: "app", "Starting to create window");
|
||||||
|
|
||||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||||
|
AppHandleManager::global().set_activation_policy_regular();
|
||||||
|
|
||||||
if let Some(window) = handle::Handle::global().get_window() {
|
if let Some(window) = handle::Handle::global().get_window() {
|
||||||
println!("Found existing window, trying to show it");
|
println!("Found existing window, trying to show it");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||||
"identifier": "io.github.clash-verge-rev.clash-verge-rev",
|
"identifier": "io.github.clash-verge-rev.clash-verge-rev",
|
||||||
|
"productName": "Clash Verge",
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"targets": ["app", "dmg"],
|
"targets": ["app", "dmg"],
|
||||||
"macOS": {
|
"macOS": {
|
||||||
@ -31,6 +32,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
|
"windows": [
|
||||||
|
{
|
||||||
|
"title": "Clash Verge"
|
||||||
|
}
|
||||||
|
],
|
||||||
"trayIcon": {
|
"trayIcon": {
|
||||||
"iconPath": "icons/tray-icon-mono.ico",
|
"iconPath": "icons/tray-icon-mono.ico",
|
||||||
"iconAsTemplate": true
|
"iconAsTemplate": true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user