GH-1874 do not allow updating while an instance is running
This is a nasty hack. Proper solution will require moving all update related functionality out of the main window. Running instances and updating should be mutually exclusive.
This commit is contained in:
		| @@ -561,14 +561,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow | |||||||
| 		updateNewsLabel(); | 		updateNewsLabel(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
| 	if(BuildConfig.UPDATER_ENABLED) | 	if(BuildConfig.UPDATER_ENABLED) | ||||||
| 	{ | 	{ | ||||||
|  | 		bool updatesAllowed = MMC->updatesAreAllowed(); | ||||||
|  | 		updatesAllowedChanged(updatesAllowed); | ||||||
| 		// set up the updater object. | 		// set up the updater object. | ||||||
| 		auto updater = MMC->updateChecker(); | 		auto updater = MMC->updateChecker(); | ||||||
| 		connect(updater.get(), &UpdateChecker::updateAvailable, this, &MainWindow::updateAvailable); | 		connect(updater.get(), &UpdateChecker::updateAvailable, this, &MainWindow::updateAvailable); | ||||||
| 		connect(updater.get(), &UpdateChecker::noUpdateFound, this, &MainWindow::updateNotAvailable); | 		connect(updater.get(), &UpdateChecker::noUpdateFound, this, &MainWindow::updateNotAvailable); | ||||||
| 		// if automatic update checks are allowed, start one. | 		// if automatic update checks are allowed, start one. | ||||||
| 		if (MMC->settings()->get("AutoUpdate").toBool()) | 		if (MMC->settings()->get("AutoUpdate").toBool() && updatesAllowed) | ||||||
| 		{ | 		{ | ||||||
| 			updater->checkForUpdate(MMC->settings()->get("UpdateChannel").toString(), false); | 			updater->checkForUpdate(MMC->settings()->get("UpdateChannel").toString(), false); | ||||||
| 		} | 		} | ||||||
| @@ -795,6 +798,15 @@ void MainWindow::repopulateAccountsMenu() | |||||||
| 	accountMenu->addAction(manageAccountsAction); | 	accountMenu->addAction(manageAccountsAction); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void MainWindow::updatesAllowedChanged(bool allowed) | ||||||
|  | { | ||||||
|  | 	if(!BuildConfig.UPDATER_ENABLED) | ||||||
|  | 	{ | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	ui->actionCheckUpdate->setEnabled(allowed); | ||||||
|  | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Assumes the sender is a QAction |  * Assumes the sender is a QAction | ||||||
|  */ |  */ | ||||||
| @@ -896,6 +908,11 @@ void MainWindow::updateNewsLabel() | |||||||
|  |  | ||||||
| void MainWindow::updateAvailable(GoUpdate::Status status) | void MainWindow::updateAvailable(GoUpdate::Status status) | ||||||
| { | { | ||||||
|  | 	if(!MMC->updatesAreAllowed()) | ||||||
|  | 	{ | ||||||
|  | 		updateNotAvailable(); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
| 	UpdateDialog dlg; | 	UpdateDialog dlg; | ||||||
| 	UpdateAction action = (UpdateAction)dlg.exec(); | 	UpdateAction action = (UpdateAction)dlg.exec(); | ||||||
| 	switch (action) | 	switch (action) | ||||||
| @@ -955,6 +972,10 @@ void MainWindow::notificationsChanged() | |||||||
|  |  | ||||||
| void MainWindow::downloadUpdates(GoUpdate::Status status) | void MainWindow::downloadUpdates(GoUpdate::Status status) | ||||||
| { | { | ||||||
|  | 	if(!MMC->updatesAreAllowed()) | ||||||
|  | 	{ | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
| 	qDebug() << "Downloading updates."; | 	qDebug() << "Downloading updates."; | ||||||
| 	ProgressDialog updateDlg(this); | 	ProgressDialog updateDlg(this); | ||||||
| 	status.rootPath = MMC->root(); | 	status.rootPath = MMC->root(); | ||||||
|   | |||||||
| @@ -54,6 +54,7 @@ public: | |||||||
|  |  | ||||||
| 	void checkInstancePathForProblems(); | 	void checkInstancePathForProblems(); | ||||||
|  |  | ||||||
|  | 	void updatesAllowedChanged(bool allowed); | ||||||
| signals: | signals: | ||||||
| 	void isClosing(); | 	void isClosing(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -965,7 +965,7 @@ bool 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); | ||||||
| 		m_runningInstances ++; | 		addRunningInstance(); | ||||||
| 		controller->start(); | 		controller->start(); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| @@ -994,6 +994,38 @@ bool MultiMC::kill(InstancePtr instance) | |||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void MultiMC::addRunningInstance() | ||||||
|  | { | ||||||
|  | 	m_runningInstances ++; | ||||||
|  | 	if(m_runningInstances == 1) | ||||||
|  | 	{ | ||||||
|  | 		emit updateAllowedChanged(false); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void MultiMC::subRunningInstance() | ||||||
|  | { | ||||||
|  | 	if(m_runningInstances == 0) | ||||||
|  | 	{ | ||||||
|  | 		qCritical() << "Something went really wrong and we now have less than 0 running instances... WTF"; | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	m_runningInstances --; | ||||||
|  | 	if(m_runningInstances == 0) | ||||||
|  | 	{ | ||||||
|  | 		emit updateAllowedChanged(true); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool MultiMC::shouldExitNow() const | ||||||
|  | { | ||||||
|  | 	return m_runningInstances == 0 && m_openWindows == 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool MultiMC::updatesAreAllowed() | ||||||
|  | { | ||||||
|  | 	return m_runningInstances == 0; | ||||||
|  | } | ||||||
|  |  | ||||||
| void MultiMC::controllerSucceeded() | void MultiMC::controllerSucceeded() | ||||||
| { | { | ||||||
| @@ -1012,10 +1044,10 @@ void MultiMC::controllerSucceeded() | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	extras.controller.reset(); | 	extras.controller.reset(); | ||||||
| 	m_runningInstances --; | 	subRunningInstance(); | ||||||
|  |  | ||||||
| 	// quit when there are no more windows. | 	// quit when there are no more windows. | ||||||
| 	if(m_openWindows == 0 && m_runningInstances == 0) | 	if(shouldExitNow()) | ||||||
| 	{ | 	{ | ||||||
| 		m_status = Status::Succeeded; | 		m_status = Status::Succeeded; | ||||||
| 		exit(0); | 		exit(0); | ||||||
| @@ -1033,10 +1065,10 @@ void MultiMC::controllerFailed(const QString& error) | |||||||
|  |  | ||||||
| 	// on failure, do... nothing | 	// on failure, do... nothing | ||||||
| 	extras.controller.reset(); | 	extras.controller.reset(); | ||||||
| 	m_runningInstances --; | 	subRunningInstance(); | ||||||
|  |  | ||||||
| 	// quit when there are no more windows. | 	// quit when there are no more windows. | ||||||
| 	if(m_openWindows == 0 && m_runningInstances == 0) | 	if(shouldExitNow()) | ||||||
| 	{ | 	{ | ||||||
| 		m_status = Status::Failed; | 		m_status = Status::Failed; | ||||||
| 		exit(1); | 		exit(1); | ||||||
| @@ -1066,6 +1098,7 @@ MainWindow* MultiMC::showMainWindow(bool minimized) | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		m_mainWindow->checkInstancePathForProblems(); | 		m_mainWindow->checkInstancePathForProblems(); | ||||||
|  | 		connect(this, &MultiMC::updateAllowedChanged, m_mainWindow, &MainWindow::updatesAllowedChanged); | ||||||
| 		connect(m_mainWindow, &MainWindow::isClosing, this, &MultiMC::on_windowClose); | 		connect(m_mainWindow, &MainWindow::isClosing, this, &MultiMC::on_windowClose); | ||||||
| 		m_openWindows++; | 		m_openWindows++; | ||||||
| 	} | 	} | ||||||
| @@ -1155,7 +1188,7 @@ void MultiMC::on_windowClose() | |||||||
| 		m_mainWindow = nullptr; | 		m_mainWindow = nullptr; | ||||||
| 	} | 	} | ||||||
| 	// quit when there are no more windows. | 	// quit when there are no more windows. | ||||||
| 	if(m_openWindows == 0 && m_runningInstances == 0) | 	if(shouldExitNow()) | ||||||
| 	{ | 	{ | ||||||
| 		exit(0); | 		exit(0); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -151,6 +151,11 @@ public: | |||||||
| 		return m_runningInstances; | 		return m_runningInstances; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	bool updatesAreAllowed(); | ||||||
|  |  | ||||||
|  | signals: | ||||||
|  | 	void updateAllowedChanged(bool status); | ||||||
|  |  | ||||||
| public slots: | public slots: | ||||||
| 	bool launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr); | 	bool launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr); | ||||||
| 	bool kill(InstancePtr instance); | 	bool kill(InstancePtr instance); | ||||||
| @@ -186,6 +191,11 @@ private: | |||||||
| 	// sets the fatal error message and m_status to Failed. | 	// sets the fatal error message and m_status to Failed. | ||||||
| 	void showFatalErrorMessage(const QString & title, const QString & content); | 	void showFatalErrorMessage(const QString & title, const QString & content); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	void addRunningInstance(); | ||||||
|  | 	void subRunningInstance(); | ||||||
|  | 	bool shouldExitNow() const; | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	QDateTime startTime; | 	QDateTime startTime; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Petr Mrázek
					Petr Mrázek