feat: add Windows service for elevated tunnel operations with IPC communication
Add Windows service to handle WireGuard tunnel operations with elevated privileges. Implement IPC server on TCP port 53189 for client-service communication using JSON protocol. Add install-service and uninstall-service commands to NSIS installer hooks for automatic service installation. Replace direct WireGuard calls with IPC requests when running on Windows. Add TunnelRequest and TunnelResponse types for IPC protocol
This commit is contained in:
@@ -17,15 +17,15 @@ pub fn current_tunnel_strategy() -> &'static str {
|
||||
|
||||
pub fn connect(app: &AppHandle, profile_path: &Path) -> Result<(), String> {
|
||||
let backend = bundled_backend(app)?;
|
||||
let status = Command::new(backend)
|
||||
let output = Command::new(backend)
|
||||
.arg("connect")
|
||||
.arg("--profile")
|
||||
.arg(profile_path)
|
||||
.status()
|
||||
.output()
|
||||
.map_err(|err| format!("Unable to start embedded tunnel backend: {}", err))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(format!("Embedded tunnel backend connect failed with status {}", status));
|
||||
if !output.status.success() {
|
||||
return Err(format_helper_error("connect", &output));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -33,15 +33,15 @@ pub fn connect(app: &AppHandle, profile_path: &Path) -> Result<(), String> {
|
||||
|
||||
pub fn disconnect(app: &AppHandle, profile_path: &Path) -> Result<(), String> {
|
||||
let backend = bundled_backend(app)?;
|
||||
let status = Command::new(backend)
|
||||
let output = Command::new(backend)
|
||||
.arg("disconnect")
|
||||
.arg("--profile")
|
||||
.arg(profile_path)
|
||||
.status()
|
||||
.output()
|
||||
.map_err(|err| format!("Unable to stop embedded tunnel backend: {}", err))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(format!("Embedded tunnel backend disconnect failed with status {}", status));
|
||||
if !output.status.success() {
|
||||
return Err(format_helper_error("disconnect", &output));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -68,3 +68,19 @@ fn bundled_backend(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn format_helper_error(action: &str, output: &std::process::Output) -> String {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let details = if !stderr.trim().is_empty() {
|
||||
stderr.trim()
|
||||
} else {
|
||||
stdout.trim()
|
||||
};
|
||||
|
||||
if details.is_empty() {
|
||||
return format!("NexaVPN tunnel backend {} failed with status {}", action, output.status);
|
||||
}
|
||||
|
||||
details.to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user