mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-04-22 22:29:30 +00:00
Proper handling of direct kill
This commit is contained in:
@@ -954,9 +954,10 @@ private:
|
|||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
// Check if app is already open
|
|
||||||
QSharedMemory sharedMemory;
|
QSharedMemory sharedMemory;
|
||||||
sharedMemory.setKey("TcpServer-Key");
|
sharedMemory.setKey("TcpServer-Key");
|
||||||
|
|
||||||
|
// Check if app is already open
|
||||||
if(sharedMemory.create(1) == false)
|
if(sharedMemory.create(1) == false)
|
||||||
{
|
{
|
||||||
LOG_INFO("Another instance already running! Opening App Window Instead");
|
LOG_INFO("Another instance already running! Opening App Window Instead");
|
||||||
@@ -968,15 +969,15 @@ int main(int argc, char *argv[]) {
|
|||||||
socket.flush();
|
socket.flush();
|
||||||
socket.waitForBytesWritten(500);
|
socket.waitForBytesWritten(500);
|
||||||
socket.disconnectFromServer();
|
socket.disconnectFromServer();
|
||||||
|
app.exit(); // exit; process already running
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Failed connection, log and abort
|
// Failed connection, log and open the app (assume it's not running)
|
||||||
LOG_ERROR("Failed to connect to the original app instance");
|
LOG_ERROR("Failed to connect to the original app instance. Assuming it is not running.");
|
||||||
LOG_DEBUG("Socket error: " << socket.errorString());
|
LOG_DEBUG("Socket error: " << socket.errorString());
|
||||||
}
|
}
|
||||||
app.exit(); // exit; process already running
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
app.setQuitOnLastWindowClosed(false);
|
app.setQuitOnLastWindowClosed(false);
|
||||||
|
|
||||||
@@ -1043,6 +1044,11 @@ int main(int argc, char *argv[]) {
|
|||||||
LOG_DEBUG("Server error: " << server.errorString());
|
LOG_DEBUG("Server error: " << server.errorString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&]() {
|
||||||
|
LOG_DEBUG("Application is about to quit. Cleaning up...");
|
||||||
|
sharedMemory.detach();
|
||||||
|
});
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user