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:
@@ -324,6 +324,12 @@ void Helpers::setBitmappedValue(unsigned int & field, unsigned int value, unsign
|
|||||||
field = (field & ~fieldmask) | (value << (numbits * index + offset));
|
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)
|
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
||||||
{
|
{
|
||||||
QString fwId = SimulatorLoader::findSimulatorByFirmwareName(getCurrentFirmware()->getId());
|
QString fwId = SimulatorLoader::findSimulatorByFirmwareName(getCurrentFirmware()->getId());
|
||||||
@@ -347,6 +353,9 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
|||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
QObject::connect(dialog, &SimulatorMainWindow::destroyed, [simuData] (void) {
|
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
|
// 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;
|
delete simuData;
|
||||||
});
|
});
|
||||||
@@ -359,6 +368,9 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
|||||||
dialog->deleteLater();
|
dialog->deleteLater();
|
||||||
}
|
}
|
||||||
else if (dialog->setRadioData(simuData)) {
|
else if (dialog->setRadioData(simuData)) {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
simulatorRunning = true;
|
||||||
|
#endif
|
||||||
dialog->show();
|
dialog->show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -122,6 +122,11 @@ namespace Helpers
|
|||||||
|
|
||||||
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx);
|
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
|
// Format a pixmap to fit on the current firmware
|
||||||
QPixmap makePixMap(const QImage & image);
|
QPixmap makePixMap(const QImage & image);
|
||||||
|
|
||||||
|
|||||||
@@ -197,6 +197,14 @@ void MainWindow::displayWarnings()
|
|||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
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.mainWinGeo(saveGeometry());
|
||||||
g.mainWinState(saveState());
|
g.mainWinState(saveState());
|
||||||
g.tabbedMdi(actTabbedWindows->isChecked());
|
g.tabbedMdi(actTabbedWindows->isChecked());
|
||||||
|
|||||||
Reference in New Issue
Block a user