add new NO_UPDATE_CHECK build switch

This commit is contained in:
Martin Rotter 2022-05-02 09:37:38 +02:00
parent 4f2f991bc4
commit e6536a172b
4 changed files with 41 additions and 28 deletions

View File

@ -20,6 +20,7 @@
#
# Variables:
# BUILD_WITH_QT6 - Build either with Qt 6 or Qt 5.
# NO_UPDATE_CHECK - Disable automatic checking for new application updates.
# USE_WEBENGINE - if specified, then QtWebEngine module for internal web browser is used.
# Otherwise simple text component is used and some features will be disabled.
# Default value is "false". If QtWebEngine is installed during compilation, then
@ -106,6 +107,7 @@ option(USE_WEBENGINE "Use QtWebEngine for embedded web browser" ON)
option(UPDATE_TRANSLATIONS "Call lupdate to update translation files from source (Qt 6 only)" OFF)
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GCC/Clang only)" OFF)
option(REVISION_FROM_GIT "Get revision using `git rev-parse`" ON)
option(NO_UPDATE_CHECK "Disable automatic checking for new application updates" OFF)
# Import Qt libraries.
set(QT6_MIN_VERSION 6.3.0)
@ -203,6 +205,10 @@ add_compile_definitions(
_UNICODE
)
if(NO_UPDATE_CHECK)
add_compile_definitions(NO_UPDATE_CHECK)
endif()
# Configure and copy some needed files.
if(WIN32)
configure_file(

View File

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" />
<releases>
<release version="4.2.2" date="2022-04-29"/>
<release version="4.2.2" date="2022-05-02"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -11,6 +11,10 @@ SettingsGeneral::SettingsGeneral(Settings* settings, QWidget* parent)
m_ui->m_checkAutostart->setText(m_ui->m_checkAutostart->text().arg(QSL(APP_NAME)));
m_ui->m_checkForUpdatesOnStart->setText(m_ui->m_checkForUpdatesOnStart->text().arg(QSL(APP_NAME)));
#if defined(NO_UPDATE_CHECK)
m_ui->m_checkForUpdatesOnStart->setVisible(false);
#endif
connect(m_ui->m_checkAutostart, &QCheckBox::stateChanged, this, &SettingsGeneral::dirtifySettings);
connect(m_ui->m_checkForUpdatesOnStart, &QCheckBox::stateChanged, this, &SettingsGeneral::dirtifySettings);
}
@ -21,7 +25,8 @@ SettingsGeneral::~SettingsGeneral() {
void SettingsGeneral::loadSettings() {
onBeginLoadSettings();
m_ui->m_checkForUpdatesOnStart->setChecked(settings()->value(GROUP(General), SETTING(General::UpdateOnStartup)).toBool());
m_ui->m_checkForUpdatesOnStart
->setChecked(settings()->value(GROUP(General), SETTING(General::UpdateOnStartup)).toBool());
// Load auto-start status.
const SystemFactory::AutoStartStatus autostart_status = qApp->system()->autoStartStatus();

View File

@ -48,10 +48,9 @@ SystemFactory::AutoStartStatus SystemFactory::autoStartStatus() const {
#if defined(Q_OS_WIN)
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
QSettings::Format::NativeFormat);
const bool autostart_enabled = registry_key.value(QSL(APP_LOW_NAME),
QString()).toString().replace(QL1C('\\'),
QL1C('/')) ==
Application::applicationFilePath();
const bool autostart_enabled =
registry_key.value(QSL(APP_LOW_NAME), QString()).toString().replace(QL1C('\\'), QL1C('/')) ==
Application::applicationFilePath();
if (autostart_enabled) {
return AutoStartStatus::Enabled;
@ -122,12 +121,12 @@ bool SystemFactory::setAutoStartStatus(AutoStartStatus new_status) {
}
#if defined(Q_OS_WIN)
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"), QSettings::NativeFormat);
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
QSettings::NativeFormat);
switch (new_status) {
case AutoStartStatus::Enabled:
registry_key.setValue(QSL(APP_LOW_NAME),
Application::applicationFilePath().replace(QL1C('/'), QL1C('\\')));
registry_key.setValue(QSL(APP_LOW_NAME), Application::applicationFilePath().replace(QL1C('/'), QL1C('\\')));
return true;
case AutoStartStatus::Disabled:
@ -155,7 +154,8 @@ bool SystemFactory::setAutoStartStatus(AutoStartStatus new_status) {
return false;
}
const QString source_autostart_desktop_file = QString(APP_DESKTOP_ENTRY_PATH) + QDir::separator() + APP_DESKTOP_SOURCE_ENTRY_FILE;
const QString source_autostart_desktop_file =
QString(APP_DESKTOP_ENTRY_PATH) + QDir::separator() + APP_DESKTOP_SOURCE_ENTRY_FILE;
return QFile::copy(source_autostart_desktop_file, destination_file);
}
@ -204,26 +204,29 @@ void SystemFactory::checkForUpdates() const {
}
void SystemFactory::checkForUpdatesOnStartup() {
#if !defined(NO_UPDATE_CHECK)
if (qApp->settings()->value(GROUP(General), SETTING(General::UpdateOnStartup)).toBool()) {
QObject::connect(qApp->system(), &SystemFactory::updatesChecked,
this, [&](const QPair<QList<UpdateInfo>, QNetworkReply::NetworkError>& updates) {
QObject::disconnect(qApp->system(), &SystemFactory::updatesChecked, this, nullptr);
QObject::connect(qApp->system(),
&SystemFactory::updatesChecked,
this,
[&](const QPair<QList<UpdateInfo>, QNetworkReply::NetworkError>& updates) {
QObject::disconnect(qApp->system(), &SystemFactory::updatesChecked, this, nullptr);
if (!updates.first.isEmpty() &&
updates.second == QNetworkReply::NetworkError::NoError &&
SystemFactory::isVersionNewer(updates.first.at(0).m_availableVersion, QSL(APP_VERSION))) {
qApp->showGuiMessage(Notification::Event::NewAppVersionAvailable, {
QObject::tr("New version available"),
QObject::tr("Click the bubble for more information."),
QSystemTrayIcon::Information }, {}, {
tr("See new version info"),
[] {
FormUpdate(qApp->mainForm()).exec();
} });
}
});
if (!updates.first.isEmpty() && updates.second == QNetworkReply::NetworkError::NoError &&
SystemFactory::isVersionNewer(updates.first.at(0).m_availableVersion, QSL(APP_VERSION))) {
qApp->showGuiMessage(Notification::Event::NewAppVersionAvailable,
{QObject::tr("New version available"),
QObject::tr("Click the bubble for more information."),
QSystemTrayIcon::Information},
{},
{tr("See new version info"), [] {
FormUpdate(qApp->mainForm()).exec();
}});
}
});
qApp->system()->checkForUpdates();
}
#endif
}
bool SystemFactory::isVersionNewer(const QString& new_version, const QString& base_version) {
@ -239,8 +242,7 @@ bool SystemFactory::isVersionEqualOrNewer(const QString& new_version, const QStr
bool SystemFactory::openFolderFile(const QString& file_path) {
#if defined(Q_OS_WIN)
return QProcess::startDetached(QSL("explorer.exe"),
{ "/select,", QDir::toNativeSeparators(file_path) });
return QProcess::startDetached(QSL("explorer.exe"), {"/select,", QDir::toNativeSeparators(file_path)});
#else
const QString folder = QDir::toNativeSeparators(QFileInfo(file_path).absoluteDir().absolutePath());