2021-08-09 00:41:52 +07:00
|
|
|
#include <QDebug>
|
2023-06-30 00:21:56 +01:00
|
|
|
#include <QTimer>
|
2020-11-23 16:20:25 +03:00
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
#include "amneziaApplication.h"
|
|
|
|
|
#include "core/utils/osSignalHandler.h"
|
|
|
|
|
#include "core/utils/migrations.h"
|
2023-08-09 18:17:29 +05:00
|
|
|
#include "version.h"
|
2021-08-19 01:51:02 +03:00
|
|
|
|
2023-08-04 20:35:43 +03:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
2021-02-24 23:40:57 +03:00
|
|
|
#ifdef Q_OS_WIN
|
2023-08-09 18:17:29 +05:00
|
|
|
#include "Windows.h"
|
2021-02-24 23:40:57 +03:00
|
|
|
#endif
|
|
|
|
|
|
2022-07-11 16:08:57 +06:00
|
|
|
#if defined(Q_OS_IOS)
|
2023-08-09 18:17:29 +05:00
|
|
|
#include "platforms/ios/QtAppDelegate-C-Interface.h"
|
2022-07-11 16:08:57 +06:00
|
|
|
#endif
|
|
|
|
|
|
2025-08-10 06:12:19 +03:00
|
|
|
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
|
2024-09-25 11:22:16 +05:00
|
|
|
bool isAnotherInstanceRunning()
|
|
|
|
|
{
|
|
|
|
|
QLocalSocket socket;
|
|
|
|
|
socket.connectToServer("AmneziaVPNInstance");
|
|
|
|
|
if (socket.waitForConnected(500)) {
|
|
|
|
|
qWarning() << "AmneziaVPN is already running";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-23 16:20:25 +03:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2023-03-23 15:13:15 +03:00
|
|
|
Migrations migrationsManager;
|
|
|
|
|
migrationsManager.doMigrations();
|
|
|
|
|
|
2021-02-24 23:40:57 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
AllowSetForegroundWindow(ASFW_ANY);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-10-08 20:08:32 +03:00
|
|
|
#ifdef Q_OS_ANDROID
|
2024-03-14 00:22:56 +03:00
|
|
|
// QTBUG-95974 QTBUG-95764 QTBUG-102168
|
2023-10-08 20:08:32 +03:00
|
|
|
qputenv("QT_ANDROID_DISABLE_ACCESSIBILITY", "1");
|
2024-04-14 14:07:26 +03:00
|
|
|
qputenv("ANDROID_OPENSSL_SUFFIX", "_3");
|
2023-10-08 20:08:32 +03:00
|
|
|
#endif
|
|
|
|
|
|
2022-08-25 12:47:02 +03:00
|
|
|
AmneziaApplication app(argc, argv);
|
2025-12-01 10:45:06 +08:00
|
|
|
OsSignalHandler::setup();
|
2021-02-24 23:40:57 +03:00
|
|
|
|
2025-08-10 06:12:19 +03:00
|
|
|
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
|
2024-09-25 11:22:16 +05:00
|
|
|
if (isAnotherInstanceRunning()) {
|
2023-08-09 18:17:29 +05:00
|
|
|
QTimer::singleShot(1000, &app, [&]() { app.quit(); });
|
2021-03-06 14:59:55 +03:00
|
|
|
return app.exec();
|
|
|
|
|
}
|
2024-09-25 11:22:16 +05:00
|
|
|
app.startLocalServer();
|
2021-08-08 18:10:09 +03:00
|
|
|
#endif
|
|
|
|
|
|
2022-08-25 12:47:02 +03:00
|
|
|
// Allow to raise app window if secondary instance launched
|
2021-02-24 23:40:57 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
AllowSetForegroundWindow(0);
|
|
|
|
|
#endif
|
2020-11-23 16:20:25 +03:00
|
|
|
|
2022-08-25 12:47:02 +03:00
|
|
|
app.registerTypes();
|
2020-11-23 16:20:25 +03:00
|
|
|
|
2020-12-04 00:45:21 +03:00
|
|
|
app.setApplicationName(APPLICATION_NAME);
|
|
|
|
|
app.setOrganizationName(ORGANIZATION_NAME);
|
|
|
|
|
app.setApplicationDisplayName(APPLICATION_NAME);
|
2020-11-23 16:20:25 +03:00
|
|
|
|
2022-08-25 12:47:02 +03:00
|
|
|
app.loadFonts();
|
2021-10-26 12:59:20 +03:00
|
|
|
|
2022-08-31 16:54:46 +03:00
|
|
|
bool doExec = app.parseCommands();
|
2021-02-24 23:40:57 +03:00
|
|
|
|
2022-08-31 16:54:46 +03:00
|
|
|
if (doExec) {
|
|
|
|
|
app.init();
|
2023-08-09 18:17:29 +05:00
|
|
|
|
2024-03-09 00:21:57 +03:00
|
|
|
qInfo().noquote() << QString("Started %1 version %2 %3").arg(APPLICATION_NAME, APP_VERSION, GIT_COMMIT_HASH);
|
2023-08-09 18:17:29 +05:00
|
|
|
qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName(), QSysInfo::currentCpuArchitecture());
|
|
|
|
|
|
2022-08-31 16:54:46 +03:00
|
|
|
return app.exec();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2020-11-23 16:20:25 +03:00
|
|
|
}
|