From 5b17ae3f7ef54fe251da3e3aae25e9c744dfec3c Mon Sep 17 00:00:00 2001 From: Patrick Klein <42714034+libklein@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:43:20 +0100 Subject: [PATCH] Implement compile-time flag to disable automatic update checks. (#4854) Usage: `cmake -DCHATTERINO_UPDATER=OFF ..` Co-authored-by: Rasmus Karlsson Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> --- CHANGELOG.md | 1 + CMakeLists.txt | 3 +++ src/CMakeLists.txt | 5 +++++ src/singletons/Updates.cpp | 14 ++++++++------ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a21f639de..4fa447fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Dev: Clarify signal connection lifetimes where applicable. (#4818) - Dev: Laid the groundwork for advanced input completion strategies. (#4639, #4846, #4853) - Dev: Fixed flickering when running with Direct2D on Windows. (#4851) +- Dev: Add a compile-time flag `CHATTERINO_DISABLE_UPDATER` to disable update checks. (#4854) ## 2.4.6 diff --git a/CMakeLists.txt b/CMakeLists.txt index f7e71271a..4f3e1699b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,9 @@ option(BUILD_SHARED_LIBS "" OFF) option(CHATTERINO_LTO "Enable LTO for all targets" OFF) option(CHATTERINO_PLUGINS "Enable EXPERIMENTAL plugin support in Chatterino" OFF) +option(CHATTERINO_UPDATER "Enable update checks" ON) +mark_as_advanced(CHATTERINO_UPDATER) + if(CHATTERINO_LTO) include(CheckIPOSupported) check_ipo_supported(RESULT CHATTERINO_ENABLE_LTO OUTPUT IPO_ERROR) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a99a4a264..b24a8ac47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1039,3 +1039,8 @@ if(CHATTERINO_ENABLE_LTO) set_property(TARGET ${LIBRARY_PROJECT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif() + +if(NOT CHATTERINO_UPDATER) + message(STATUS "Disabling the updater.") + target_compile_definitions(${LIBRARY_PROJECT} PUBLIC CHATTERINO_DISABLE_UPDATER) +endif() diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index b25e52819..54ba974d2 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -250,6 +250,7 @@ void Updates::installUpdates() void Updates::checkForUpdates() { +#ifndef CHATTERINO_DISABLE_UPDATER auto version = Version::instance(); if (!version.isSupportedOS()) @@ -291,7 +292,7 @@ void Updates::checkForUpdates() return Failure; } -#if defined Q_OS_WIN || defined Q_OS_MACOS +# if defined Q_OS_WIN || defined Q_OS_MACOS /// Downloads an installer for the new version auto updateExeUrl = object["updateexe"]; if (!updateExeUrl.isString()) @@ -303,7 +304,7 @@ void Updates::checkForUpdates() } this->updateExe_ = updateExeUrl.toString(); -# ifdef Q_OS_WIN +# ifdef Q_OS_WIN /// Windows portable auto portableUrl = object["portable_download"]; if (!portableUrl.isString()) @@ -315,17 +316,17 @@ void Updates::checkForUpdates() return Failure; } this->updatePortable_ = portableUrl.toString(); -# endif +# endif -#elif defined Q_OS_LINUX +# elif defined Q_OS_LINUX QJsonValue updateGuide = object.value("updateguide"); if (updateGuide.isString()) { this->updateGuideLink_ = updateGuide.toString(); } -#else +# else return Failure; -#endif +# endif /// Current version this->onlineVersion_ = version.toString(); @@ -345,6 +346,7 @@ void Updates::checkForUpdates() }) .execute(); this->setStatus_(Searching); +#endif } Updates::Status Updates::getStatus() const