UI: Simplify main().

This commit is contained in:
Nodir Temirkhodjaev 2021-05-23 17:46:47 +03:00
parent f53672603e
commit 02397a9736
3 changed files with 18 additions and 13 deletions

View File

@ -9,6 +9,7 @@
#include "util/dateutil.h"
#include "util/envmanager.h"
#include "util/fileutil.h"
#include "util/osutil.h"
#include "util/startuputil.h"
#include "util/stringutil.h"
@ -103,6 +104,9 @@ void FortSettings::setupGlobal()
qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", dpiPolicy.toLatin1());
}
m_hasService = StartupUtil::isServiceInstalled();
m_isUserAdmin = OsUtil::isUserAdmin();
m_noCache = settings.value("global/noCache").toBool();
m_defaultLanguage = settings.value("global/defaultLanguage").toString();

View File

@ -20,14 +20,11 @@ public:
bool noCache() const { return m_noCache; }
bool isService() const { return m_isService; }
bool hasService() const { return m_hasService; }
void setHasService(bool v) { m_hasService = v; }
bool isServiceClient() const { return hasService() && !isService(); }
bool isUserAdmin() const { return m_isUserAdmin; }
void setIsUserAdmin(bool v) { m_isUserAdmin = v; }
QString defaultLanguage() const { return m_defaultLanguage; }

View File

@ -40,25 +40,32 @@ void install(const char *arg)
}
}
}
int main(int argc, char *argv[])
bool processArgs(int argc, char *argv[])
{
// Uninstall
if (argc > 1 && !strcmp(argv[1], "-u")) {
uninstall();
return 0;
return true;
}
// Install
if (argc > 2 && !strcmp(argv[1], "-i")) {
install(argv[2]);
return 0;
return true;
}
return false;
}
}
int main(int argc, char *argv[])
{
if (processArgs(argc, argv))
return 0;
// Process global settings required before QApplication costruction
FortSettings settings;
settings.setHasService(StartupUtil::isServiceInstalled());
settings.setupGlobal();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -80,9 +87,8 @@ int main(int argc, char *argv[])
ControlManager controlManager(&settings);
// Send control command to running instance
if (controlManager.isCommandClient()) {
if (controlManager.isCommandClient())
return controlManager.postCommand() ? 0 : FORT_ERROR_CONTROL;
}
FortManager::setupResources();
@ -92,8 +98,6 @@ int main(int argc, char *argv[])
if (!fortManager.checkRunningInstance())
return FORT_ERROR_INSTANCE;
settings.setIsUserAdmin(OsUtil::isUserAdmin());
fortManager.initialize();
if (settings.isService()) {