Show Mojang service statuses in status bar
This commit is contained in:
@ -77,6 +77,8 @@
|
||||
|
||||
#include "logic/news/NewsChecker.h"
|
||||
|
||||
#include "logic/status/StatusChecker.h"
|
||||
|
||||
#include "logic/net/URLConstants.h"
|
||||
|
||||
#include "logic/BaseInstance.h"
|
||||
@ -199,7 +201,27 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad()));
|
||||
|
||||
m_statusLeft = new QLabel(tr("No instance selected"), this);
|
||||
m_statusRight = new QLabel(tr("No status available"), this);
|
||||
m_statusRefresh = new QToolButton(this);
|
||||
m_statusRefresh->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
m_statusRefresh->setIcon(
|
||||
QPixmap(":/icons/toolbar/refresh").scaled(16, 16, Qt::KeepAspectRatio));
|
||||
|
||||
statusBar()->addPermanentWidget(m_statusLeft, 1);
|
||||
statusBar()->addPermanentWidget(m_statusRight, 0);
|
||||
statusBar()->addPermanentWidget(m_statusRefresh, 0);
|
||||
|
||||
// Start status checker
|
||||
{
|
||||
connect(MMC->statusChecker().get(), &StatusChecker::statusLoaded, this, &MainWindow::updateStatusUI);
|
||||
connect(MMC->statusChecker().get(), &StatusChecker::statusLoadingFailed, this, &MainWindow::updateStatusFailedUI);
|
||||
|
||||
connect(m_statusRefresh, &QAbstractButton::clicked, this, &MainWindow::reloadStatus);
|
||||
connect(&statusTimer, &QTimer::timeout, this, &MainWindow::reloadStatus);
|
||||
statusTimer.setSingleShot(true);
|
||||
|
||||
reloadStatus();
|
||||
}
|
||||
|
||||
// Add "manage accounts" button, right align
|
||||
QWidget *spacer = new QWidget();
|
||||
@ -498,6 +520,63 @@ void MainWindow::updateNewsLabel()
|
||||
}
|
||||
}
|
||||
|
||||
static QString convertStatus(const QString &status)
|
||||
{
|
||||
if(status == "green") return "↑";
|
||||
else if(status == "yellow") return "-";
|
||||
else if(status == "red") return "↓";
|
||||
else return "?";
|
||||
}
|
||||
|
||||
void MainWindow::reloadStatus()
|
||||
{
|
||||
MMC->statusChecker()->reloadStatus();
|
||||
updateStatusUI();
|
||||
}
|
||||
|
||||
static QString makeStatusString(const QMap<QString, QString> statuses)
|
||||
{
|
||||
QString status = "";
|
||||
status += "Web: " + convertStatus(statuses["minecraft.net"]);
|
||||
status += " Account: " + convertStatus(statuses["account.mojang.com"]);
|
||||
status += " Skins: " + convertStatus(statuses["skins.minecraft.net"]);
|
||||
status += " Auth: " + convertStatus(statuses["authserver.mojang.com"]);
|
||||
status += " Session: " + convertStatus(statuses["sessionserver.mojang.com"]);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void MainWindow::updateStatusUI()
|
||||
{
|
||||
auto statusChecker = MMC->statusChecker();
|
||||
auto statuses = statusChecker->getStatusEntries();
|
||||
|
||||
QString status = makeStatusString(statuses);
|
||||
if(statusChecker->isLoadingStatus())
|
||||
{
|
||||
m_statusRefresh->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
m_statusRefresh->setText(tr("Loading..."));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_statusRefresh->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
m_statusRefresh->setText(tr(""));
|
||||
}
|
||||
|
||||
m_statusRight->setText(status);
|
||||
|
||||
statusTimer.start(60 * 1000);
|
||||
}
|
||||
|
||||
void MainWindow::updateStatusFailedUI()
|
||||
{
|
||||
m_statusRight->setText(makeStatusString(QMap<QString, QString>()));
|
||||
m_statusRefresh->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
m_statusRefresh->setText(tr("Failed."));
|
||||
|
||||
statusTimer.start(60 * 1000);
|
||||
}
|
||||
|
||||
void MainWindow::updateAvailable(QString repo, QString versionName, int versionId)
|
||||
{
|
||||
UpdateDialog dlg;
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QProcess>
|
||||
#include <QTimer>
|
||||
|
||||
#include "logic/lists/InstanceList.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
@ -168,6 +169,12 @@ slots:
|
||||
void repopulateAccountsMenu();
|
||||
|
||||
void updateNewsLabel();
|
||||
|
||||
void updateStatusUI();
|
||||
|
||||
void updateStatusFailedUI();
|
||||
|
||||
void reloadStatus();
|
||||
|
||||
/*!
|
||||
* Runs the DownloadUpdateTask and installs updates.
|
||||
@ -198,8 +205,12 @@ private:
|
||||
Task *m_versionLoadTask;
|
||||
|
||||
QLabel *m_statusLeft;
|
||||
QLabel *m_statusRight;
|
||||
QToolButton *m_statusRefresh;
|
||||
|
||||
QMenu *accountMenu;
|
||||
QToolButton *accountMenuButton;
|
||||
QAction *manageAccountsAction;
|
||||
|
||||
QTimer statusTimer;
|
||||
};
|
||||
|
Reference in New Issue
Block a user