SpiceAgent: Gracefully exit when the Spice server disconnects

This commit is contained in:
Timothy Flynn 2023-05-21 13:58:25 -04:00 committed by Andreas Kling
parent 36d61c01bc
commit 35fdc7f8c8
Notes: sideshowbarker 2024-07-17 05:06:13 +09:00
3 changed files with 13 additions and 1 deletions

View File

@ -217,6 +217,12 @@ ErrorOr<void> SpiceAgent::on_message_received()
dbgln_if(SPICE_AGENT_DEBUG, "Ignored message: {}", header);
break;
case Message::Type::Disconnected:
dbgln_if(SPICE_AGENT_DEBUG, "Spice server disconnected");
if (on_disconnected_from_spice_server)
on_disconnected_from_spice_server();
break;
default:
dbgln("Unknown message received: {}", header);
break;

View File

@ -62,6 +62,8 @@ public:
return {};
}
Function<void()> on_disconnected_from_spice_server;
private:
NonnullOwnPtr<Core::File> m_spice_device;
Vector<Capability> m_capabilities;

View File

@ -35,7 +35,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::unveil(nullptr, nullptr));
auto agent = TRY(SpiceAgent::SpiceAgent::create(SPICE_DEVICE));
TRY(agent->start());
agent->on_disconnected_from_spice_server = [&]() {
app->quit();
};
TRY(agent->start());
return app->exec();
}