Skip to content

Commit

Permalink
logging enabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Nethius committed Sep 26, 2023
1 parent 1a8c087 commit acb306a
Showing 1 changed file with 58 additions and 45 deletions.
103 changes: 58 additions & 45 deletions client/amnezia_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
AmneziaApplication::AmneziaApplication(int &argc, char *argv[]) : AMNEZIA_BASE_CLASS(argc, argv)
#else
AmneziaApplication::AmneziaApplication(int &argc, char *argv[], bool allowSecondary, SingleApplication::Options options,
int timeout, const QString &userData)
AmneziaApplication::AmneziaApplication(int &argc, char *argv[], bool allowSecondary,
SingleApplication::Options options, int timeout,
const QString &userData)
: SingleApplication(argc, argv, allowSecondary, options, timeout, userData)
#endif
{
Expand All @@ -43,16 +44,17 @@ AmneziaApplication::AmneziaApplication(int &argc, char *argv[], bool allowSecond
s.setValue("permFixed", true);
}

QString configLoc1 = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/"
+ ORGANIZATION_NAME + "/" + APPLICATION_NAME + ".conf";
QString configLoc1 = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first()
+ "/" + ORGANIZATION_NAME + "/" + APPLICATION_NAME + ".conf";
QFile::setPermissions(configLoc1, QFileDevice::ReadOwner | QFileDevice::WriteOwner);

QString configLoc2 = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/"
+ ORGANIZATION_NAME + "/" + APPLICATION_NAME + "/" + APPLICATION_NAME + ".conf";
QString configLoc2 = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first()
+ "/" + ORGANIZATION_NAME + "/" + APPLICATION_NAME + "/" + APPLICATION_NAME + ".conf";
QFile::setPermissions(configLoc2, QFileDevice::ReadOwner | QFileDevice::WriteOwner);
#endif

m_settings = std::shared_ptr<Settings>(new Settings);
m_settings->setSaveLogs(true);
}

AmneziaApplication::~AmneziaApplication()
Expand Down Expand Up @@ -105,11 +107,12 @@ void AmneziaApplication::init()
return;
}

connect(AndroidController::instance(), &AndroidController::importConfigFromOutside, [this](QString data) {
m_pageController->replaceStartPage();
m_importController->extractConfigFromData(data);
m_pageController->goToPageViewConfig();
});
connect(AndroidController::instance(), &AndroidController::importConfigFromOutside,
[this](QString data) {
m_pageController->replaceStartPage();
m_importController->extractConfigFromData(data);
m_pageController->goToPageViewConfig();
});
#endif

#ifdef Q_OS_IOS
Expand All @@ -120,24 +123,25 @@ void AmneziaApplication::init()
m_pageController->goToPageViewConfig();
});

connect(IosController::Instance(), &IosController::importBackupFromOutside, [this](QString filePath) {
m_pageController->replaceStartPage();
m_pageController->goToPageSettingsBackup();
m_settingsController->importBackupFromOutside(filePath);
});
connect(IosController::Instance(), &IosController::importBackupFromOutside,
[this](QString filePath) {
m_pageController->replaceStartPage();
m_pageController->goToPageSettingsBackup();
m_settingsController->importBackupFromOutside(filePath);
});
#endif

m_notificationHandler.reset(NotificationHandler::create(nullptr));

connect(m_vpnConnection.get(), &VpnConnection::connectionStateChanged, m_notificationHandler.get(),
&NotificationHandler::setConnectionState);
connect(m_vpnConnection.get(), &VpnConnection::connectionStateChanged,
m_notificationHandler.get(), &NotificationHandler::setConnectionState);

connect(m_notificationHandler.get(), &NotificationHandler::raiseRequested, m_pageController.get(),
&PageController::raiseMainWindow);
connect(m_notificationHandler.get(), &NotificationHandler::connectRequested, m_connectionController.get(),
&ConnectionController::openConnection);
connect(m_notificationHandler.get(), &NotificationHandler::disconnectRequested, m_connectionController.get(),
&ConnectionController::closeConnection);
connect(m_notificationHandler.get(), &NotificationHandler::raiseRequested,
m_pageController.get(), &PageController::raiseMainWindow);
connect(m_notificationHandler.get(), &NotificationHandler::connectRequested,
m_connectionController.get(), &ConnectionController::openConnection);
connect(m_notificationHandler.get(), &NotificationHandler::disconnectRequested,
m_connectionController.get(), &ConnectionController::closeConnection);

m_engine->load(url);
m_systemController->setQmlRoot(m_engine->rootObjects().value(0));
Expand Down Expand Up @@ -202,8 +206,8 @@ void AmneziaApplication::registerTypes()
m_protocolProps.reset(new ProtocolProps());
qmlRegisterSingletonInstance("ProtocolProps", 1, 0, "ProtocolProps", m_protocolProps.get());

qmlRegisterSingletonType(QUrl("qrc:/ui/qml/Filters/ContainersModelFilters.qml"), "ContainersModelFilters", 1, 0,
"ContainersModelFilters");
qmlRegisterSingletonType(QUrl("qrc:/ui/qml/Filters/ContainersModelFilters.qml"),
"ContainersModelFilters", 1, 0, "ContainersModelFilters");

//
Vpn::declareQmlVpnConnectionStateEnum();
Expand All @@ -222,7 +226,8 @@ void AmneziaApplication::loadTranslator()
auto locale = m_settings->getAppLanguage();
m_translator.reset(new QTranslator());
if (locale != QLocale::English) {
if (m_translator->load(locale, QString("amneziavpn"), QLatin1String("_"), QLatin1String(":/i18n"))) {
if (m_translator->load(locale, QString("amneziavpn"), QLatin1String("_"),
QLatin1String(":/i18n"))) {
if (QCoreApplication::installTranslator(m_translator.get())) {
m_settings->setAppLanguage(locale);
}
Expand All @@ -241,7 +246,8 @@ void AmneziaApplication::updateTranslator(const QLocale &locale)
m_engine->retranslate();
}

if (m_translator->load(locale, QString("amneziavpn"), QLatin1String("_"), QLatin1String(":/i18n"))) {
if (m_translator->load(locale, QString("amneziavpn"), QLatin1String("_"),
QLatin1String(":/i18n"))) {
if (QCoreApplication::installTranslator(m_translator.get())) {
m_settings->setAppLanguage(locale);
}
Expand Down Expand Up @@ -287,22 +293,24 @@ void AmneziaApplication::initModels()

m_serversModel.reset(new ServersModel(m_settings, this));
m_engine->rootContext()->setContextProperty("ServersModel", m_serversModel.get());
connect(m_serversModel.get(), &ServersModel::currentlyProcessedServerIndexChanged, m_containersModel.get(),
&ContainersModel::setCurrentlyProcessedServerIndex);
connect(m_serversModel.get(), &ServersModel::currentlyProcessedServerIndexChanged,
m_containersModel.get(), &ContainersModel::setCurrentlyProcessedServerIndex);

m_languageModel.reset(new LanguageModel(m_settings, this));
m_engine->rootContext()->setContextProperty("LanguageModel", m_languageModel.get());
connect(m_languageModel.get(), &LanguageModel::updateTranslations, this, &AmneziaApplication::updateTranslator);
connect(this, &AmneziaApplication::translationsUpdated, m_languageModel.get(), &LanguageModel::translationsUpdated);
connect(m_languageModel.get(), &LanguageModel::updateTranslations, this,
&AmneziaApplication::updateTranslator);
connect(this, &AmneziaApplication::translationsUpdated, m_languageModel.get(),
&LanguageModel::translationsUpdated);

m_sitesModel.reset(new SitesModel(m_settings, this));
m_engine->rootContext()->setContextProperty("SitesModel", m_sitesModel.get());
connect(m_containersModel.get(), &ContainersModel::defaultContainerChanged, this, [this]() {
if (m_containersModel->getDefaultContainer() == DockerContainer::WireGuard
&& m_sitesModel->getRouteMode() != Settings::RouteMode::VpnAllSites) {
m_sitesModel->setRouteMode(Settings::RouteMode::VpnAllSites);
emit m_pageController->showNotificationMessage(
tr("Split tunneling for WireGuard is not implemented, the option was disabled"));
emit m_pageController->showNotificationMessage(tr(
"Split tunneling for WireGuard is not implemented, the option was disabled"));
}
});

Expand All @@ -313,7 +321,8 @@ void AmneziaApplication::initModels()
m_engine->rootContext()->setContextProperty("OpenVpnConfigModel", m_openVpnConfigModel.get());

m_shadowSocksConfigModel.reset(new ShadowSocksConfigModel(this));
m_engine->rootContext()->setContextProperty("ShadowSocksConfigModel", m_shadowSocksConfigModel.get());
m_engine->rootContext()->setContextProperty("ShadowSocksConfigModel",
m_shadowSocksConfigModel.get());

m_cloakConfigModel.reset(new CloakConfigModel(this));
m_engine->rootContext()->setContextProperty("CloakConfigModel", m_cloakConfigModel.get());
Expand All @@ -332,28 +341,32 @@ void AmneziaApplication::initModels()

void AmneziaApplication::initControllers()
{
m_connectionController.reset(new ConnectionController(m_serversModel, m_containersModel, m_vpnConnection));
m_connectionController.reset(
new ConnectionController(m_serversModel, m_containersModel, m_vpnConnection));
m_engine->rootContext()->setContextProperty("ConnectionController", m_connectionController.get());

m_pageController.reset(new PageController(m_serversModel, m_settings));
m_engine->rootContext()->setContextProperty("PageController", m_pageController.get());

m_installController.reset(new InstallController(m_serversModel, m_containersModel, m_protocolsModel, m_settings));
m_installController.reset(
new InstallController(m_serversModel, m_containersModel, m_protocolsModel, m_settings));
m_engine->rootContext()->setContextProperty("InstallController", m_installController.get());
connect(m_installController.get(), &InstallController::passphraseRequestStarted, m_pageController.get(),
&PageController::showPassphraseRequestDrawer);
connect(m_pageController.get(), &PageController::passphraseRequestDrawerClosed, m_installController.get(),
&InstallController::setEncryptedPassphrase);
connect(m_installController.get(), &InstallController::currentContainerUpdated, m_connectionController.get(),
&ConnectionController::onCurrentContainerUpdated);
connect(m_installController.get(), &InstallController::passphraseRequestStarted,
m_pageController.get(), &PageController::showPassphraseRequestDrawer);
connect(m_pageController.get(), &PageController::passphraseRequestDrawerClosed,
m_installController.get(), &InstallController::setEncryptedPassphrase);
connect(m_installController.get(), &InstallController::currentContainerUpdated,
m_connectionController.get(), &ConnectionController::onCurrentContainerUpdated);

m_importController.reset(new ImportController(m_serversModel, m_containersModel, m_settings));
m_engine->rootContext()->setContextProperty("ImportController", m_importController.get());

m_exportController.reset(new ExportController(m_serversModel, m_containersModel, m_settings, m_configurator));
m_exportController.reset(
new ExportController(m_serversModel, m_containersModel, m_settings, m_configurator));
m_engine->rootContext()->setContextProperty("ExportController", m_exportController.get());

m_settingsController.reset(new SettingsController(m_serversModel, m_containersModel, m_languageModel, m_settings));
m_settingsController.reset(
new SettingsController(m_serversModel, m_containersModel, m_languageModel, m_settings));
m_engine->rootContext()->setContextProperty("SettingsController", m_settingsController.get());
if (m_settingsController->isAutoStartEnabled() && m_serversModel->getDefaultServerIndex() >= 0) {
QTimer::singleShot(1000, this, [this]() { m_connectionController->openConnection(); });
Expand Down

0 comments on commit acb306a

Please sign in to comment.