mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-30 18:10:04 +08:00
* refactor(config): adopt tristr for config strings Wire the tristr git dependency (pinned rev) and switch the config and enhance modules from smartstring::alias::String to tristr::alias::String. Drop the smartstring-era per-field specta overrides except the three webdav fields required by serialize_with and the ipc::JsonValue bridge: tristr maps to Primitive::str natively and the generated bindings stay byte-identical (gen-contract --check passes). Call sites in not-yet-migrated modules (cmd/core/feat/utils) are bridged with explicit tristr::alias::String paths and as_str().into() conversions; each bridge is absorbed when its module migrates. * refactor(cmd): adopt tristr for command strings Switch the cmd module from smartstring::alias::String to tristr::alias::String and drop its smartstring-era per-field specta overrides (ProfileSelection/ProfileCreate/ProfilePatch, RuntimeLogs); bindings stay byte-identical. Calls into not-yet-migrated feat/core functions keep smartstring-typed locals via full paths until those modules migrate. * refactor(core): adopt tristr for core strings Switch the core module (validate, timer, sysopt, backup, hotkey, tray, manager, notify) from smartstring::alias::String to tristr::alias::String and drop the smartstring-era specta overrides on ValidationOutcome and the notify payload structs; bindings stay byte-identical. WebDAV calls from the not-yet-migrated feat module are bridged with as_str().into(). * refactor(feat): adopt tristr for feature strings Switch the feat module (backup, icon, dns, profile, clash) from smartstring::alias::String to tristr::alias::String, drop its smartstring-era specta overrides (IconInfo, backup listings, DnsOverrideOutcome), and absorb the temporary smartstring-typed bridge locals the cmd module used to call into feat. * refactor(utils): adopt tristr for utility strings Switch utils/network.rs and utils/resolve/scheme.rs from smartstring::alias::String to tristr::alias::String and absorb the temporary user_agent and profile-name bridge conversions. * refactor(deps): drop smartstring in favor of tristr Remove the smartstring workspace and member dependencies and its Cargo.lock entry; tristr is the only string representation left. * build(deps): bump tristr to fuzz-harness fix rev Pin 3738d8c renames the stale vstr path dependency in the upstream fuzz manifest so its seven targets build again; library code is unchanged from 3756ed1a.
122 lines
3.2 KiB
Rust
122 lines
3.2 KiB
Rust
use super::NoticeStatus;
|
|
use crate::{APP_HANDLE, singleton};
|
|
use std::sync::{
|
|
Arc,
|
|
atomic::{AtomicBool, Ordering},
|
|
};
|
|
use tauri::AppHandle;
|
|
use tauri_plugin_mihomo::{Mihomo, MihomoExt as _};
|
|
#[cfg(target_os = "macos")]
|
|
use tristr::alias::String;
|
|
|
|
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) {
|
|
Self::send_event(FrontendEvent::RunStateChanged { state: state.clone() });
|
|
}
|
|
|
|
pub fn notify_profile_changed(profile_id: &str) {
|
|
Self::send_event(FrontendEvent::ProfileChanged {
|
|
current_profile_id: profile_id,
|
|
});
|
|
}
|
|
|
|
pub fn notify_timer_updated(profile_index: &str) {
|
|
Self::send_event(FrontendEvent::TimerUpdated { profile_index });
|
|
}
|
|
|
|
pub fn notify_profile_update_started(uid: &str) {
|
|
Self::send_event(FrontendEvent::ProfileUpdateStarted { uid });
|
|
}
|
|
|
|
pub fn notify_profile_update_completed(uid: &str) {
|
|
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);
|
|
}
|
|
}
|