RMG: check for updates once an hour and add 'Check For Updates' to View

This commit is contained in:
Rosalie Wanders
2023-02-23 15:45:32 +01:00
parent 96459432a6
commit ea01c86821
6 changed files with 67 additions and 11 deletions
+48 -10
View File
@@ -71,7 +71,9 @@ bool MainWindow::Init(QApplication* app, bool showUI)
this->updateActions(false, false);
#ifdef UPDATER
this->checkForUpdates();
this->checkForUpdates(true, false);
#else
this->action_Help_Update->setVisible(false);
#endif // UPDATER
this->initializeEmulationThread();
@@ -890,16 +892,44 @@ void MainWindow::connectActionSignals(void)
connect(this->action_Help_Github, &QAction::triggered, this, &MainWindow::on_Action_Help_Github);
connect(this->action_Help_About, &QAction::triggered, this, &MainWindow::on_Action_Help_About);
connect(this->action_Help_Update, &QAction::triggered, this, &MainWindow::on_Action_Help_Update);
}
#ifdef UPDATER
void MainWindow::checkForUpdates(void)
void MainWindow::checkForUpdates(bool silent, bool force)
{
if (!CoreSettingsGetBoolValue(SettingsID::GUI_CheckForUpdates))
if (!force && !CoreSettingsGetBoolValue(SettingsID::GUI_CheckForUpdates))
{
return;
}
// only check for updates on the stable versions unless forced
QString currentVersion = QString::fromStdString(CoreGetVersion());
if (!force && currentVersion.size() != 6)
{
return;
}
QString dateTimeFormat = "dd-MM-yyyy_hh:mm";
QString lastUpdateCheckDateTimeString = QString::fromStdString(CoreSettingsGetStringValue(SettingsID::GUI_LastUpdateCheck));
QDateTime lastUpdateCheckDateTime = QDateTime::fromString(lastUpdateCheckDateTimeString, dateTimeFormat);
QDateTime currentDateTime = QDateTime::currentDateTime();
// only check for updates once every hour unless forced
if (!force &&
lastUpdateCheckDateTime.isValid() &&
lastUpdateCheckDateTime.addSecs(3600) > currentDateTime)
{
return;
}
// update last update check date & time
CoreSettingsSetValue(SettingsID::GUI_LastUpdateCheck, currentDateTime.toString(dateTimeFormat).toStdString());
// whether or not the update check is silent
this->ui_SilentUpdateCheck = silent;
// execute update check
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
connect(networkAccessManager, &QNetworkAccessManager::finished, this, &MainWindow::on_networkAccessManager_Finished);
networkAccessManager->get(QNetworkRequest(QUrl("https://api.github.com/repos/Rosalie241/RMG/releases/latest")));
@@ -1011,6 +1041,10 @@ void MainWindow::on_networkAccessManager_Finished(QNetworkReply* reply)
{
if (reply->error())
{
if (!this->ui_SilentUpdateCheck)
{
this->showErrorMessage("Failed to check for updates!", reply->errorString());
}
reply->deleteLater();
return;
}
@@ -1023,16 +1057,13 @@ void MainWindow::on_networkAccessManager_Finished(QNetworkReply* reply)
reply->deleteLater();
// make sure the current version is valid
// and not a dev version
if (currentVersion.size() != 6)
{
return;
}
// do nothing when versions match
if (currentVersion == latestVersion)
{
if (!this->ui_SilentUpdateCheck)
{
this->showErrorMessage("You're already on the latest version!");
}
return;
}
@@ -1518,6 +1549,13 @@ void MainWindow::on_Action_Help_About(void)
dialog.exec();
}
void MainWindow::on_Action_Help_Update(void)
{
#ifdef UPDATER
this->checkForUpdates(false, true);
#endif // UPDATER
}
void MainWindow::on_Emulation_Started(void)
{
this->logDialog.Clear();
+4 -1
View File
@@ -82,6 +82,8 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
bool ui_AddedActions = false;
bool ui_SilentUpdateCheck = false;
int ui_TimerId = 0;
int ui_TimerTimeout = 0;
@@ -119,7 +121,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
void removeActions(void);
#ifdef UPDATER
void checkForUpdates(void);
void checkForUpdates(bool, bool);
#endif // UPDATER
protected:
void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
@@ -170,6 +172,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
void on_Action_Help_Github(void);
void on_Action_Help_About(void);
void on_Action_Help_Update(void);
void on_Emulation_Started(void);
void on_Emulation_Finished(bool);
+11
View File
@@ -147,6 +147,8 @@
</property>
<addaction name="action_Help_Github"/>
<addaction name="separator"/>
<addaction name="action_Help_Update"/>
<addaction name="separator"/>
<addaction name="action_Help_About"/>
</widget>
<addaction name="menuSystem"/>
@@ -620,6 +622,15 @@
<string>300%</string>
</property>
</action>
<action name="action_Help_Update">
<property name="icon">
<iconset theme="download-line">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Check For Updates</string>
</property>
</action>
</widget>
<resources>
<include location="UIResources.qrc"/>
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 19h18v2H3v-2zm10-5.828L19.071 7.1l1.414 1.414L12 17 3.515 8.515 4.929 7.1 11 13.17V2h2v11.172z"/></svg>

After

Width:  |  Height:  |  Size: 235 B

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 19h18v2H3v-2zm10-5.828L19.071 7.1l1.414 1.414L12 17 3.515 8.515 4.929 7.1 11 13.17V2h2v11.172z" fill="#ffffff"/></svg>

After

Width:  |  Height:  |  Size: 250 B

+2
View File
@@ -11,6 +11,7 @@
<file alias="icons/black/svg/delete-back-line.svg">Resource/icons/black/svg/delete-back-line.svg</file>
<file alias="icons/black/svg/delete-bin-line.svg">Resource/icons/black/svg/delete-bin-line.svg</file>
<file alias="icons/black/svg/door-open-line.svg">Resource/icons/black/svg/door-open-line.svg</file>
<file alias="icons/black/svg/download-line.svg">Resource/icons/black/svg/download-line.svg</file>
<file alias="icons/black/svg/file-line.svg">Resource/icons/black/svg/file-line.svg</file>
<file alias="icons/black/svg/file-list-line.svg">Resource/icons/black/svg/file-list-line.svg</file>
<file alias="icons/black/svg/folder-open-line.svg">Resource/icons/black/svg/folder-open-line.svg</file>
@@ -40,6 +41,7 @@
<file alias="icons/white/svg/delete-back-line.svg">Resource/icons/white/svg/delete-back-line.svg</file>
<file alias="icons/white/svg/delete-bin-line.svg">Resource/icons/white/svg/delete-bin-line.svg</file>
<file alias="icons/white/svg/door-open-line.svg">Resource/icons/white/svg/door-open-line.svg</file>
<file alias="icons/white/svg/download-line.svg">Resource/icons/white/svg/download-line.svg</file>
<file alias="icons/white/svg/file-line.svg">Resource/icons/white/svg/file-line.svg</file>
<file alias="icons/white/svg/file-list-line.svg">Resource/icons/white/svg/file-list-line.svg</file>
<file alias="icons/white/svg/folder-open-line.svg">Resource/icons/white/svg/folder-open-line.svg</file>