refactor: Move installer flag handling to launcher

This is only used by the launcher
This commit is contained in:
Lars Toenning
2024-02-15 23:01:00 +01:00
parent a84e299e45
commit a664371567
5 changed files with 31 additions and 31 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -6,6 +6,7 @@
#include "blackcore/db/databasereaderconfig.h"
#include "blackmisc/directoryutils.h"
#include "blackmisc/icons.h"
#include "blackcore/webdataservices.h"
#include <QtGlobal>
#include <QApplication>
@@ -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())
{

View File

@@ -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<CSwiftLauncher> 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

View File

@@ -63,7 +63,7 @@ public:
};
//! Constructor
explicit CSwiftLauncher(QWidget *parent = nullptr);
CSwiftLauncher(bool installerMode, QWidget *parent = nullptr);
//! Destructor
virtual ~CSwiftLauncher() override;