NOISSUE ask user if closing is OK when instances are still running
This commit is contained in:
parent
8b952b3870
commit
1276ecdbb7
@ -1356,12 +1356,27 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered()
|
|||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
// Save the window state and geometry.
|
if(MMC->numRunningInstances())
|
||||||
|
{
|
||||||
|
auto resBtn = QMessageBox::question(
|
||||||
|
this,
|
||||||
|
tr("Do you want to close MultiMC?"),
|
||||||
|
tr("<p>You still have instances running.</p><p>Closing MultiMC will result in inaccurate time tracking and no Minecraft crash handling.</p><p>Are you sure?</p>"),
|
||||||
|
QMessageBox::No | QMessageBox::Yes,
|
||||||
|
QMessageBox::Yes
|
||||||
|
);
|
||||||
|
if (resBtn != QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no running instances or user said yes.
|
||||||
|
event->accept();
|
||||||
|
// Save the window state and geometry.
|
||||||
MMC->settings()->set("MainWindowState", saveState().toBase64());
|
MMC->settings()->set("MainWindowState", saveState().toBase64());
|
||||||
MMC->settings()->set("MainWindowGeometry", saveGeometry().toBase64());
|
MMC->settings()->set("MainWindowGeometry", saveGeometry().toBase64());
|
||||||
|
|
||||||
QMainWindow::closeEvent(event);
|
|
||||||
QApplication::exit();
|
QApplication::exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1104,6 +1104,7 @@ void MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *pro
|
|||||||
connect(controller.get(), &LaunchController::succeeded, this, &MultiMC::controllerSucceeded);
|
connect(controller.get(), &LaunchController::succeeded, this, &MultiMC::controllerSucceeded);
|
||||||
connect(controller.get(), &LaunchController::failed, this, &MultiMC::controllerFailed);
|
connect(controller.get(), &LaunchController::failed, this, &MultiMC::controllerFailed);
|
||||||
controller->start();
|
controller->start();
|
||||||
|
m_runningInstances ++;
|
||||||
}
|
}
|
||||||
else if (instance->isRunning())
|
else if (instance->isRunning())
|
||||||
{
|
{
|
||||||
@ -1118,6 +1119,7 @@ void MultiMC::controllerSucceeded()
|
|||||||
return;
|
return;
|
||||||
auto id = controller->id();
|
auto id = controller->id();
|
||||||
auto & extras = m_instanceExtras[id];
|
auto & extras = m_instanceExtras[id];
|
||||||
|
|
||||||
// on success, do...
|
// on success, do...
|
||||||
if (controller->instance()->settings()->get("AutoCloseConsole").toBool())
|
if (controller->instance()->settings()->get("AutoCloseConsole").toBool())
|
||||||
{
|
{
|
||||||
@ -1127,8 +1129,10 @@ void MultiMC::controllerSucceeded()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
extras.controller.reset();
|
extras.controller.reset();
|
||||||
|
m_runningInstances --;
|
||||||
|
|
||||||
// quit when there are no more windows.
|
// quit when there are no more windows.
|
||||||
if(m_openWindows == 0)
|
if(m_openWindows == 0 && m_runningInstances == 0)
|
||||||
{
|
{
|
||||||
m_status = Status::Succeeded;
|
m_status = Status::Succeeded;
|
||||||
quit();
|
quit();
|
||||||
@ -1146,8 +1150,10 @@ void MultiMC::controllerFailed(const QString& error)
|
|||||||
|
|
||||||
// on failure, do... nothing
|
// on failure, do... nothing
|
||||||
extras.controller.reset();
|
extras.controller.reset();
|
||||||
|
m_runningInstances --;
|
||||||
|
|
||||||
// quit when there are no more windows.
|
// quit when there are no more windows.
|
||||||
if(m_openWindows == 0)
|
if(m_openWindows == 0 && m_runningInstances == 0)
|
||||||
{
|
{
|
||||||
m_status = Status::Failed;
|
m_status = Status::Failed;
|
||||||
quit();
|
quit();
|
||||||
|
@ -144,6 +144,11 @@ public:
|
|||||||
InstanceWindow *showInstanceWindow(InstancePtr instance, QString page = QString());
|
InstanceWindow *showInstanceWindow(InstancePtr instance, QString page = QString());
|
||||||
MainWindow *showMainWindow(bool minimized = false);
|
MainWindow *showMainWindow(bool minimized = false);
|
||||||
|
|
||||||
|
size_t numRunningInstances()
|
||||||
|
{
|
||||||
|
return m_runningInstances;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
|
void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
|
||||||
|
|
||||||
@ -208,6 +213,7 @@ private:
|
|||||||
};
|
};
|
||||||
std::map<QString, InstanceXtras> m_instanceExtras;
|
std::map<QString, InstanceXtras> m_instanceExtras;
|
||||||
size_t m_openWindows = 0;
|
size_t m_openWindows = 0;
|
||||||
|
size_t m_runningInstances = 0;
|
||||||
|
|
||||||
// main window, if any
|
// main window, if any
|
||||||
MainWindow * m_mainWindow = nullptr;
|
MainWindow * m_mainWindow = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user