Add option to disable QSU (#6)

This commit is contained in:
Alex Spataru 2021-02-05 08:34:47 -05:00
parent 3bd194f3a4
commit 69a3d443a7
6 changed files with 69 additions and 44 deletions

View File

@ -20,9 +20,9 @@
# THE SOFTWARE. # THE SOFTWARE.
# #
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
# Make options # Make options
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
UI_DIR = uic UI_DIR = uic
MOC_DIR = moc MOC_DIR = moc
@ -35,16 +35,16 @@ isEmpty(PREFIX) {
PREFIX = /usr PREFIX = /usr
} }
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
# Qt configuration # Qt configuration
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
TEMPLATE = app TEMPLATE = app # Project template
TARGET = serial-studio TARGET = serial-studio # Set default target name
CONFIG += resources_big # Avoid isses with large *.qrc
CONFIG += qtquickcompiler # Pre-compile QML interface
CONFIG += qtc_runnable QTPLUGIN += qsvg # Fixes issues with windeployqt
CONFIG += resources_big
CONFIG += qtquickcompiler
QT += xml QT += xml
QT += sql QT += sql
@ -56,11 +56,9 @@ QT += widgets
QT += serialport QT += serialport
QT += quickcontrols2 QT += quickcontrols2
QTPLUGIN += qsvg #-----------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Compiler options # Compiler options
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
*g++*: { *g++*: {
QMAKE_CXXFLAGS_RELEASE -= -O QMAKE_CXXFLAGS_RELEASE -= -O
@ -72,49 +70,49 @@ QTPLUGIN += qsvg
QMAKE_CXXFLAGS_RELEASE *= /O2 QMAKE_CXXFLAGS_RELEASE *= /O2
} }
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
# Libraries # Libraries
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
include(libs/Libraries.pri) include(libs/Libraries.pri)
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
# Deploy options # Deploy options
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
win32* { win32* {
TARGET = SerialStudio TARGET = SerialStudio # Change target name
RC_FILE = deploy/windows/resources/info.rc RC_FILE = deploy/windows/resources/info.rc # Set applicaiton icon
} }
macx* { macx* {
TARGET = SerialStudio TARGET = SerialStudio # Change target name
ICON = deploy/macOS/icon.icns ICON = deploy/macOS/icon.icns # icon file
RC_FILE = deploy/macOS/icon.icns RC_FILE = deploy/macOS/icon.icns # icon file
QMAKE_INFO_PLIST = deploy/macOS/info.plist QMAKE_INFO_PLIST = deploy/macOS/info.plist # Add info.plist file
CONFIG += sdk_no_version_check # To avoid warnings with Big Sur CONFIG += sdk_no_version_check # Avoid warnings with Big Sur
} }
target.path = $$PREFIX/bin target.path = $$PREFIX/bin
linux:!android { linux:!android {
icon.path = $$PREFIX/share/pixmaps icon.path = $$PREFIX/share/pixmaps # icon instalation path
desktop.path = $$PREFIX/share/applications desktop.path = $$PREFIX/share/applications # *.desktop instalation path
icon.files += deploy/linux/serial-studio.png icon.files += deploy/linux/serial-studio.png # Add application icon
desktop.files += deploy/linux/serial-studio.desktop desktop.files += deploy/linux/serial-studio.desktop # Add *.desktop file
INSTALLS += target desktop icon # make install targets
INSTALLS += target desktop icon
} }
mingw { mingw {
license.path = $$PREFIX/share/licenses/$$TARGET license.path = $$PREFIX/share/licenses/$$TARGET # Set license install path
license.files += LICENSE.md license.files += LICENSE.md # Add LICENSE.md file
INSTALLS += target license INSTALLS += target license # Install target+licence (MSYS2)
DEFINES += DISABLE_QSU # Disable QSimpleUpdater (MSYS2)
} }
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
# Import source code # Import source code
#------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------
INCLUDEPATH += src INCLUDEPATH += src

View File

@ -129,10 +129,12 @@ Window {
Button { Button {
Layout.fillWidth: true Layout.fillWidth: true
visible: Cpp_UpdaterEnabled
enabled: Cpp_UpdaterEnabled
text: qsTr("Check for updates") + Cpp_Misc_Translator.dummy text: qsTr("Check for updates") + Cpp_Misc_Translator.dummy
onClicked: { onClicked: {
CppUpdater.setNotifyOnFinish(Cpp_AppUpdaterUrl, true) Cpp_Updater.setNotifyOnFinish(Cpp_AppUpdaterUrl, true)
CppUpdater.checkForUpdates(Cpp_AppUpdaterUrl) Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
} }
} }

View File

@ -170,11 +170,11 @@ ApplicationWindow {
// Second launch ask user if he/she wants to enable automatic updates // Second launch ask user if he/she wants to enable automatic updates
if (appLaunchStatus == 2) if (appLaunchStatus == 2)
automaticUpdatesMessageDialog.visible = true automaticUpdatesMessageDialog.visible = Cpp_UpdaterEnabled
// Check for updates (if we are allowed) // Check for updates (if we are allowed)
if (automaticUpdates) if (automaticUpdates && Cpp_UpdaterEnabled)
CppUpdater.checkForUpdates(Cpp_AppUpdaterUrl) Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
} }
} }
@ -376,7 +376,7 @@ ApplicationWindow {
// Behavior when the user clicks on "Yes" // Behavior when the user clicks on "Yes"
onAccepted: { onAccepted: {
app.automaticUpdates = true app.automaticUpdates = true
CppUpdater.checkForUpdates(Cpp_AppUpdaterUrl) Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
} }
// Behavior when the user clicks on "No" // Behavior when the user clicks on "No"

View File

@ -27,7 +27,7 @@
#include <QString> #include <QString>
// clang-format off // clang-format off
#define APP_VERSION "1.0.14" #define APP_VERSION "1.0.12"
#define APP_DEVELOPER "Alex Spataru" #define APP_DEVELOPER "Alex Spataru"
#define APP_NAME "Serial Studio" #define APP_NAME "Serial Studio"
#define APP_ICON ":/images/icon.png" #define APP_ICON ":/images/icon.png"

View File

@ -55,7 +55,7 @@
*/ */
ModuleManager::ModuleManager() ModuleManager::ModuleManager()
{ {
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(stopOperations())); connect(engine(), SIGNAL(quit()), this, SLOT(stopOperations()));
LOG_INFO() << "Initialized module manager class"; LOG_INFO() << "Initialized module manager class";
} }
@ -82,6 +82,9 @@ void ModuleManager::configureLogger()
*/ */
void ModuleManager::configureUpdater() void ModuleManager::configureUpdater()
{ {
if (!autoUpdaterEnabled())
return;
LOG_INFO() << "Configuring QSimpleUpdater..."; LOG_INFO() << "Configuring QSimpleUpdater...";
QSimpleUpdater::getInstance()->setNotifyOnUpdate(APP_UPDATER_URL, true); QSimpleUpdater::getInstance()->setNotifyOnUpdate(APP_UPDATER_URL, true);
QSimpleUpdater::getInstance()->setNotifyOnFinish(APP_UPDATER_URL, false); QSimpleUpdater::getInstance()->setNotifyOnFinish(APP_UPDATER_URL, false);
@ -102,6 +105,22 @@ void ModuleManager::registerQmlTypes()
qmlRegisterType<JSON::Dataset>("SerialStudio", 1, 0, "Dataset"); qmlRegisterType<JSON::Dataset>("SerialStudio", 1, 0, "Dataset");
} }
/**
* Enables or disables the auto-updater system (QSimpleUpdater).
*
* To disable QSimpleUpdater, you need to add DEFINES += DISABLE_QSU in the qmake project
* file. This option is provided for package managers, users are expected to update the
* application using the same package manager they used for installing it.
*/
bool ModuleManager::autoUpdaterEnabled()
{
#ifdef DISABLE_QSU
return false;
#else
return true;
#endif
}
/** /**
* Initializes all the application modules, registers them with the QML engine and loads * Initializes all the application modules, registers them with the QML engine and loads
* the "main.qml" file as the root QML file. * the "main.qml" file as the root QML file.
@ -123,9 +142,14 @@ void ModuleManager::initializeQmlInterface()
auto jsonGenerator = JSON::Generator::getInstance(); auto jsonGenerator = JSON::Generator::getInstance();
LOG_INFO() << "Finished initializing C++ modules"; LOG_INFO() << "Finished initializing C++ modules";
// Retranslate the QML interface automagically
connect(translator, &Misc::Translator::languageChanged,
engine(), &QQmlEngine::retranslate);
// Register C++ modules with QML // Register C++ modules with QML
auto c = engine()->rootContext(); auto c = engine()->rootContext();
c->setContextProperty("CppUpdater", updater); c->setContextProperty("Cpp_Updater", updater);
c->setContextProperty("Cpp_UpdaterEnabled", autoUpdaterEnabled());
c->setContextProperty("Cpp_Misc_Translator", translator); c->setContextProperty("Cpp_Misc_Translator", translator);
c->setContextProperty("Cpp_CSV_Export", csvExport); c->setContextProperty("Cpp_CSV_Export", csvExport);
c->setContextProperty("Cpp_CSV_Player", csvPlayer); c->setContextProperty("Cpp_CSV_Player", csvPlayer);

View File

@ -36,6 +36,7 @@ public:
void configureLogger(); void configureLogger();
void configureUpdater(); void configureUpdater();
void registerQmlTypes(); void registerQmlTypes();
bool autoUpdaterEnabled();
void initializeQmlInterface(); void initializeQmlInterface();
QQmlApplicationEngine *engine(); QQmlApplicationEngine *engine();