feat: add fallback tunnel status check and improve Windows service command calls
Add fallback to tunnel_status when metrics query fails in current_metrics function, returning zero bytes with actual tunnel state. Update waitForTunnelStatus in frontend to use tunnel_status instead of tunnel_metrics for status polling and refresh metrics separately on success. Change CloseRequested window event handler to call app_handle().exit(0) instead of no-op. Replace "sc" with "sc.exe" in all Windows service command
This commit is contained in:
@@ -403,11 +403,21 @@ fn current_metrics(app: &AppHandle) -> Result<TunnelMetrics, String> {
|
||||
let session = session.as_ref().ok_or_else(|| "No active session is available".to_string())?;
|
||||
session.profile_path.clone()
|
||||
};
|
||||
tunnel_manager::metrics(app, std::path::Path::new(&profile_path)).map(|metrics| TunnelMetrics {
|
||||
active: metrics.active,
|
||||
rx_bytes: metrics.rx_bytes,
|
||||
tx_bytes: metrics.tx_bytes,
|
||||
})
|
||||
match tunnel_manager::metrics(app, std::path::Path::new(&profile_path)) {
|
||||
Ok(metrics) => Ok(TunnelMetrics {
|
||||
active: metrics.active,
|
||||
rx_bytes: metrics.rx_bytes,
|
||||
tx_bytes: metrics.tx_bytes,
|
||||
}),
|
||||
Err(_) => {
|
||||
let active = tunnel_manager::is_active(app, std::path::Path::new(&profile_path))?;
|
||||
Ok(TunnelMetrics {
|
||||
active,
|
||||
rx_bytes: 0,
|
||||
tx_bytes: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn sync_current_session(app: &AppHandle) -> Result<SessionState, String> {
|
||||
@@ -658,7 +668,9 @@ pub fn run() {
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| match event {
|
||||
WindowEvent::CloseRequested { .. } => {}
|
||||
WindowEvent::CloseRequested { .. } => {
|
||||
window.app_handle().exit(0);
|
||||
}
|
||||
WindowEvent::Resized(_) => {
|
||||
if window.is_minimized().unwrap_or(false) {
|
||||
hide_main_window(window);
|
||||
|
||||
Reference in New Issue
Block a user