Add option to disable feature for checking for a new update

(cherry picked from commit d26dd55dba066aa4884b00b55173597f49309f0d)
This commit is contained in:
Yuriy Puchkov
2021-01-31 11:47:03 +02:00
parent de3b0385d5
commit 540e407eb7
7 changed files with 62 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ GeneralConf::GeneralConf(QWidget* parent)
initShowSidePanelButton();
initShowDesktopNotification();
initShowTrayIcon();
initCheckForUpdates();
initAutostart();
initUseJpgForClipboard();
initSaveAfterCopy();
@@ -93,6 +94,12 @@ void GeneralConf::showTrayIconChanged(bool checked)
}
}
void GeneralConf::checkForUpdatesChanged(bool checked)
{
ConfigHandler().setCheckForUpdates(checked);
Controller::getInstance()->setCheckForUpdatesEnabled(checked);
}
void GeneralConf::autostartChanged(bool checked)
{
ConfigHandler().setStartupLaunch(checked);
@@ -247,6 +254,19 @@ void GeneralConf::initConfigButtons()
&GeneralConf::resetConfiguration);
}
void GeneralConf::initCheckForUpdates()
{
m_checkForUpdates = new QCheckBox(tr("Automatic check for updates"), this);
m_checkForUpdates->setChecked(ConfigHandler().checkForUpdates());
m_checkForUpdates->setToolTip(tr("Automatic check for updates"));
m_layout->addWidget(m_checkForUpdates);
connect(m_checkForUpdates,
&QCheckBox::clicked,
this,
&GeneralConf::checkForUpdatesChanged);
}
void GeneralConf::initAutostart()
{
m_autostart = new QCheckBox(tr("Launch at startup"), this);

View File

@@ -39,6 +39,7 @@ private slots:
void showSidePanelButtonChanged(bool checked);
void showDesktopNotificationChanged(bool checked);
void showTrayIconChanged(bool checked);
void checkForUpdatesChanged(bool checked);
void autostartChanged(bool checked);
void saveAfterCopyChanged(bool checked);
void changeSavePath();
@@ -56,6 +57,7 @@ private:
void initShowDesktopNotification();
void initShowTrayIcon();
void initConfigButtons();
void initCheckForUpdates();
void initAutostart();
void initSaveAfterCopy();
void initUseJpgForClipboard();
@@ -66,6 +68,7 @@ private:
QCheckBox* m_showTray;
QCheckBox* m_helpMessage;
QCheckBox* m_sidePanelButton;
QCheckBox* m_checkForUpdates;
QCheckBox* m_autostart;
QPushButton* m_importButton;
QPushButton* m_exportButton;

View File

@@ -135,6 +135,15 @@ void Controller::enableExports()
this, &Controller::captureFailed, this, &Controller::handleCaptureFailed);
}
void Controller::setCheckForUpdatesEnabled(const bool enabled)
{
m_appUpdates->setVisible(enabled);
m_appUpdates->setEnabled(enabled);
if (enabled) {
getLatestAvailableVersion();
}
}
void Controller::getLatestAvailableVersion()
{
// This features is required for MacOS and Windows user and for Linux users
@@ -149,12 +158,17 @@ void Controller::getLatestAvailableVersion()
// check for updates each 24 hours
doLater(1000 * 60 * 60 * 24, this, [this]() {
if (ConfigHandler().checkForUpdates()) {
this->getLatestAvailableVersion();
}
});
}
void Controller::handleReplyCheckUpdates(QNetworkReply* reply)
{
if (!ConfigHandler().checkForUpdates()) {
return;
}
if (reply->error() == QNetworkReply::NoError) {
QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
QJsonObject json = response.object();
@@ -402,6 +416,7 @@ void Controller::enableTrayIcon()
m_trayIconMenu->addAction(infoAction);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(quitAction);
setCheckForUpdatesEnabled(ConfigHandler().checkForUpdates());
m_trayIcon = new QSystemTrayIcon();
m_trayIcon->setToolTip(QStringLiteral("Flameshot"));

View File

@@ -54,6 +54,8 @@ public:
void enableExports();
void updateRecentScreenshots();
void setCheckForUpdatesEnabled(const bool enabled);
signals:
void captureTaken(uint id, QPixmap p, QRect selection);
void captureFailed(uint id);

View File

@@ -309,6 +309,20 @@ void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen)
m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen);
}
bool ConfigHandler::checkForUpdates()
{
bool res = true;
if (m_settings.contains(QStringLiteral("checkForUpdates"))) {
res = m_settings.value(QStringLiteral("checkForUpdates")).toBool();
}
return res;
}
void ConfigHandler::setCheckForUpdates(const bool checkForUpdates)
{
m_settings.setValue(QStringLiteral("checkForUpdates"), checkForUpdates);
}
bool ConfigHandler::startupLaunchValue()
{
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \

View File

@@ -70,6 +70,9 @@ public:
bool keepOpenAppLauncherValue();
void setKeepOpenAppLauncher(const bool);
bool checkForUpdates();
void setCheckForUpdates(const bool);
bool verifyLaunchFile();
bool startupLaunchValue();
void setStartupLaunch(const bool);

View File

@@ -808,6 +808,10 @@ void CaptureWidget::initPanel()
void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion,
const QString& appLatestUrl)
{
if (!ConfigHandler().checkForUpdates()) {
// option check for updates disabled
return;
}
if (nullptr == m_updateNotificationWidget) {
m_updateNotificationWidget =
new UpdateNotificationWidget(this, appLatestVersion, appLatestUrl);