From 03599e4da75defccf4eb075ba17a06d5727f3b9a Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Sat, 18 Mar 2023 06:06:29 +0300 Subject: [PATCH] added the ability to work with an online repository * added a command line argument for the application, when called, cached profiles will be cleared --- client/amnezia_application.cpp | 23 +++++++++---- client/amnezia_application.h | 4 +++ client/main.cpp | 4 +-- deploy/installer/config/controlscript.js | 33 ++++++++----------- deploy/installer/config/linux.xml.in | 3 +- deploy/installer/config/macos.xml.in | 1 - deploy/installer/config/windows.xml.in | 8 ++++- .../meta/clearProfilesCheckboxForm.ui | 31 +++++++++++++++++ .../meta/componentscript.js | 22 ++++++++++--- .../meta/package.xml.in | 3 ++ 10 files changed, 96 insertions(+), 36 deletions(-) create mode 100644 deploy/installer/packages/org.amneziavpn.package/meta/clearProfilesCheckboxForm.ui diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index 2cb3dad8..5bdfce1c 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -197,16 +197,27 @@ bool AmneziaApplication::parseCommands() m_parser.addHelpOption(); m_parser.addVersionOption(); - QCommandLineOption c_autostart {{"a", "autostart"}, "System autostart"}; - m_parser.addOption(c_autostart); - - QCommandLineOption c_cleanup {{"c", "cleanup"}, "Cleanup logs"}; - m_parser.addOption(c_cleanup); + m_parser.addOption(m_autoStartOption); + m_parser.addOption(m_cleanUpOption); + m_parser.addOption(m_clearProfilesOption); m_parser.process(*this); - if (m_parser.isSet(c_cleanup)) { + if (m_parser.isSet(m_cleanUpOption)) { Logger::cleanUp(); + QTimer::singleShot(100, this, [this]{ + quit(); + }); + exec(); + return false; + } else if (m_parser.isSet(m_clearProfilesOption)) { + for (int i = 0; i < m_settings->serversCount(); i++) { + const auto &containers = m_settings->containers(i).keys(); + for (DockerContainer container : containers) { + m_settings->clearLastConnectionConfig(i, container); + } + } + QTimer::singleShot(100, this, [this]{ quit(); }); diff --git a/client/amnezia_application.h b/client/amnezia_application.h index f0f8f529..45856146 100644 --- a/client/amnezia_application.h +++ b/client/amnezia_application.h @@ -55,7 +55,11 @@ private: ProtocolProps* m_protocolProps {}; QTranslator* m_translator; + QCommandLineParser m_parser; + QCommandLineOption m_autoStartOption {{"a", "autoStart"}, tr("System autostart")}; + QCommandLineOption m_cleanUpOption {{"c", "cleanUp"}, tr("Cleanup logs")}; + QCommandLineOption m_clearProfilesOption {"clearProfiles", tr("Clear client cached profile")}; }; diff --git a/client/main.cpp b/client/main.cpp index e1004597..70b05e2d 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -55,9 +55,9 @@ int main(int argc, char *argv[]) app.loadTranslator(); app.loadFonts(); - bool doExec = app.parseCommands(); + bool runGuiApplication = app.parseCommands(); - if (doExec) { + if (runGuiApplication) { app.init(); return app.exec(); } diff --git a/deploy/installer/config/controlscript.js b/deploy/installer/config/controlscript.js index bf22f8f6..42f5d2dd 100644 --- a/deploy/installer/config/controlscript.js +++ b/deploy/installer/config/controlscript.js @@ -1,8 +1,6 @@ var requestToQuitFromApp = false; var updaterCompleted = 0; var desktopAppProcessRunning = false; -var appInstalledUninstallerPath; -var appInstalledUninstallerPath_x86; function appName() { @@ -18,18 +16,20 @@ function appExecutableFileName() } } -function appInstalled() +function pathToMaintenanceTool() { if (runningOnWindows()) { - appInstalledUninstallerPath = installer.value("RootDir") + "Program Files/AmneziaVPN/maintenancetool.exe"; - appInstalledUninstallerPath_x86 = installer.value("RootDir") + "Program Files (x86)/AmneziaVPN/maintenancetool.exe"; - } else if (runningOnMacOS()){ - appInstalledUninstallerPath = "/Applications/" + appName() + ".app/maintenancetool.app/Contents/MacOS/maintenancetool"; - } else if (runningOnLinux()){ - appInstalledUninstallerPath = "/opt/" + appName() + "/maintenancetool"; + return installer.value("TargetDir") + "/maintenancetool.exe"; + } else if (runningOnMacOS()) { + return installer.value("TargetDir") + "/maintenancetool.app/Contents/MacOS/maintenancetool"; + } else if (runningOnLinux()) { + return installer.value("TargetDir") + "/maintenancetool"; } +} - return installer.fileExists(appInstalledUninstallerPath) || installer.fileExists(appInstalledUninstallerPath_x86); +function appInstalled() +{ + return installer.fileExists(pathToMaintenanceTool()); } function endsWith(str, suffix) @@ -259,18 +259,13 @@ function Controller () { qsTr("We need to remove the old installation first. Do you wish to proceed?"), QMessageBox.Ok | QMessageBox.Cancel)) { - if (appInstalled()) { var resultArray = []; - if (installer.fileExists(appInstalledUninstallerPath_x86)) { - console.log("Starting uninstallation " + appInstalledUninstallerPath_x86); - resultArray = installer.execute(appInstalledUninstallerPath_x86); - } - - if (installer.fileExists(appInstalledUninstallerPath)) { - console.log("Starting uninstallation " + appInstalledUninstallerPath); - resultArray = installer.execute(appInstalledUninstallerPath); + if (installer.fileExists(pathToMaintenanceTool())) { + console.log("Starting uninstallation " + pathToMaintenanceTool()); + var args = ["--sr"]; + resultArray = installer.execute(pathToMaintenanceTool(), args); } console.log("Uninstaller finished with code: " + resultArray[1]) diff --git a/deploy/installer/config/linux.xml.in b/deploy/installer/config/linux.xml.in index 150c9cc5..fb5ac10a 100644 --- a/deploy/installer/config/linux.xml.in +++ b/deploy/installer/config/linux.xml.in @@ -13,13 +13,12 @@ true false controlscript.js - false true false true - https://amneziavpn.org/updates/linux + http://localhost/repository true AmneziaVPN - repository for Linux diff --git a/deploy/installer/config/macos.xml.in b/deploy/installer/config/macos.xml.in index 74b682b7..8de5f5d4 100644 --- a/deploy/installer/config/macos.xml.in +++ b/deploy/installer/config/macos.xml.in @@ -13,7 +13,6 @@ true false controlscript.js - false true false true diff --git a/deploy/installer/config/windows.xml.in b/deploy/installer/config/windows.xml.in index 36daa166..bbe6e684 100644 --- a/deploy/installer/config/windows.xml.in +++ b/deploy/installer/config/windows.xml.in @@ -13,8 +13,14 @@ true false controlscript.js - false true false true + + + http://localhost/repository + 1 + AmneziaVPN - repository for Windows + + diff --git a/deploy/installer/packages/org.amneziavpn.package/meta/clearProfilesCheckboxForm.ui b/deploy/installer/packages/org.amneziavpn.package/meta/clearProfilesCheckboxForm.ui new file mode 100644 index 00000000..caab17b4 --- /dev/null +++ b/deploy/installer/packages/org.amneziavpn.package/meta/clearProfilesCheckboxForm.ui @@ -0,0 +1,31 @@ + + + ClearProfilesCheckboxForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Clear client cached profiles + + + false + + + + + + + + \ No newline at end of file diff --git a/deploy/installer/packages/org.amneziavpn.package/meta/componentscript.js b/deploy/installer/packages/org.amneziavpn.package/meta/componentscript.js index aae48338..307973db 100644 --- a/deploy/installer/packages/org.amneziavpn.package/meta/componentscript.js +++ b/deploy/installer/packages/org.amneziavpn.package/meta/componentscript.js @@ -47,7 +47,11 @@ function Component() Component.prototype.componentLoaded = function () { - + console.log("123"); + // if (installer.isPackageManager()) { + installer.addWizardPageItem( component, "ClearProfilesCheckboxForm", QInstaller.ComponentSelection ); + console.log("333"); + // } } Component.prototype.installationFinishedPageIsShown = function() @@ -62,7 +66,6 @@ Component.prototype.createOperations = function() component.createOperations(); if (runningOnWindows()) { - component.addOperation("CreateShortcut", "@TargetDir@/" + appExecutableFileName(), QDesktopServices.storageLocation(QDesktopServices.DesktopLocation) + "/" + appName() + ".lnk", "workingDirectory=@TargetDir@", "iconPath=@TargetDir@\\" + appExecutableFileName(), "iconId=0"); @@ -100,7 +103,6 @@ Component.prototype.createOperations = function() Component.prototype.installationFinished = function() { var command = ""; - var args = []; if ((installer.status === QInstaller.Success) && (installer.isInstaller() || installer.isUpdater())) { @@ -121,11 +123,21 @@ Component.prototype.installationFinished = function() } else if (runningOnMacOS()) { command = "/Applications/" + appName() + ".app/Contents/MacOS/" + appName(); } else if (runningOnLinux()) { - command = "@TargetDir@/client/" + appName(); - } + command = "@TargetDir@/client/" + appName(); + } installer.dropAdminRights() + if (installer.isUninstaller() || installer.isUpdater()) { + var checkboxForm = component.userInterface( "ClearProfilesCheckboxForm" ); + if (checkboxForm && checkboxForm.ClearProfilesCheckbox.checked) { + var args = ["--clearProfiles"]; + processStatus = installer.execute(command, args, installer.value("TargetDir")); + } + } + + var args = []; processStatus = installer.executeDetached(command, args, installer.value("TargetDir")); + } } diff --git a/deploy/installer/packages/org.amneziavpn.package/meta/package.xml.in b/deploy/installer/packages/org.amneziavpn.package/meta/package.xml.in index 447bad2c..5d84c6a8 100644 --- a/deploy/installer/packages/org.amneziavpn.package/meta/package.xml.in +++ b/deploy/installer/packages/org.amneziavpn.package/meta/package.xml.in @@ -8,4 +8,7 @@ true true + + clearProfilesCheckboxForm.ui +