UICommon: Add AutoUpdate module + placeholder Qt implementation

The AutoUpdate module is a generic update checker mechanism which can be
used by UI backends to trigger an auto-update check as well as the
actual update process.

Currently only configurable through .ini and the Qt implementation is
completely placeholder-y -- blocking the main thread on a network
request on startup, etc.
This commit is contained in:
Pierre Bourdon
2018-03-17 17:22:05 -07:00
parent 37902c4aa4
commit 66b41c5509
7 changed files with 244 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include <QApplication>
#include <QMessageBox>
#include <QObject>
#include <QWidget>
#include "Common/MsgHandler.h"
#include "Core/Analytics.h"
@ -20,6 +21,7 @@
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/Translation.h"
#include "UICommon/AutoUpdate.h"
#include "UICommon/CommandLineParse.h"
#include "UICommon/UICommon.h"
@ -50,6 +52,35 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
});
}
// TODO: This should be replaced with something in a background thread, it performs a blocking
// HTTP query. It also needs a proper UI, and many other things. But right now it needs to be
// manually enabled through INI, so all these problems are ignored :)
class QtAutoUpdateChecker : public AutoUpdateChecker
{
public:
explicit QtAutoUpdateChecker(QWidget* parent) : m_parent(parent) {}
protected:
void OnUpdateAvailable(const NewVersionInformation& info) override
{
QMessageBox prompt(m_parent);
prompt.setIcon(QMessageBox::Question);
prompt.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
prompt.setText(QString::fromUtf8("Update Dolphin to version %1?")
.arg(QString::fromStdString(info.new_shortrev)));
const int answer = prompt.exec();
if (answer == QMessageBox::Yes)
{
TriggerUpdate(info);
m_parent->close();
}
}
private:
QWidget* m_parent;
};
// N.B. On Windows, this should be called from WinMain. Link against qtmain and specify
// /SubSystem:Windows
int main(int argc, char* argv[])
@ -152,6 +183,9 @@ int main(int argc, char* argv[])
}
#endif
QtAutoUpdateChecker updater(&win);
updater.CheckForUpdate();
retval = app.exec();
}