mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-27 07:40:05 +08:00
refactor: optimize profile change notifications to use references
This commit is contained in:
@@ -44,27 +44,26 @@ impl Handle {
|
||||
Self::send_event(FrontendEvent::RefreshVerge);
|
||||
}
|
||||
|
||||
pub fn notify_profile_changed(profile_id: String) {
|
||||
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) {
|
||||
pub fn notify_timer_updated(profile_index: &String) {
|
||||
Self::send_event(FrontendEvent::TimerUpdated { profile_index });
|
||||
}
|
||||
|
||||
pub fn notify_profile_update_started(uid: String) {
|
||||
pub fn notify_profile_update_started(uid: &String) {
|
||||
Self::send_event(FrontendEvent::ProfileUpdateStarted { uid });
|
||||
}
|
||||
|
||||
pub fn notify_profile_update_completed(uid: String) {
|
||||
pub fn notify_profile_update_completed(uid: &String) {
|
||||
Self::send_event(FrontendEvent::ProfileUpdateCompleted { uid });
|
||||
}
|
||||
|
||||
// TODO 利用 &str 等缩短 Clone
|
||||
pub fn notice_message<S: Into<String>, M: Into<String>>(status: S, msg: M) {
|
||||
let status_str = status.into();
|
||||
pub fn notice_message<S: AsRef<str>, M: Into<String>>(status: S, msg: M) {
|
||||
let status_str = status.as_ref();
|
||||
let msg_str = msg.into();
|
||||
|
||||
Self::send_event(FrontendEvent::NoticeMessage {
|
||||
|
||||
@@ -5,16 +5,15 @@ use smartstring::alias::String;
|
||||
|
||||
use tauri::{Emitter as _, WebviewWindow};
|
||||
|
||||
// TODO 重构或优化,避免 Clone 过多
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum FrontendEvent {
|
||||
#[derive(Debug)]
|
||||
pub enum FrontendEvent<'a> {
|
||||
RefreshClash,
|
||||
RefreshVerge,
|
||||
NoticeMessage { status: String, message: String },
|
||||
ProfileChanged { current_profile_id: String },
|
||||
TimerUpdated { profile_index: String },
|
||||
ProfileUpdateStarted { uid: String },
|
||||
ProfileUpdateCompleted { uid: String },
|
||||
NoticeMessage { status: &'a str, message: String },
|
||||
ProfileChanged { current_profile_id: &'a String },
|
||||
TimerUpdated { profile_index: &'a String },
|
||||
ProfileUpdateStarted { uid: &'a String },
|
||||
ProfileUpdateCompleted { uid: &'a String },
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -409,12 +409,12 @@ impl Timer {
|
||||
}
|
||||
|
||||
/// Emit update events for frontend notification
|
||||
fn emit_update_event(_uid: &str, _is_start: bool) {
|
||||
fn emit_update_event(uid: &String, is_start: bool) {
|
||||
{
|
||||
if _is_start {
|
||||
super::handle::Handle::notify_profile_update_started(_uid.into());
|
||||
if is_start {
|
||||
super::handle::Handle::notify_profile_update_started(uid);
|
||||
} else {
|
||||
super::handle::Handle::notify_profile_update_completed(_uid.into());
|
||||
super::handle::Handle::notify_profile_update_completed(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user