From a6643715670eb03685c3988761bf539f92eaabaa Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Thu, 15 Feb 2024 23:01:00 +0100 Subject: [PATCH] refactor: Move installer flag handling to launcher This is only used by the launcher --- src/blackcore/application.cpp | 17 ----------------- src/blackcore/application.h | 3 --- src/swiftlauncher/main.cpp | 25 +++++++++++++++++++++++-- src/swiftlauncher/swiftlauncher.cpp | 15 +++++++-------- src/swiftlauncher/swiftlauncher.h | 2 +- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index ec195efcf..aaa962bec 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -872,18 +872,6 @@ namespace BlackCore new CWebDataServices(m_webReadersUsed, m_dbReaderConfig, {}, this)); Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO, "Missing web services"); - // caches from local files (i.e. the files delivered) - if (this->isInstallerOptionSet()) - { - const QDateTime ts = m_webDataServices->getLatestDbEntityCacheTimestamp(); - if (!ts.isValid() || ts < QDateTime::currentDateTimeUtc().addYears(-2)) - { - // we only init, if there are: - // a) no cache timestamps b) or it was not updated for some years - msgs.push_back(m_webDataServices->initDbCachesFromLocalResourceFiles(false)); - } - } - // watchdog if (m_networkWatchDog) { @@ -1251,11 +1239,6 @@ namespace BlackCore return m_parser.isSet(option); } - bool CApplication::isInstallerOptionSet() const - { - return this->isParserOptionSet("installer"); - } - bool CApplication::skipSingleApplicationCheck() const { return this->isParserOptionSet(m_cmdSkipSingleApp); diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 867906649..6ae5d70c8 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -263,9 +263,6 @@ namespace BlackCore //! Add the audio options void addAudioOptions(); - //! Called by installer? - bool isInstallerOptionSet() const; - //! Skip the single application check bool skipSingleApplicationCheck() const; diff --git a/src/swiftlauncher/main.cpp b/src/swiftlauncher/main.cpp index 82a05c308..3cbe421d4 100644 --- a/src/swiftlauncher/main.cpp +++ b/src/swiftlauncher/main.cpp @@ -6,6 +6,7 @@ #include "blackcore/db/databasereaderconfig.h" #include "blackmisc/directoryutils.h" #include "blackmisc/icons.h" +#include "blackcore/webdataservices.h" #include #include @@ -17,6 +18,21 @@ using namespace BlackMisc; using namespace BlackCore; using namespace BlackCore::Db; +//! Init the DB cache from local resource files if the cache has no timestamp or the cache was not updated since 2 years +void initDbCacheFromResourceFileIfRequired(CGuiApplication &a) +{ + Q_ASSERT_X(a.hasWebDataServices(), Q_FUNC_INFO, "Requires web services"); + + CWebDataServices *webDataServices = a.getWebDataServices(); + + // caches from local files (i.e. the files delivered) + const QDateTime ts = webDataServices->getLatestDbEntityCacheTimestamp(); + if (!ts.isValid() || ts < QDateTime::currentDateTimeUtc().addYears(-2)) + { + webDataServices->initDbCachesFromLocalResourceFiles(false); + } +} + int main(int argc, char *argv[]) { CGuiApplication::highDpiScreenSupport(CGuiApplication::scaleFactor(argc, argv)); @@ -24,9 +40,14 @@ int main(int argc, char *argv[]) Q_UNUSED(qa) CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Laucher, CIcons::swiftLauncher1024()); a.addVatlibOptions(); // so it can be passed (hand over) to started applications - a.addParserOption({ { "i", "installer" }, QCoreApplication::translate("main", "Installer setup.") }); + const QCommandLineOption installerOption { { "i", "installer" }, QCoreApplication::translate("main", "Installer setup.") }; + a.addParserOption(installerOption); if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; } a.useWebDataServices(BlackCore::CWebReaderFlags::AllSwiftDbReaders, CDatabaseReaderConfigList::forLauncher()); + + const bool installMode = a.isParserOptionSet(installerOption); + if (installMode) initDbCacheFromResourceFileIfRequired(a); + a.useFacadeNoContexts(); if (!a.start()) { @@ -34,7 +55,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - CSwiftLauncher launcher; + CSwiftLauncher launcher(installMode); const int res = a.exec(); if (res != EXIT_SUCCESS || !launcher.shouldStartAppDetached()) { diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index fc8a7fa92..b8bac8ff1 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -50,11 +50,11 @@ using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::Data; using namespace BlackMisc::Simulation::FsCommon; -CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QMainWindow(parent, CEnableForFramelessWindow::modeToWindowFlags(CEnableForFramelessWindow::WindowNormal)), - CEnableForFramelessWindow(CEnableForFramelessWindow::WindowFrameless, true, "framelessMainWindow", this), - CCentralMultiSimulatorModelSetCachesAware(), - CIdentifiable(this), - ui(new Ui::CSwiftLauncher) +CSwiftLauncher::CSwiftLauncher(bool installerMode, QWidget *parent) : QMainWindow(parent, CEnableForFramelessWindow::modeToWindowFlags(CEnableForFramelessWindow::WindowNormal)), + CEnableForFramelessWindow(CEnableForFramelessWindow::WindowFrameless, true, "framelessMainWindow", this), + CCentralMultiSimulatorModelSetCachesAware(), + CIdentifiable(this), + ui(new Ui::CSwiftLauncher) { Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui"); sGui->registerMainApplicationWidget(this); @@ -100,7 +100,7 @@ CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QMainWindow(parent, CEnableFor } const QPointer myself(this); - if (sGui->isInstallerOptionSet()) + if (installerMode) { QTimer::singleShot(1000, this, [=] { if (!sGui || sGui->isShuttingDown() || !myself) { return; } @@ -114,7 +114,7 @@ CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QMainWindow(parent, CEnableFor if (!sGui || sGui->isShuttingDown() || !myself) { return; } this->onCoreModeReleased(); this->requestMacMicrophoneAccess(); - this->installerMode(); + if (installerMode) this->installerMode(); }); this->show(); @@ -123,7 +123,6 @@ CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QMainWindow(parent, CEnableFor void CSwiftLauncher::installerMode() { if (!sGui || sGui->isShuttingDown()) { return; } - if (!sGui->isInstallerOptionSet()) { return; } bool runDialog = false; do diff --git a/src/swiftlauncher/swiftlauncher.h b/src/swiftlauncher/swiftlauncher.h index cef35ce33..c7a0f7719 100644 --- a/src/swiftlauncher/swiftlauncher.h +++ b/src/swiftlauncher/swiftlauncher.h @@ -63,7 +63,7 @@ public: }; //! Constructor - explicit CSwiftLauncher(QWidget *parent = nullptr); + CSwiftLauncher(bool installerMode, QWidget *parent = nullptr); //! Destructor virtual ~CSwiftLauncher() override;