[dekstop] Add subscription to the shutdown event

This commit is contained in:
Vladimir Stoilov 2024-05-22 15:22:29 +03:00
parent 0b52c5347a
commit 3131fb28cc
No known key found for this signature in database
GPG key ID: 2F190B67A43A81AF

View file

@ -260,6 +260,22 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
}
};
let mut portmaster_shutdown_event_subscription = match cli
.request(Request::Subscribe(
"query runtime:modules/core/event/shutdown".to_string(),
))
.await
{
Ok(rx) => rx,
Err(err) => {
error!(
"cancel try_handler: failed to subscribe to 'runtime:modules/core/event/shutdown': {}",
err
);
return;
}
};
_ = icon.set_icon(Some(Image::from_bytes(BLUE_ICON).unwrap()));
let mut subsystems: HashMap<String, Subsystem> = HashMap::new();
@ -358,6 +374,17 @@ pub async fn tray_handler(cli: PortAPI, app: tauri::AppHandle) {
}
}
}
},
msg = portmaster_shutdown_event_subscription.recv() => {
let msg = match msg {
Some(m) => m,
None => { break }
};
debug!("Shutdown request received: {:?}", msg);
match msg {
Response::Ok(_, _) | Response::New(_, _) | Response::Update(_, _) => app.exit(0),
_ => {},
}
}
}
}