added the ability to work with an online repository

* added a command line argument for the application, when called, cached profiles will be cleared
This commit is contained in:
vladimir.kuznetsov 2023-03-18 06:06:29 +03:00
parent 6f53abbae3
commit 03599e4da7
10 changed files with 96 additions and 36 deletions

View file

@ -197,16 +197,27 @@ bool AmneziaApplication::parseCommands()
m_parser.addHelpOption(); m_parser.addHelpOption();
m_parser.addVersionOption(); m_parser.addVersionOption();
QCommandLineOption c_autostart {{"a", "autostart"}, "System autostart"}; m_parser.addOption(m_autoStartOption);
m_parser.addOption(c_autostart); m_parser.addOption(m_cleanUpOption);
m_parser.addOption(m_clearProfilesOption);
QCommandLineOption c_cleanup {{"c", "cleanup"}, "Cleanup logs"};
m_parser.addOption(c_cleanup);
m_parser.process(*this); m_parser.process(*this);
if (m_parser.isSet(c_cleanup)) { if (m_parser.isSet(m_cleanUpOption)) {
Logger::cleanUp(); 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]{ QTimer::singleShot(100, this, [this]{
quit(); quit();
}); });

View file

@ -55,7 +55,11 @@ private:
ProtocolProps* m_protocolProps {}; ProtocolProps* m_protocolProps {};
QTranslator* m_translator; QTranslator* m_translator;
QCommandLineParser m_parser; 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")};
}; };

View file

@ -55,9 +55,9 @@ int main(int argc, char *argv[])
app.loadTranslator(); app.loadTranslator();
app.loadFonts(); app.loadFonts();
bool doExec = app.parseCommands(); bool runGuiApplication = app.parseCommands();
if (doExec) { if (runGuiApplication) {
app.init(); app.init();
return app.exec(); return app.exec();
} }

View file

@ -1,8 +1,6 @@
var requestToQuitFromApp = false; var requestToQuitFromApp = false;
var updaterCompleted = 0; var updaterCompleted = 0;
var desktopAppProcessRunning = false; var desktopAppProcessRunning = false;
var appInstalledUninstallerPath;
var appInstalledUninstallerPath_x86;
function appName() function appName()
{ {
@ -18,18 +16,20 @@ function appExecutableFileName()
} }
} }
function appInstalled() function pathToMaintenanceTool()
{ {
if (runningOnWindows()) { if (runningOnWindows()) {
appInstalledUninstallerPath = installer.value("RootDir") + "Program Files/AmneziaVPN/maintenancetool.exe"; return installer.value("TargetDir") + "/maintenancetool.exe";
appInstalledUninstallerPath_x86 = installer.value("RootDir") + "Program Files (x86)/AmneziaVPN/maintenancetool.exe";
} else if (runningOnMacOS()) { } else if (runningOnMacOS()) {
appInstalledUninstallerPath = "/Applications/" + appName() + ".app/maintenancetool.app/Contents/MacOS/maintenancetool"; return installer.value("TargetDir") + "/maintenancetool.app/Contents/MacOS/maintenancetool";
} else if (runningOnLinux()) { } else if (runningOnLinux()) {
appInstalledUninstallerPath = "/opt/" + appName() + "/maintenancetool"; return installer.value("TargetDir") + "/maintenancetool";
}
} }
return installer.fileExists(appInstalledUninstallerPath) || installer.fileExists(appInstalledUninstallerPath_x86); function appInstalled()
{
return installer.fileExists(pathToMaintenanceTool());
} }
function endsWith(str, suffix) function endsWith(str, suffix)
@ -259,18 +259,13 @@ function Controller () {
qsTr("We need to remove the old installation first. Do you wish to proceed?"), qsTr("We need to remove the old installation first. Do you wish to proceed?"),
QMessageBox.Ok | QMessageBox.Cancel)) { QMessageBox.Ok | QMessageBox.Cancel)) {
if (appInstalled()) { if (appInstalled()) {
var resultArray = []; var resultArray = [];
if (installer.fileExists(appInstalledUninstallerPath_x86)) { if (installer.fileExists(pathToMaintenanceTool())) {
console.log("Starting uninstallation " + appInstalledUninstallerPath_x86); console.log("Starting uninstallation " + pathToMaintenanceTool());
resultArray = installer.execute(appInstalledUninstallerPath_x86); var args = ["--sr"];
} resultArray = installer.execute(pathToMaintenanceTool(), args);
if (installer.fileExists(appInstalledUninstallerPath)) {
console.log("Starting uninstallation " + appInstalledUninstallerPath);
resultArray = installer.execute(appInstalledUninstallerPath);
} }
console.log("Uninstaller finished with code: " + resultArray[1]) console.log("Uninstaller finished with code: " + resultArray[1])

View file

@ -13,13 +13,12 @@
<AllowSpaceInPath>true</AllowSpaceInPath> <AllowSpaceInPath>true</AllowSpaceInPath>
<AllowNonAsciiCharacters>false</AllowNonAsciiCharacters> <AllowNonAsciiCharacters>false</AllowNonAsciiCharacters>
<ControlScript>controlscript.js</ControlScript> <ControlScript>controlscript.js</ControlScript>
<RepositorySettingsPageVisible>false</RepositorySettingsPageVisible>
<DependsOnLocalInstallerBinary>true</DependsOnLocalInstallerBinary> <DependsOnLocalInstallerBinary>true</DependsOnLocalInstallerBinary>
<SupportsModify>false</SupportsModify> <SupportsModify>false</SupportsModify>
<DisableAuthorizationFallback>true</DisableAuthorizationFallback> <DisableAuthorizationFallback>true</DisableAuthorizationFallback>
<RemoteRepositories> <RemoteRepositories>
<Repository> <Repository>
<Url>https://amneziavpn.org/updates/linux</Url> <Url>http://localhost/repository</Url>
<Enabled>true</Enabled> <Enabled>true</Enabled>
<DisplayName>AmneziaVPN - repository for Linux</DisplayName> <DisplayName>AmneziaVPN - repository for Linux</DisplayName>
</Repository> </Repository>

View file

@ -13,7 +13,6 @@
<AllowSpaceInPath>true</AllowSpaceInPath> <AllowSpaceInPath>true</AllowSpaceInPath>
<AllowNonAsciiCharacters>false</AllowNonAsciiCharacters> <AllowNonAsciiCharacters>false</AllowNonAsciiCharacters>
<ControlScript>controlscript.js</ControlScript> <ControlScript>controlscript.js</ControlScript>
<RepositorySettingsPageVisible>false</RepositorySettingsPageVisible>
<DependsOnLocalInstallerBinary>true</DependsOnLocalInstallerBinary> <DependsOnLocalInstallerBinary>true</DependsOnLocalInstallerBinary>
<SupportsModify>false</SupportsModify> <SupportsModify>false</SupportsModify>
<DisableAuthorizationFallback>true</DisableAuthorizationFallback> <DisableAuthorizationFallback>true</DisableAuthorizationFallback>

View file

@ -13,8 +13,14 @@
<AllowSpaceInPath>true</AllowSpaceInPath> <AllowSpaceInPath>true</AllowSpaceInPath>
<AllowNonAsciiCharacters>false</AllowNonAsciiCharacters> <AllowNonAsciiCharacters>false</AllowNonAsciiCharacters>
<ControlScript>controlscript.js</ControlScript> <ControlScript>controlscript.js</ControlScript>
<RepositorySettingsPageVisible>false</RepositorySettingsPageVisible>
<DependsOnLocalInstallerBinary>true</DependsOnLocalInstallerBinary> <DependsOnLocalInstallerBinary>true</DependsOnLocalInstallerBinary>
<SupportsModify>false</SupportsModify> <SupportsModify>false</SupportsModify>
<DisableAuthorizationFallback>true</DisableAuthorizationFallback> <DisableAuthorizationFallback>true</DisableAuthorizationFallback>
<RemoteRepositories>
<Repository>
<Url>http://localhost/repository</Url>
<Enabled>1</Enabled>
<DisplayName>AmneziaVPN - repository for Windows</DisplayName>
</Repository>
</RemoteRepositories>
</Installer> </Installer>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ClearProfilesCheckboxForm</class>
<widget class="QWidget" name="ClearProfilesCheckboxForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="ClearProfilesCheckbox">
<property name="text">
<string>Clear client cached profiles</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -47,7 +47,11 @@ function Component()
Component.prototype.componentLoaded = function () Component.prototype.componentLoaded = function ()
{ {
console.log("123");
// if (installer.isPackageManager()) {
installer.addWizardPageItem( component, "ClearProfilesCheckboxForm", QInstaller.ComponentSelection );
console.log("333");
// }
} }
Component.prototype.installationFinishedPageIsShown = function() Component.prototype.installationFinishedPageIsShown = function()
@ -62,7 +66,6 @@ Component.prototype.createOperations = function()
component.createOperations(); component.createOperations();
if (runningOnWindows()) { if (runningOnWindows()) {
component.addOperation("CreateShortcut", "@TargetDir@/" + appExecutableFileName(), component.addOperation("CreateShortcut", "@TargetDir@/" + appExecutableFileName(),
QDesktopServices.storageLocation(QDesktopServices.DesktopLocation) + "/" + appName() + ".lnk", QDesktopServices.storageLocation(QDesktopServices.DesktopLocation) + "/" + appName() + ".lnk",
"workingDirectory=@TargetDir@", "iconPath=@TargetDir@\\" + appExecutableFileName(), "iconId=0"); "workingDirectory=@TargetDir@", "iconPath=@TargetDir@\\" + appExecutableFileName(), "iconId=0");
@ -100,7 +103,6 @@ Component.prototype.createOperations = function()
Component.prototype.installationFinished = function() Component.prototype.installationFinished = function()
{ {
var command = ""; var command = "";
var args = [];
if ((installer.status === QInstaller.Success) && (installer.isInstaller() || installer.isUpdater())) { if ((installer.status === QInstaller.Success) && (installer.isInstaller() || installer.isUpdater())) {
@ -126,6 +128,16 @@ Component.prototype.installationFinished = function()
installer.dropAdminRights() 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")); processStatus = installer.executeDetached(command, args, installer.value("TargetDir"));
} }
} }

View file

@ -8,4 +8,7 @@
<ForcedInstallation>true</ForcedInstallation> <ForcedInstallation>true</ForcedInstallation>
<RequiresAdminRights>true</RequiresAdminRights> <RequiresAdminRights>true</RequiresAdminRights>
<Script>componentscript.js</Script> <Script>componentscript.js</Script>
<UserInterfaces>
<UserInterface>clearProfilesCheckboxForm.ui</UserInterface>
</UserInterfaces>
</Package> </Package>