mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: enhance clash caller & support more commands
This commit is contained in:
@@ -1,17 +1,31 @@
|
||||
use tauri::api::process::kill_children;
|
||||
|
||||
use crate::utils::{clash, import};
|
||||
use crate::{
|
||||
events::{emit::ClashInfoPayload, state::ClashInfoState},
|
||||
utils::{clash, import},
|
||||
};
|
||||
use tauri::{api::process::kill_children, AppHandle, State};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn cmd_restart_sidebar() {
|
||||
pub fn restart_sidebar(app_handle: AppHandle, clash_info: State<'_, ClashInfoState>) {
|
||||
kill_children();
|
||||
clash::run_clash_bin();
|
||||
let payload = clash::run_clash_bin(&app_handle);
|
||||
|
||||
if let Ok(mut arc) = clash_info.0.lock() {
|
||||
*arc = payload;
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn cmd_import_profile(url: String) -> Result<String, String> {
|
||||
pub async fn import_profile(url: String) -> Result<String, String> {
|
||||
match import::import_profile(&url).await {
|
||||
Ok(_) => Ok(String::from("success")),
|
||||
Err(_) => Err(String::from("error")),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_clash_info(clash_info: State<'_, ClashInfoState>) -> Option<ClashInfoPayload> {
|
||||
match clash_info.0.lock() {
|
||||
Ok(arc) => Some(arc.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user