GH-1645 reimplement open/close instance window based on settings
This commit is contained in:
parent
4b03dfcbd7
commit
fe68d59460
@ -90,10 +90,8 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget *parent)
|
||||
{
|
||||
auto launchTask = m_instance->getLaunchTask();
|
||||
on_InstanceLaunchTask_changed(launchTask);
|
||||
connect(m_instance.get(), &BaseInstance::launchTaskChanged,
|
||||
this, &InstanceWindow::on_InstanceLaunchTask_changed);
|
||||
connect(m_instance.get(), &BaseInstance::runningStatusChanged,
|
||||
this, &InstanceWindow::on_RunningState_changed);
|
||||
connect(m_instance.get(), &BaseInstance::launchTaskChanged, this, &InstanceWindow::on_InstanceLaunchTask_changed);
|
||||
connect(m_instance.get(), &BaseInstance::runningStatusChanged, this, &InstanceWindow::on_RunningState_changed);
|
||||
}
|
||||
|
||||
// set up instance destruction detection
|
||||
@ -128,22 +126,7 @@ void InstanceWindow::setKillButton(bool kill)
|
||||
|
||||
void InstanceWindow::on_InstanceLaunchTask_changed(std::shared_ptr<LaunchTask> proc)
|
||||
{
|
||||
if(m_proc)
|
||||
{
|
||||
disconnect(m_proc.get(), &LaunchTask::succeeded, this, &InstanceWindow::onSucceeded);
|
||||
disconnect(m_proc.get(), &LaunchTask::failed, this, &InstanceWindow::onFailed);
|
||||
disconnect(m_proc.get(), &LaunchTask::requestProgress, this, &InstanceWindow::onProgressRequested);
|
||||
}
|
||||
|
||||
m_proc = proc;
|
||||
|
||||
if(m_proc)
|
||||
{
|
||||
// Set up signal connections
|
||||
connect(m_proc.get(), &LaunchTask::succeeded, this, &InstanceWindow::onSucceeded);
|
||||
connect(m_proc.get(), &LaunchTask::failed, this, &InstanceWindow::onFailed);
|
||||
connect(m_proc.get(), &LaunchTask::requestProgress, this, &InstanceWindow::onProgressRequested);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceWindow::on_RunningState_changed(bool running)
|
||||
@ -202,34 +185,6 @@ void InstanceWindow::on_btnKillMinecraft_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceWindow::onSucceeded()
|
||||
{
|
||||
if (m_instance->settings()->get("AutoCloseConsole").toBool() && m_container->prepareToClose())
|
||||
{
|
||||
this->close();
|
||||
return;
|
||||
}
|
||||
// Raise Window
|
||||
if (MMC->settings()->get("RaiseConsole").toBool())
|
||||
{
|
||||
show();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceWindow::onFailed(QString reason)
|
||||
{
|
||||
}
|
||||
|
||||
void InstanceWindow::onProgressRequested(Task* task)
|
||||
{
|
||||
ProgressDialog progDialog(this);
|
||||
progDialog.setSkipButton(true, tr("Abort"));
|
||||
m_proc->proceed();
|
||||
progDialog.execWithTask(task);
|
||||
}
|
||||
|
||||
QString InstanceWindow::instanceId()
|
||||
{
|
||||
return m_instance->id();
|
||||
|
@ -47,10 +47,6 @@ slots:
|
||||
void on_closeButton_clicked();
|
||||
void on_btnKillMinecraft_clicked();
|
||||
|
||||
void onSucceeded();
|
||||
void onFailed(QString reason);
|
||||
void onProgressRequested(Task *task);
|
||||
|
||||
void on_InstanceLaunchTask_changed(std::shared_ptr<LaunchTask> proc);
|
||||
void on_RunningState_changed(bool running);
|
||||
void on_instanceStatusChanged(BaseInstance::Status, BaseInstance::Status newStatus);
|
||||
|
@ -206,11 +206,15 @@ void LaunchController::launchInstance()
|
||||
}
|
||||
|
||||
auto console = qobject_cast<InstanceWindow *>(m_parentWidget);
|
||||
if(!console)
|
||||
if(!console && m_showConsole)
|
||||
{
|
||||
MMC->showInstanceWindow(m_instance);
|
||||
}
|
||||
connect(m_launcher.get(), &LaunchTask::readyForLaunch, this, &LaunchController::readyForLaunch);
|
||||
connect(m_launcher.get(), &LaunchTask::succeeded, this, &LaunchController::onSucceeded);
|
||||
connect(m_launcher.get(), &LaunchTask::failed, this, &LaunchController::onFailed);
|
||||
connect(m_launcher.get(), &LaunchTask::requestProgress, this, &LaunchController::onProgressRequested);
|
||||
|
||||
|
||||
m_launcher->prependStep(std::make_shared<TextPrint>(m_launcher.get(), "MultiMC version: " + BuildConfig.printableVersionString() + "\n\n", MessageLevel::MultiMC));
|
||||
m_launcher->start();
|
||||
@ -221,7 +225,6 @@ void LaunchController::readyForLaunch()
|
||||
if (!m_profiler)
|
||||
{
|
||||
m_launcher->proceed();
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -247,7 +250,6 @@ void LaunchController::readyForLaunch()
|
||||
msg.setModal(true);
|
||||
msg.exec();
|
||||
m_launcher->proceed();
|
||||
emitSucceeded();
|
||||
});
|
||||
connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString & message)
|
||||
{
|
||||
@ -263,3 +265,21 @@ void LaunchController::readyForLaunch()
|
||||
});
|
||||
profilerInstance->beginProfiling(m_launcher);
|
||||
}
|
||||
|
||||
void LaunchController::onSucceeded()
|
||||
{
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void LaunchController::onFailed(QString reason)
|
||||
{
|
||||
emitFailed(reason);
|
||||
}
|
||||
|
||||
void LaunchController::onProgressRequested(Task* task)
|
||||
{
|
||||
ProgressDialog progDialog(m_parentWidget);
|
||||
progDialog.setSkipButton(true, tr("Abort"));
|
||||
m_launcher->proceed();
|
||||
progDialog.execWithTask(task);
|
||||
}
|
||||
|
@ -17,6 +17,10 @@ public:
|
||||
{
|
||||
m_instance = instance;
|
||||
}
|
||||
InstancePtr instance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
void setOnline(bool online)
|
||||
{
|
||||
m_online = online;
|
||||
@ -29,6 +33,14 @@ public:
|
||||
{
|
||||
m_parentWidget = widget;
|
||||
}
|
||||
void setShowConsole(bool showConsole)
|
||||
{
|
||||
m_showConsole = showConsole;
|
||||
}
|
||||
QString id()
|
||||
{
|
||||
return m_instance->id();
|
||||
}
|
||||
|
||||
private:
|
||||
void login();
|
||||
@ -37,9 +49,14 @@ private:
|
||||
private slots:
|
||||
void readyForLaunch();
|
||||
|
||||
void onSucceeded();
|
||||
void onFailed(QString reason);
|
||||
void onProgressRequested(Task *task);
|
||||
|
||||
private:
|
||||
BaseProfilerFactory *m_profiler = nullptr;
|
||||
bool m_online = true;
|
||||
bool m_showConsole = false;
|
||||
InstancePtr m_instance;
|
||||
QWidget * m_parentWidget = nullptr;
|
||||
InstanceWindow *m_console = nullptr;
|
||||
|
@ -547,7 +547,6 @@ void MultiMC::initGlobalSettings()
|
||||
|
||||
// Console
|
||||
m_settings->registerSetting("ShowConsole", true);
|
||||
m_settings->registerSetting("RaiseConsole", true);
|
||||
m_settings->registerSetting("AutoCloseConsole", true);
|
||||
m_settings->registerSetting("LogPrePostOutput", true);
|
||||
|
||||
@ -1072,25 +1071,32 @@ void MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *pro
|
||||
{
|
||||
if(instance->canLaunch())
|
||||
{
|
||||
m_launchController.reset(new LaunchController());
|
||||
m_launchController->setInstance(instance);
|
||||
m_launchController->setOnline(online);
|
||||
m_launchController->setProfiler(profiler);
|
||||
auto windowIter = m_instanceWindows.find(instance->id());
|
||||
if(windowIter != m_instanceWindows.end())
|
||||
auto & extras = m_instanceExtras[instance->id()];
|
||||
auto & window = extras.window;
|
||||
if(window)
|
||||
{
|
||||
auto window = *windowIter;
|
||||
if(!window->saveAll())
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_launchController->setParentWidget(window);
|
||||
}
|
||||
if(m_mainWindow)
|
||||
auto & controller = extras.controller;
|
||||
controller.reset(new LaunchController());
|
||||
controller->setInstance(instance);
|
||||
controller->setOnline(online);
|
||||
controller->setProfiler(profiler);
|
||||
controller->setShowConsole(instance->settings()->get("ShowConsole").toBool());
|
||||
if(window)
|
||||
{
|
||||
m_launchController->setParentWidget(m_mainWindow);
|
||||
controller->setParentWidget(window);
|
||||
}
|
||||
m_launchController->start();
|
||||
else if(m_mainWindow)
|
||||
{
|
||||
controller->setParentWidget(m_mainWindow);
|
||||
}
|
||||
connect(controller.get(), &LaunchController::succeeded, this, &MultiMC::controllerSucceeded);
|
||||
connect(controller.get(), &LaunchController::failed, this, &MultiMC::controllerFailed);
|
||||
controller->start();
|
||||
}
|
||||
else if (instance->isRunning())
|
||||
{
|
||||
@ -1098,6 +1104,37 @@ void MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *pro
|
||||
}
|
||||
}
|
||||
|
||||
void MultiMC::controllerSucceeded()
|
||||
{
|
||||
auto controller = qobject_cast<LaunchController *>(QObject::sender());
|
||||
if(!controller)
|
||||
return;
|
||||
auto id = controller->id();
|
||||
auto & extras = m_instanceExtras[id];
|
||||
// on success, do...
|
||||
if (controller->instance()->settings()->get("AutoCloseConsole").toBool())
|
||||
{
|
||||
if(extras.window)
|
||||
{
|
||||
extras.window->close();
|
||||
}
|
||||
}
|
||||
extras.controller.reset();
|
||||
}
|
||||
|
||||
void MultiMC::controllerFailed(const QString& error)
|
||||
{
|
||||
Q_UNUSED(error);
|
||||
auto controller = qobject_cast<LaunchController *>(QObject::sender());
|
||||
if(!controller)
|
||||
return;
|
||||
auto id = controller->id();
|
||||
auto & extras = m_instanceExtras[id];
|
||||
|
||||
// on failure, do... nothing
|
||||
extras.controller.reset();
|
||||
}
|
||||
|
||||
MainWindow * MultiMC::showMainWindow()
|
||||
{
|
||||
if(m_mainWindow)
|
||||
@ -1123,34 +1160,43 @@ InstanceWindow *MultiMC::showInstanceWindow(InstancePtr instance, QString page)
|
||||
if(!instance)
|
||||
return nullptr;
|
||||
auto id = instance->id();
|
||||
InstanceWindow * window = nullptr;
|
||||
auto & extras = m_instanceExtras[id];
|
||||
auto & window = extras.window;
|
||||
|
||||
auto iter = m_instanceWindows.find(id);
|
||||
if(iter != m_instanceWindows.end())
|
||||
if(window)
|
||||
{
|
||||
window = *iter;
|
||||
window->raise();
|
||||
window->activateWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
window = new InstanceWindow(instance);
|
||||
m_instanceWindows[id] = window;
|
||||
connect(window, &InstanceWindow::isClosing, this, &MultiMC::on_windowClose);
|
||||
}
|
||||
if(!page.isEmpty())
|
||||
{
|
||||
window->selectPage(page);
|
||||
}
|
||||
m_openWindows ++;
|
||||
if(extras.controller)
|
||||
{
|
||||
extras.controller->setParentWidget(window);
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
void MultiMC::on_windowClose()
|
||||
{
|
||||
m_openWindows--;
|
||||
auto instWindow = qobject_cast<InstanceWindow *>(QObject::sender());
|
||||
if(instWindow)
|
||||
{
|
||||
m_instanceWindows.remove(instWindow->instanceId());
|
||||
auto & extras = m_instanceExtras[instWindow->instanceId()];
|
||||
extras.window = nullptr;
|
||||
if(extras.controller)
|
||||
{
|
||||
extras.controller->setParentWidget(m_mainWindow);
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto mainWindow = qobject_cast<MainWindow *>(QObject::sender());
|
||||
@ -1159,7 +1205,7 @@ void MultiMC::on_windowClose()
|
||||
m_mainWindow = nullptr;
|
||||
}
|
||||
// quit when there are no more windows.
|
||||
if(m_instanceWindows.isEmpty() && !m_mainWindow)
|
||||
if(m_openWindows == 0)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
|
@ -154,6 +154,9 @@ private slots:
|
||||
|
||||
void messageReceived(const QString & message);
|
||||
|
||||
void controllerSucceeded();
|
||||
void controllerFailed(const QString & error);
|
||||
|
||||
private:
|
||||
void initLogger();
|
||||
void initIcons();
|
||||
@ -167,7 +170,6 @@ private:
|
||||
private:
|
||||
QDateTime startTime;
|
||||
|
||||
unique_qobject_ptr<LaunchController> m_launchController;
|
||||
std::shared_ptr<QTranslator> m_qt_translator;
|
||||
std::shared_ptr<QTranslator> m_mmc_translator;
|
||||
std::shared_ptr<SettingsObject> m_settings;
|
||||
@ -189,16 +191,24 @@ private:
|
||||
QMap<QString, std::shared_ptr<BaseDetachedToolFactory>> m_tools;
|
||||
|
||||
QString m_rootPath;
|
||||
|
||||
Status m_status = MultiMC::Failed;
|
||||
|
||||
// used on Windows to attach the standard IO streams
|
||||
bool consoleAttached = false;
|
||||
|
||||
// map from instance ID to its window
|
||||
QMap<QString, InstanceWindow *> m_instanceWindows;
|
||||
// FIXME: attach to instances instead.
|
||||
struct InstanceXtras
|
||||
{
|
||||
InstanceWindow * window = nullptr;
|
||||
unique_qobject_ptr<LaunchController> controller;
|
||||
};
|
||||
std::map<QString, InstanceXtras> m_instanceExtras;
|
||||
size_t m_openWindows = 0;
|
||||
|
||||
// main window, if any
|
||||
MainWindow * m_mainWindow = nullptr;
|
||||
|
||||
// peer MultiMC instance connector - used to implement single instance MultiMC and signalling
|
||||
LocalPeer * m_peerInstance = nullptr;
|
||||
public:
|
||||
QString m_instanceIdToLaunch;
|
||||
|
@ -94,7 +94,7 @@ bool PageContainer::selectPage(QString pageId)
|
||||
{
|
||||
index = m_proxyModel->mapFromSource(m_model->index(page->listIndex));
|
||||
}
|
||||
else
|
||||
if(!index.isValid())
|
||||
{
|
||||
index = m_proxyModel->index(0, 0);
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ void WonkoClient::runTask(Task *pTask) {
|
||||
void WonkoClient::initGlobalSettings()
|
||||
{
|
||||
m_settings->registerSetting("ShowConsole", true);
|
||||
m_settings->registerSetting("RaiseConsole", true);
|
||||
m_settings->registerSetting("AutoCloseConsole", true);
|
||||
m_settings->registerSetting("LogPrePostOutput", true);
|
||||
// Window Size
|
||||
|
Loading…
Reference in New Issue
Block a user