fix(cpn): Ignore 'Quit' event in main window on MacOS if simulator running (#2874)

Prevents app crashing on exit while the simulator is open.
This commit is contained in:
philmoz
2022-12-20 21:15:35 +10:00
committed by GitHub
parent 4841f0673c
commit af040c9e2e
3 changed files with 25 additions and 0 deletions
+12
View File
@@ -324,6 +324,12 @@ void Helpers::setBitmappedValue(unsigned int & field, unsigned int value, unsign
field = (field & ~fieldmask) | (value << (numbits * index + offset));
}
#ifdef __APPLE__
// Flag when simulator is running
static bool simulatorRunning = false;
bool isSimulatorRunning() { return simulatorRunning; }
#endif
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
{
QString fwId = SimulatorLoader::findSimulatorByFirmwareName(getCurrentFirmware()->getId());
@@ -347,6 +353,9 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
dialog->setAttribute(Qt::WA_DeleteOnClose);
QObject::connect(dialog, &SimulatorMainWindow::destroyed, [simuData] (void) {
#ifdef __APPLE__
simulatorRunning = false;
#endif
// TODO simuData and Horus tmp directory is deleted on simulator close OR we could use it to get back data from the simulation
delete simuData;
});
@@ -359,6 +368,9 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
dialog->deleteLater();
}
else if (dialog->setRadioData(simuData)) {
#ifdef __APPLE__
simulatorRunning = true;
#endif
dialog->show();
}
else {
+5
View File
@@ -122,6 +122,11 @@ namespace Helpers
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx);
#ifdef __APPLE__
// Flag when simulator is running
bool isSimulatorRunning();
#endif
// Format a pixmap to fit on the current firmware
QPixmap makePixMap(const QImage & image);
+8
View File
@@ -197,6 +197,14 @@ void MainWindow::displayWarnings()
void MainWindow::closeEvent(QCloseEvent *event)
{
#ifdef __APPLE__
// If simulator is running ignore this Quit event (simulator will still be closed)
// - prevents app crash on exit
if (isSimulatorRunning()) {
event->ignore();
return;
}
#endif
g.mainWinGeo(saveGeometry());
g.mainWinState(saveState());
g.tabbedMdi(actTabbedWindows->isChecked());