Add check for updates setting

This commit is contained in:
GriffinR 2024-01-20 23:02:43 -05:00
parent d6dfab1805
commit 09c2ed6b30
6 changed files with 49 additions and 6 deletions

View file

@ -26,6 +26,9 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkBox_MonitorProjectFiles">
<property name="toolTip">
<string>If checked, a prompt to reload your project will appear if relevant project files are edited</string>
</property>
<property name="text">
<string>Monitor project files</string>
</property>
@ -33,11 +36,24 @@
</item>
<item>
<widget class="QCheckBox" name="checkBox_OpenRecentProject">
<property name="toolTip">
<string>If checked, Porymap will automatically open your most recently opened project on startup</string>
</property>
<property name="text">
<string>Open recent project on launch</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_CheckForUpdates">
<property name="toolTip">
<string>If checked, Porymap will automatically alert you on startup if a new release is available</string>
</property>
<property name="text">
<string>Automatically check for updates</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View file

@ -74,6 +74,7 @@ public:
this->paletteEditorBitDepth = 24;
this->projectSettingsTab = 0;
this->warpBehaviorWarningDisabled = false;
this->checkForUpdates = true;
}
void addRecentProject(QString project);
void setRecentProjects(QStringList projects);
@ -105,6 +106,7 @@ public:
void setPaletteEditorBitDepth(int bitDepth);
void setProjectSettingsTab(int tab);
void setWarpBehaviorWarningDisabled(bool disabled);
void setCheckForUpdates(bool enabled);
QString getRecentProject();
QStringList getRecentProjects();
bool getReopenOnLaunch();
@ -135,6 +137,7 @@ public:
int getPaletteEditorBitDepth();
int getProjectSettingsTab();
bool getWarpBehaviorWarningDisabled();
bool getCheckForUpdates();
protected:
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
@ -183,6 +186,7 @@ private:
int paletteEditorBitDepth;
int projectSettingsTab;
bool warpBehaviorWarningDisabled;
bool checkForUpdates;
};
extern PorymapConfig porymapConfig;

View file

@ -400,7 +400,7 @@ private:
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
int insertTilesetLabel(QStringList * list, QString label);
void checkForUpdates();
void checkForUpdates(bool requestedByUser);
};
enum MapListUserRoles {

View file

@ -407,6 +407,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->projectSettingsTab = getConfigInteger(key, value, 0);
} else if (key == "warp_behavior_warning_disabled") {
this->warpBehaviorWarningDisabled = getConfigBool(key, value);
} else if (key == "check_for_updates") {
this->checkForUpdates = getConfigBool(key, value);
} else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
}
@ -453,6 +455,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("palette_editor_bit_depth", QString::number(this->paletteEditorBitDepth));
map.insert("project_settings_tab", QString::number(this->projectSettingsTab));
map.insert("warp_behavior_warning_disabled", QString::number(this->warpBehaviorWarningDisabled));
map.insert("check_for_updates", QString::number(this->checkForUpdates));
return map;
}
@ -790,6 +793,15 @@ bool PorymapConfig::getWarpBehaviorWarningDisabled() {
return this->warpBehaviorWarningDisabled;
}
void PorymapConfig::setCheckForUpdates(bool enabled) {
this->checkForUpdates = enabled;
this->save();
}
bool PorymapConfig::getCheckForUpdates() {
return this->checkForUpdates;
}
const QStringList ProjectConfig::versionStrings = {
"pokeruby",
"pokefirered",

View file

@ -66,6 +66,9 @@ MainWindow::MainWindow(QWidget *parent) :
// there is a bug affecting macOS users, where the trackpad deilveres a bad touch-release gesture
// the warning is a bit annoying, so it is disabled here
QLoggingCategory::setFilterRules(QStringLiteral("qt.pointer.dispatch=false"));
if (porymapConfig.getCheckForUpdates())
this->checkForUpdates(false);
}
MainWindow::~MainWindow()
@ -242,28 +245,31 @@ void MainWindow::initExtraSignals() {
label_MapRulerStatus->setAlignment(Qt::AlignCenter);
label_MapRulerStatus->setTextFormat(Qt::PlainText);
label_MapRulerStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
// TODO: (if enabled) queue an automatic "Check for Updates"
}
// TODO: Relocate
#include <QNetworkReply>
#include <QNetworkRequest>
void MainWindow::on_actionCheck_for_Updates_triggered() {
checkForUpdates();
checkForUpdates(true);
}
void MainWindow::checkForUpdates() {
void MainWindow::checkForUpdates(bool requestedByUser) {
if (!this->networkAccessManager)
this->networkAccessManager = new QNetworkAccessManager(this);
// We could get ".../releases/latest" to retrieve less data, but this would run into problems if the
// most recent item on the releases page is not actually a new release (like the static windows build).
QNetworkRequest request(QUrl("https://api.github.com/repos/huderlem/porymap/releases"));
static const QUrl url("https://api.github.com/repos/huderlem/porymap/releases");
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkReply * reply = this->networkAccessManager->get(request);
if (requestedByUser) {
// TODO: Show dialog
}
connect(reply, &QNetworkReply::finished, [this, reply] {
QJsonDocument data = QJsonDocument::fromJson(reply->readAll());
QJsonArray releases = data.array();

View file

@ -49,6 +49,7 @@ void PreferenceEditor::updateFields() {
ui->lineEdit_TextEditorGotoLine->setText(porymapConfig.getTextEditorGotoLine());
ui->checkBox_MonitorProjectFiles->setChecked(porymapConfig.getMonitorFiles());
ui->checkBox_OpenRecentProject->setChecked(porymapConfig.getReopenOnLaunch());
ui->checkBox_CheckForUpdates->setChecked(porymapConfig.getCheckForUpdates());
}
void PreferenceEditor::saveFields() {
@ -58,10 +59,14 @@ void PreferenceEditor::saveFields() {
emit themeChanged(theme);
}
porymapConfig.setSaveDisabled(true);
porymapConfig.setTextEditorOpenFolder(ui->lineEdit_TextEditorOpenFolder->text());
porymapConfig.setTextEditorGotoLine(ui->lineEdit_TextEditorGotoLine->text());
porymapConfig.setMonitorFiles(ui->checkBox_MonitorProjectFiles->isChecked());
porymapConfig.setReopenOnLaunch(ui->checkBox_OpenRecentProject->isChecked());
porymapConfig.setCheckForUpdates(ui->checkBox_CheckForUpdates->isChecked());
porymapConfig.setSaveDisabled(false);
porymapConfig.save();
emit preferencesSaved();
}