diff --git a/forms/preferenceeditor.ui b/forms/preferenceeditor.ui
index 974d6322..a7009e6e 100644
--- a/forms/preferenceeditor.ui
+++ b/forms/preferenceeditor.ui
@@ -26,6 +26,9 @@
-
+
+ If checked, a prompt to reload your project will appear if relevant project files are edited
+
Monitor project files
@@ -33,11 +36,24 @@
-
+
+ If checked, Porymap will automatically open your most recently opened project on startup
+
Open recent project on launch
+ -
+
+
+ If checked, Porymap will automatically alert you on startup if a new release is available
+
+
+ Automatically check for updates
+
+
+
diff --git a/include/config.h b/include/config.h
index 17a19dec..17cc20d0 100644
--- a/include/config.h
+++ b/include/config.h
@@ -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;
diff --git a/include/mainwindow.h b/include/mainwindow.h
index 7d512ef5..75c38fc9 100644
--- a/include/mainwindow.h
+++ b/include/mainwindow.h
@@ -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 {
diff --git a/src/config.cpp b/src/config.cpp
index 0c49605c..9cf0c54c 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -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 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",
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 7027ebca..6e2ca509 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -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
#include
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();
diff --git a/src/ui/preferenceeditor.cpp b/src/ui/preferenceeditor.cpp
index f94c07da..eacc3f3d 100644
--- a/src/ui/preferenceeditor.cpp
+++ b/src/ui/preferenceeditor.cpp
@@ -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();
}