修改中转站
This commit is contained in:
@@ -15,3 +15,4 @@ pub mod filesystem;
|
||||
pub mod git;
|
||||
pub mod terminal;
|
||||
pub mod ccr;
|
||||
pub mod system;
|
||||
|
62
src-tauri/src/commands/system.rs
Normal file
62
src-tauri/src/commands/system.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
/// Flush system DNS cache across platforms
|
||||
#[tauri::command]
|
||||
pub async fn flush_dns() -> Result<String, String> {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let output = Command::new("ipconfig")
|
||||
.arg("/flushdns")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.map_err(|e| format!("Failed to execute ipconfig: {}", e))?;
|
||||
if output.status.success() {
|
||||
return Ok("DNS cache flushed".into());
|
||||
} else {
|
||||
let err = String::from_utf8_lossy(&output.stderr).to_string();
|
||||
return Err(if err.is_empty() { "ipconfig /flushdns failed".into() } else { err });
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let output = Command::new("dscacheutil")
|
||||
.arg("-flushcache")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.map_err(|e| format!("Failed to execute dscacheutil: {}", e))?;
|
||||
if output.status.success() {
|
||||
return Ok("DNS cache flushed".into());
|
||||
} else {
|
||||
let err = String::from_utf8_lossy(&output.stderr).to_string();
|
||||
return Err(if err.is_empty() { "dscacheutil -flushcache failed".into() } else { err });
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
// Try common Linux methods in order
|
||||
let attempts: Vec<(&str, Vec<&str>)> = vec![
|
||||
("resolvectl", vec!["flush-caches"]),
|
||||
("systemd-resolve", vec!["--flush-caches"]),
|
||||
("sh", vec!["-c", "service nscd restart || service dnsmasq restart || rc-service nscd restart"]),
|
||||
];
|
||||
|
||||
for (cmd, args) in attempts {
|
||||
if let Ok(output) = Command::new(cmd)
|
||||
.args(&args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
{
|
||||
if output.status.success() {
|
||||
return Ok("DNS cache flushed".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
Err("No supported DNS flush method succeeded on this Linux system".into())
|
||||
}
|
||||
}
|
||||
|
@@ -83,6 +83,7 @@ use commands::ccr::{
|
||||
check_ccr_installation, get_ccr_version, get_ccr_service_status, start_ccr_service,
|
||||
stop_ccr_service, restart_ccr_service, open_ccr_ui, get_ccr_config_path,
|
||||
};
|
||||
use commands::system::flush_dns;
|
||||
use process::ProcessRegistryState;
|
||||
use file_watcher::FileWatcherState;
|
||||
use std::sync::Mutex;
|
||||
@@ -431,6 +432,9 @@ fn main() {
|
||||
restart_ccr_service,
|
||||
open_ccr_ui,
|
||||
get_ccr_config_path,
|
||||
|
||||
// System utilities
|
||||
flush_dns,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
Reference in New Issue
Block a user