mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-24 12:42:22 +08:00
* refactor(core): type notice statuses behind the frozen wire contract * refactor(utils): unified retry and strategy-list helpers * refactor(feat): declarative effect registry for verge and clash patches * refactor(core): derive refresh announcements from transaction commit * refactor(core): fold tray, hotkey, autostart updates into effect ensures * refactor(utils): migrate remaining bounded retry loops * docs: add src-tauri architecture guardrails * refactor(core): coalesce burst refresh announcements * refactor(core): complete bounded service retry migration * ci(backend): add architecture ban gates * test(feat): freeze representative effect registry mappings * docs(backend): record dead wire contract entries * chore(core): document watcher exit conditions * fix(backend): preserve applied state across later failures * fix(config): retain runtime after an applied core replacement * refactor(backend): flatten refresh publication and retry policies * docs(backend): focus guardrails on architecture ownership * refactor(effects): use one execution order * fix(config): publish retained runtime and reconcile proxy settings
124 lines
3.2 KiB
Rust
124 lines
3.2 KiB
Rust
use super::NoticeStatus;
|
|
use crate::{APP_HANDLE, singleton};
|
|
use smartstring::alias::String;
|
|
use std::sync::{
|
|
Arc,
|
|
atomic::{AtomicBool, Ordering},
|
|
};
|
|
use tauri::AppHandle;
|
|
use tauri_plugin_mihomo::{Mihomo, MihomoExt as _};
|
|
|
|
use super::notification::{FrontendEvent, NotificationSystem};
|
|
|
|
#[derive(Debug)]
|
|
pub struct Handle {
|
|
is_exiting: AtomicBool,
|
|
}
|
|
|
|
impl Default for Handle {
|
|
fn default() -> Self {
|
|
Self {
|
|
is_exiting: AtomicBool::new(false),
|
|
}
|
|
}
|
|
}
|
|
|
|
singleton!(Handle, HANDLE);
|
|
|
|
impl Handle {
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
pub fn app_handle() -> &'static AppHandle {
|
|
#[allow(clippy::expect_used)]
|
|
APP_HANDLE.get().expect("App handle not initialized")
|
|
}
|
|
|
|
pub fn mihomo() -> &'static Mihomo {
|
|
Self::app_handle().mihomo()
|
|
}
|
|
|
|
pub fn refresh_clash() {
|
|
super::announce(super::Refresh::Clash);
|
|
}
|
|
|
|
pub fn refresh_verge() {
|
|
super::announce(super::Refresh::Verge);
|
|
}
|
|
|
|
/// Push a Run State snapshot to the frontend.
|
|
///
|
|
/// Sent on every transition, so the frontend does not have to poll to notice that the Core
|
|
/// stopped or that the Service came back.
|
|
pub fn notify_run_state(state: &crate::core::runstate::RunStateView) {
|
|
let Ok(state) = serde_json::to_value(state) else {
|
|
return;
|
|
};
|
|
Self::send_event(FrontendEvent::RunStateChanged { state });
|
|
}
|
|
|
|
pub fn notify_profile_changed(profile_id: &String) {
|
|
Self::send_event(FrontendEvent::ProfileChanged {
|
|
current_profile_id: profile_id,
|
|
});
|
|
}
|
|
|
|
pub fn notify_timer_updated(profile_index: &String) {
|
|
Self::send_event(FrontendEvent::TimerUpdated { profile_index });
|
|
}
|
|
|
|
pub fn notify_profile_update_started(uid: &String) {
|
|
Self::send_event(FrontendEvent::ProfileUpdateStarted { uid });
|
|
}
|
|
|
|
pub fn notify_profile_update_completed(uid: &String) {
|
|
Self::send_event(FrontendEvent::ProfileUpdateCompleted { uid });
|
|
}
|
|
|
|
pub fn notice(status: NoticeStatus, message: impl Into<Arc<str>>) {
|
|
Self::send_event(FrontendEvent::NoticeMessage {
|
|
status,
|
|
message: message.into(),
|
|
});
|
|
}
|
|
|
|
pub fn set_is_exiting(&self) {
|
|
self.is_exiting.store(true, Ordering::Release);
|
|
}
|
|
|
|
pub fn clear_is_exiting(&self) {
|
|
self.is_exiting.store(false, Ordering::Release);
|
|
}
|
|
|
|
pub fn is_exiting(&self) -> bool {
|
|
self.is_exiting.load(Ordering::Acquire)
|
|
}
|
|
|
|
pub(super) fn send_event(event: FrontendEvent) {
|
|
let handle = Self::global();
|
|
if handle.is_exiting() {
|
|
return;
|
|
}
|
|
|
|
NotificationSystem::send_event(Self::app_handle().clone(), event);
|
|
}
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
impl Handle {
|
|
pub fn set_activation_policy(&self, policy: tauri::ActivationPolicy) -> Result<(), String> {
|
|
Self::app_handle()
|
|
.set_activation_policy(policy)
|
|
.map_err(|e| e.to_string().into())
|
|
}
|
|
|
|
pub fn set_activation_policy_regular(&self) {
|
|
let _ = self.set_activation_policy(tauri::ActivationPolicy::Regular);
|
|
}
|
|
|
|
pub fn set_activation_policy_accessory(&self) {
|
|
let _ = self.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
|
}
|
|
}
|