Skip to content

Commit

Permalink
feat(build): Add UPDATE_CHECKER option to CMake
Browse files Browse the repository at this point in the history
This option allows us to build Notes without any sort of update
checking code (including the auto-updater).

This is mostly useful for Linux package maintainers, where any update
checking feature is essentially useless, since we don't (and shouldn't)
have control over a Linux distribution's package upgrading process.

Nevertheless, this option is still enabled by default, meaning that
both the update checker and the auto-updater _will_ still work.

To disable them, invoke CMake with -DUPDATE_CHECKER=OFF.
  • Loading branch information
guihkx committed Feb 15, 2023
1 parent c82c0b7 commit 0ef084e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
41 changes: 30 additions & 11 deletions CMakeLists.txt
Expand Up @@ -11,6 +11,8 @@ set(USE_QT_VERSION
CACHE STRING "Use a specific version of Qt to build the app")
option(GIT_REVISION
"Append the current git revision to the app's version string" OFF)
option(UPDATE_CHECKER
"Enable or disable both the update checker and auto-updater" ON)

project(
Notes
Expand Down Expand Up @@ -76,6 +78,7 @@ message(STATUS "Success! Configuration details:")
message(STATUS "App name: ${PROJECT_NAME}")
message(STATUS "App version: ${PROJECT_VERSION}")
message(STATUS "Qt version: ${QT_VERSION}")
message(STATUS "Update checker: ${UPDATE_CHECKER}")
if(CMAKE_BUILD_TYPE STREQUAL "")
message(STATUS "Build type: (not set)")
else()
Expand Down Expand Up @@ -178,13 +181,10 @@ set(SOURCES
${PROJECT_SOURCE_DIR}/src/trashbuttondelegateeditor.h
${PROJECT_SOURCE_DIR}/src/treeviewlogic.cpp
${PROJECT_SOURCE_DIR}/src/treeviewlogic.h
${PROJECT_SOURCE_DIR}/src/updaterwindow.cpp
${PROJECT_SOURCE_DIR}/src/updaterwindow.h
# ui
${PROJECT_SOURCE_DIR}/src/aboutwindow.ui
${PROJECT_SOURCE_DIR}/src/mainwindow.ui
${PROJECT_SOURCE_DIR}/src/styleeditorwindow.ui
${PROJECT_SOURCE_DIR}/src/updaterwindow.ui
# qrc files
${PROJECT_SOURCE_DIR}/src/fonts.qrc
${PROJECT_SOURCE_DIR}/src/images.qrc
Expand All @@ -203,22 +203,33 @@ set(SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qownlanguagedata.h
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qplaintexteditsearchwidget.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit/qplaintexteditsearchwidget.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include/QSimpleUpdater.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/QSimpleUpdater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Updater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Updater.h
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobal.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobal.h
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut.cpp
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut.h
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_p.h)

if(UPDATE_CHECKER)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/src/updaterwindow.cpp
${PROJECT_SOURCE_DIR}/src/updaterwindow.h
${PROJECT_SOURCE_DIR}/src/updaterwindow.ui)

list(
APPEND
SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include/QSimpleUpdater.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Downloader.h
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/QSimpleUpdater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Updater.cpp
${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/src/Updater.h)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/src/framelesswindow.mm
${PROJECT_SOURCE_DIR}/src/framelesswindow.h
${PROJECT_SOURCE_DIR}/src/images/notes_icon.icns)

list(APPEND SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_mac.cpp)
elseif(UNIX)
Expand All @@ -228,6 +239,7 @@ elseif(WIN32)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/src/framelesswindow.cpp
${PROJECT_SOURCE_DIR}/src/framelesswindow.h
${PROJECT_SOURCE_DIR}/src/images/notes.rc)

list(APPEND SOURCES_3RD_PARTY
${PROJECT_SOURCE_DIR}/3rdParty/qxt/qxtglobalshortcut_win.cpp)
endif()
Expand All @@ -240,11 +252,18 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/src)
# Include third-party headers as 'system' files, in order to silence compiler warnings on them.
target_include_directories(
${PROJECT_NAME} SYSTEM
PUBLIC ${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include
${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src
PUBLIC ${PROJECT_SOURCE_DIR}/3rdParty/qautostart/src
${PROJECT_SOURCE_DIR}/3rdParty/qmarkdowntextedit
${PROJECT_SOURCE_DIR}/3rdParty/qxt)

if(UPDATE_CHECKER)
target_include_directories(
${PROJECT_NAME} SYSTEM
PUBLIC ${PROJECT_SOURCE_DIR}/3rdParty/QSimpleUpdater/include)

add_definitions(-DUPDATE_CHECKER)
endif()

target_compile_definitions(
${PROJECT_NAME}
PUBLIC APP_VERSION="${PROJECT_VERSION}${GIT_REV}"
Expand Down
8 changes: 5 additions & 3 deletions src/aboutwindow.cpp
Expand Up @@ -23,9 +23,11 @@ AboutWindow::AboutWindow(QWidget *parent) : QDialog(parent), m_ui(new Ui::AboutW
"Ahmed<br/><br/><strong>Designers:</strong><br/>Kevin Doyle<br/><br/>And to the "
"many of our beloved users who keep sending us feedback, you are an essential force in "
"helping us improve, thank you!<br/><br/><strong>Notes makes use of the following "
"third-party "
"libraries:</strong><br/><br/>QMarkdownTextEdit<br/>QSimpleUpdater<br/>QAutostart<br/"
">QXT<br/><br/><strong>Notes makes use of the following open source "
"third-party libraries:</strong><br/><br/>QMarkdownTextEdit<br/>"
#if defined(UPDATE_CHECKER)
"QSimpleUpdater<br/>"
#endif
"QAutostart<br/>QXT<br/><br/><strong>Notes makes use of the following open source "
"fonts:</strong><br/><br/>Roboto<br/>Source Sans Pro<br/>Trykker<br/>Mate<br/>iA "
"Writer Mono<br/>iA Writer Duo<br/>iA Writer Quattro<br/>");
m_ui->aboutText->setTextColor(QColor(26, 26, 26));
Expand Down
21 changes: 20 additions & 1 deletion src/mainwindow.cpp
Expand Up @@ -8,7 +8,6 @@
#include "ui_mainwindow.h"
#include "notelistdelegate.h"
#include "qxtglobalshortcut.h"
#include "updaterwindow.h"
#include "treeviewlogic.h"
#include "listviewlogic.h"
#include "noteeditorlogic.h"
Expand Down Expand Up @@ -81,7 +80,9 @@ MainWindow::MainWindow(QWidget *parent)
m_isTemp(false),
m_isListViewScrollBarHidden(true),
m_isOperationRunning(false),
#if defined(UPDATE_CHECKER)
m_dontShowUpdateWindow(false),
#endif
m_alwaysStayOnTop(false),
m_useNativeWindowFrame(false),
m_listOfSerifFonts(
Expand Down Expand Up @@ -134,7 +135,9 @@ MainWindow::MainWindow(QWidget *parent)
setupTextEdit();
restoreStates();
setupSignalsSlots();
#if defined(UPDATE_CHECKER)
autoCheckForUpdates();
#endif

QTimer::singleShot(200, this, SLOT(InitData()));
}
Expand Down Expand Up @@ -629,8 +632,10 @@ void MainWindow::setupTitleBarButtons()
*/
void MainWindow::setupSignalsSlots()
{
#if defined(UPDATE_CHECKER)
connect(&m_updater, &UpdaterWindow::dontShowUpdateWindowChanged, this,
[=](bool state) { m_dontShowUpdateWindow = state; });
#endif
// Style Editor Window
connect(&m_styleEditorWindow, &StyleEditorWindow::changeFontType, this,
[=](FontTypeface fontType) { changeEditorFontTypeFromStyleButtons(fontType); });
Expand Down Expand Up @@ -790,12 +795,14 @@ void MainWindow::setupSignalsSlots()
* Checks for updates, if an update is found, then the updater dialog will show
* up, otherwise, no notification shall be showed
*/
#if defined(UPDATE_CHECKER)
void MainWindow::autoCheckForUpdates()
{
m_updater.installEventFilter(this);
m_updater.setShowWindowDisable(m_dontShowUpdateWindow);
m_updater.checkForUpdates(false);
}
#endif

void MainWindow::setSearchEditStyleSheet(bool isFocused = false)
{
Expand Down Expand Up @@ -1069,9 +1076,11 @@ void MainWindow::initializeSettingsDatabase()
if (m_settingsDatabase->value(QStringLiteral("version"), "NULL") == "NULL")
m_settingsDatabase->setValue(QStringLiteral("version"), qApp->applicationVersion());

#if defined(UPDATE_CHECKER)
if (m_settingsDatabase->value(QStringLiteral("dontShowUpdateWindow"), "NULL") == "NULL")
m_settingsDatabase->setValue(QStringLiteral("dontShowUpdateWindow"),
m_dontShowUpdateWindow);
#endif

if (m_settingsDatabase->value(QStringLiteral("windowGeometry"), "NULL") == "NULL") {
int initWidth = 870;
Expand Down Expand Up @@ -1244,9 +1253,11 @@ void MainWindow::restoreStates()
// }
#endif

#if defined(UPDATE_CHECKER)
if (m_settingsDatabase->value(QStringLiteral("dontShowUpdateWindow"), "NULL") != "NULL")
m_dontShowUpdateWindow =
m_settingsDatabase->value(QStringLiteral("dontShowUpdateWindow")).toBool();
#endif

m_splitter->setCollapsible(0, true);
m_splitter->resize(width() - m_layoutMargin, height() - m_layoutMargin);
Expand Down Expand Up @@ -1606,9 +1617,11 @@ void MainWindow::onDotsButtonClicked()
}
});

#if defined(UPDATE_CHECKER)
// Check for update action
QAction *checkForUpdatesAction = mainMenu.addAction(tr("Check For &Updates"));
connect(checkForUpdatesAction, &QAction::triggered, this, &MainWindow::checkForUpdates);
#endif

// Autostart
QAction *autostartAction = mainMenu.addAction(tr("&Start automatically"));
Expand Down Expand Up @@ -2182,10 +2195,12 @@ void MainWindow::QuitApplication()
* Called when the "Check for Updates" menu item is clicked, this function
* instructs the updater window to check if there are any updates available
*/
#if defined(UPDATE_CHECKER)
void MainWindow::checkForUpdates()
{
m_updater.checkForUpdates(true);
}
#endif

/*!
* \brief MainWindow::importNotesFile
Expand Down Expand Up @@ -2452,7 +2467,9 @@ void MainWindow::closeEvent(QCloseEvent *event)

m_noteEditorLogic->saveNoteToDB();

#if defined(UPDATE_CHECKER)
m_settingsDatabase->setValue(QStringLiteral("dontShowUpdateWindow"), m_dontShowUpdateWindow);
#endif
m_settingsDatabase->setValue(QStringLiteral("splitterSizes"), m_splitter->saveState());

QString currentFontTypefaceString;
Expand Down Expand Up @@ -3457,6 +3474,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event)
break;
}
case QEvent::Show:
#if defined(UPDATE_CHECKER)
if (object == &m_updater) {

QRect rect = m_updater.geometry();
Expand All @@ -3468,6 +3486,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event)

m_updater.setGeometry(QRect(x, y, rect.width(), rect.height()));
}
#endif
break;
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
Expand Down
14 changes: 13 additions & 1 deletion src/mainwindow.h
Expand Up @@ -29,7 +29,11 @@
#include "notelistmodel.h"
#include "notelistview.h"
#include "nodetreemodel.h"
#include "updaterwindow.h"

#if defined(UPDATE_CHECKER)
# include "updaterwindow.h"
#endif

#include "styleeditorwindow.h"
#include "dbmanager.h"
#include "customDocument.h"
Expand Down Expand Up @@ -148,7 +152,9 @@ public slots:
DBManager *m_dbManager;
QThread *m_dbThread;
SplitterStyle *m_splitterStyle;
#if defined(UPDATE_CHECKER)
UpdaterWindow m_updater;
#endif
StyleEditorWindow m_styleEditorWindow;
AboutWindow m_aboutWindow;
StretchSide m_stretchSide;
Expand All @@ -167,7 +173,9 @@ public slots:
bool m_isTemp;
bool m_isListViewScrollBarHidden;
bool m_isOperationRunning;
#if defined(UPDATE_CHECKER)
bool m_dontShowUpdateWindow;
#endif
bool m_alwaysStayOnTop;
bool m_useNativeWindowFrame;

Expand Down Expand Up @@ -211,7 +219,9 @@ public slots:
void setupRightFrame();
void setupTitleBarButtons();
void setupSignalsSlots();
#if defined(UPDATE_CHECKER)
void autoCheckForUpdates();
#endif
void setupSearchEdit();
void resetEditorSettings();
void setupTextEditStyleSheet(int paddingLeft, int paddingRight);
Expand Down Expand Up @@ -272,7 +282,9 @@ private slots:
void maximizeWindow();
void minimizeWindow();
void QuitApplication();
#if defined(UPDATE_CHECKER)
void checkForUpdates();
#endif
void collapseNoteList();
void expandNoteList();
void toggleNoteList();
Expand Down

1 comment on commit 0ef084e

@danfe
Copy link

@danfe danfe commented on 0ef084e Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Now I can drop local update-disabling patches from the FreeBSD port. :-)

Please sign in to comment.