added autostart and start minimized options
- added disabling split tunneling when selecting the wireguard protocol - if for macos the application is minimized to tray, then now it is not displayed in the dock
This commit is contained in:
parent
23ad006187
commit
4c79905f5b
8 changed files with 173 additions and 44 deletions
|
@ -129,14 +129,16 @@ void AmneziaApplication::init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// if (m_parser.isSet("a")) m_uiLogic->showOnStartup();
|
if (m_parser.isSet("a"))
|
||||||
// else emit m_uiLogic->show();
|
m_pageController->showOnStartup();
|
||||||
// #else
|
else
|
||||||
// m_uiLogic->showOnStartup();
|
emit m_pageController->raiseMainWindow();
|
||||||
// #endif
|
#else
|
||||||
|
m_pageController->showOnStartup();
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO - fix
|
// TODO - fix
|
||||||
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
|
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
|
||||||
if (isPrimary()) {
|
if (isPrimary()) {
|
||||||
QObject::connect(this, &SingleApplication::instanceStarted, m_pageController.get(), [this]() {
|
QObject::connect(this, &SingleApplication::instanceStarted, m_pageController.get(), [this]() {
|
||||||
|
@ -276,6 +278,14 @@ void AmneziaApplication::initModels()
|
||||||
|
|
||||||
m_sitesModel.reset(new SitesModel(m_settings, this));
|
m_sitesModel.reset(new SitesModel(m_settings, this));
|
||||||
m_engine->rootContext()->setContextProperty("SitesModel", m_sitesModel.get());
|
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"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
m_protocolsModel.reset(new ProtocolsModel(m_settings, this));
|
m_protocolsModel.reset(new ProtocolsModel(m_settings, this));
|
||||||
m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());
|
m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());
|
||||||
|
@ -306,7 +316,7 @@ 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_engine->rootContext()->setContextProperty("ConnectionController", m_connectionController.get());
|
||||||
|
|
||||||
m_pageController.reset(new PageController(m_serversModel));
|
m_pageController.reset(new PageController(m_serversModel, m_settings));
|
||||||
m_engine->rootContext()->setContextProperty("PageController", m_pageController.get());
|
m_engine->rootContext()->setContextProperty("PageController", m_pageController.get());
|
||||||
|
|
||||||
m_installController.reset(new InstallController(m_serversModel, m_containersModel, m_settings));
|
m_installController.reset(new InstallController(m_serversModel, m_containersModel, m_settings));
|
||||||
|
|
|
@ -5,9 +5,13 @@
|
||||||
#include "../../platforms/android/androidutils.h"
|
#include "../../platforms/android/androidutils.h"
|
||||||
#include <QJniObject>
|
#include <QJniObject>
|
||||||
#endif
|
#endif
|
||||||
|
#if defined Q_OS_MAC
|
||||||
|
#include "ui/macos_util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
PageController::PageController(const QSharedPointer<ServersModel> &serversModel, QObject *parent)
|
PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
|
||||||
: QObject(parent), m_serversModel(serversModel)
|
const std::shared_ptr<Settings> &settings, QObject *parent)
|
||||||
|
: QObject(parent), m_serversModel(serversModel), m_settings(settings)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
// Change color of navigation and status bar's
|
// Change color of navigation and status bar's
|
||||||
|
@ -23,6 +27,9 @@ PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
connect(this, &PageController::raiseMainWindow, []() { setDockIconVisible(true); });
|
||||||
|
connect(this, &PageController::hideMainWindow, []() { setDockIconVisible(false); });
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PageController::getInitialPage()
|
QString PageController::getInitialPage()
|
||||||
|
@ -88,3 +95,16 @@ void PageController::updateNavigationBarColor(const int color)
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PageController::showOnStartup()
|
||||||
|
{
|
||||||
|
if (!m_settings->isStartMinimized()) {
|
||||||
|
emit raiseMainWindow();
|
||||||
|
} else {
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
emit hideMainWindow();
|
||||||
|
#elif defined Q_OS_MACX
|
||||||
|
setDockIconVisible(false);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -63,7 +63,8 @@ class PageController : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit PageController(const QSharedPointer<ServersModel> &serversModel, QObject *parent = nullptr);
|
explicit PageController(const QSharedPointer<ServersModel> &serversModel, const std::shared_ptr<Settings> &settings,
|
||||||
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QString getInitialPage();
|
QString getInitialPage();
|
||||||
|
@ -75,6 +76,8 @@ public slots:
|
||||||
unsigned int getInitialPageNavigationBarColor();
|
unsigned int getInitialPageNavigationBarColor();
|
||||||
void updateNavigationBarColor(const int color);
|
void updateNavigationBarColor(const int color);
|
||||||
|
|
||||||
|
void showOnStartup();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void goToPageHome();
|
void goToPageHome();
|
||||||
void goToPageSettings();
|
void goToPageSettings();
|
||||||
|
@ -100,6 +103,8 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<ServersModel> m_serversModel;
|
QSharedPointer<ServersModel> m_serversModel;
|
||||||
|
|
||||||
|
std::shared_ptr<Settings> m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PAGECONTROLLER_H
|
#endif // PAGECONTROLLER_H
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "fileUtilites.h"
|
#include "fileUtilites.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "ui/qautostart.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
SettingsController::SettingsController(const QSharedPointer<ServersModel> &serversModel,
|
SettingsController::SettingsController(const QSharedPointer<ServersModel> &serversModel,
|
||||||
|
@ -137,3 +138,23 @@ void SettingsController::toggleAutoConnect(bool enable)
|
||||||
{
|
{
|
||||||
m_settings->setAutoConnect(enable);
|
m_settings->setAutoConnect(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SettingsController::isAutoStartEnabled()
|
||||||
|
{
|
||||||
|
return Autostart::isAutostart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsController::toggleAutoStart(bool enable)
|
||||||
|
{
|
||||||
|
Autostart::setAutostart(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SettingsController::isStartMinimizedEnabled()
|
||||||
|
{
|
||||||
|
return m_settings->isStartMinimized();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsController::toggleStartMinimized(bool enable)
|
||||||
|
{
|
||||||
|
m_settings->setStartMinimized(enable);
|
||||||
|
}
|
||||||
|
|
|
@ -48,6 +48,12 @@ public slots:
|
||||||
bool isAutoConnectEnabled();
|
bool isAutoConnectEnabled();
|
||||||
void toggleAutoConnect(bool enable);
|
void toggleAutoConnect(bool enable);
|
||||||
|
|
||||||
|
bool isAutoStartEnabled();
|
||||||
|
void toggleAutoStart(bool enable);
|
||||||
|
|
||||||
|
bool isStartMinimizedEnabled();
|
||||||
|
void toggleStartMinimized(bool enable);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void primaryDnsChanged();
|
void primaryDnsChanged();
|
||||||
void secondaryDnsChanged();
|
void secondaryDnsChanged();
|
||||||
|
|
|
@ -1,60 +1,86 @@
|
||||||
#include <QMainWindow>
|
|
||||||
#include <Cocoa/Cocoa.h>
|
|
||||||
#include "macos_util.h"
|
#include "macos_util.h"
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
#include <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
// void setDockIconVisible(bool visible)
|
||||||
|
//{
|
||||||
|
// QProcess process;
|
||||||
|
// process.start(
|
||||||
|
// "osascript",
|
||||||
|
// { "-e tell application \"System Events\" to get properties of (get application process \"AmneziaVPN\")" });
|
||||||
|
// process.waitForFinished(3000);
|
||||||
|
// const auto output = QString::fromLocal8Bit(process.readAllStandardOutput());
|
||||||
|
|
||||||
|
// qDebug() << output;
|
||||||
|
|
||||||
|
// if (visible) {
|
||||||
|
// [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
||||||
|
// } else {
|
||||||
|
// [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
void setDockIconVisible(bool visible)
|
void setDockIconVisible(bool visible)
|
||||||
{
|
{
|
||||||
if (!visible) {
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||||
[NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];
|
if (visible) {
|
||||||
|
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
} else {
|
} else {
|
||||||
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
|
TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//this Objective-c class is used to override the action of system close button and zoom button
|
// this Objective-c class is used to override the action of system close button and zoom button
|
||||||
//https://stackoverflow.com/questions/27643659/setting-c-function-as-selector-for-nsbutton-produces-no-results
|
// https://stackoverflow.com/questions/27643659/setting-c-function-as-selector-for-nsbutton-produces-no-results
|
||||||
@interface ButtonPasser : NSObject{
|
@interface ButtonPasser : NSObject {
|
||||||
}
|
}
|
||||||
@property(readwrite) QMainWindow* window;
|
@property (readwrite) QMainWindow *window;
|
||||||
+ (void)closeButtonAction:(id)sender;
|
+ (void)closeButtonAction:(id)sender;
|
||||||
- (void)zoomButtonAction:(id)sender;
|
- (void)zoomButtonAction:(id)sender;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation ButtonPasser{
|
@implementation ButtonPasser {
|
||||||
}
|
}
|
||||||
+ (void)closeButtonAction:(id)sender
|
+ (void)closeButtonAction:(id)sender
|
||||||
{
|
{
|
||||||
Q_UNUSED(sender);
|
Q_UNUSED(sender);
|
||||||
ProcessSerialNumber pn;
|
ProcessSerialNumber pn;
|
||||||
GetFrontProcess (&pn);
|
GetFrontProcess(&pn);
|
||||||
ShowHideProcess(&pn,false);
|
ShowHideProcess(&pn, false);
|
||||||
}
|
}
|
||||||
- (void)zoomButtonAction:(id)sender
|
- (void)zoomButtonAction:(id)sender
|
||||||
{
|
{
|
||||||
Q_UNUSED(sender);
|
Q_UNUSED(sender);
|
||||||
if (0 == self.window) return;
|
if (0 == self.window)
|
||||||
if (self.window->isMaximized()) self.window->showNormal();
|
return;
|
||||||
else self.window->showMaximized();
|
if (self.window->isMaximized())
|
||||||
|
self.window->showNormal();
|
||||||
|
else
|
||||||
|
self.window->showMaximized();
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
void fixWidget(QWidget *widget)
|
void fixWidget(QWidget *widget)
|
||||||
{
|
{
|
||||||
NSView *view = (NSView *)widget->winId();
|
NSView *view = (NSView *)widget->winId();
|
||||||
if (0 == view) return;
|
if (0 == view)
|
||||||
|
return;
|
||||||
NSWindow *window = view.window;
|
NSWindow *window = view.window;
|
||||||
if (0 == window) return;
|
if (0 == window)
|
||||||
|
return;
|
||||||
|
|
||||||
//override the action of close button
|
// override the action of close button
|
||||||
//https://stackoverflow.com/questions/27643659/setting-c-function-as-selector-for-nsbutton-produces-no-results
|
// https://stackoverflow.com/questions/27643659/setting-c-function-as-selector-for-nsbutton-produces-no-results
|
||||||
//https://developer.apple.com/library/content/documentation/General/Conceptual/CocoaEncyclopedia/Target-Action/Target-Action.html
|
// https://developer.apple.com/library/content/documentation/General/Conceptual/CocoaEncyclopedia/Target-Action/Target-Action.html
|
||||||
// NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
|
// NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
|
||||||
// [closeButton setTarget:[ButtonPasser class]];
|
// [closeButton setTarget:[ButtonPasser class]];
|
||||||
// [closeButton setAction:@selector(closeButtonAction:)];
|
// [closeButton setAction:@selector(closeButtonAction:)];
|
||||||
|
|
||||||
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
||||||
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
||||||
|
|
|
@ -43,9 +43,50 @@ PageType {
|
||||||
headerText: qsTr("Application")
|
headerText: qsTr("Application")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwitcherType {
|
||||||
|
visible: !GC.isMobile()
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.margins: 16
|
||||||
|
|
||||||
|
text: qsTr("Auto start")
|
||||||
|
descriptionText: qsTr("Launch the application every time ") + Qt.platform.os + qsTr(" starts")
|
||||||
|
|
||||||
|
checked: SettingsController.isAutoStartEnabled()
|
||||||
|
onCheckedChanged: {
|
||||||
|
if (checked !== SettingsController.isAutoStartEnabled()) {
|
||||||
|
SettingsController.toggleAutoStart(checked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DividerType {
|
||||||
|
visible: !GC.isMobile()
|
||||||
|
}
|
||||||
|
|
||||||
|
SwitcherType {
|
||||||
|
visible: !GC.isMobile()
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.margins: 16
|
||||||
|
|
||||||
|
text: qsTr("Start minimized")
|
||||||
|
descriptionText: qsTr("Launch application minimized")
|
||||||
|
|
||||||
|
checked: SettingsController.isStartMinimizedEnabled()
|
||||||
|
onCheckedChanged: {
|
||||||
|
if (checked !== SettingsController.isStartMinimizedEnabled()) {
|
||||||
|
SettingsController.toggleStartMinimized(checked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DividerType {
|
||||||
|
visible: !GC.isMobile()
|
||||||
|
}
|
||||||
|
|
||||||
LabelWithButtonType {
|
LabelWithButtonType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
text: qsTr("Language")
|
text: qsTr("Language")
|
||||||
descriptionText: LanguageModel.currentLanguageName
|
descriptionText: LanguageModel.currentLanguageName
|
||||||
|
|
|
@ -42,11 +42,10 @@ PageType {
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitcherType {
|
SwitcherType {
|
||||||
|
visible: !GC.isMobile()
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 16
|
Layout.margins: 16
|
||||||
Layout.bottomMargin: 16
|
|
||||||
Layout.leftMargin: 16
|
|
||||||
Layout.rightMargin: 16
|
|
||||||
|
|
||||||
text: qsTr("Auto connect")
|
text: qsTr("Auto connect")
|
||||||
descriptionText: qsTr("Connect to VPN on app start")
|
descriptionText: qsTr("Connect to VPN on app start")
|
||||||
|
@ -59,12 +58,13 @@ PageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DividerType {
|
||||||
|
visible: !GC.isMobile()
|
||||||
|
}
|
||||||
|
|
||||||
SwitcherType {
|
SwitcherType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 16
|
Layout.margins: 16
|
||||||
Layout.bottomMargin: 16
|
|
||||||
Layout.leftMargin: 16
|
|
||||||
Layout.rightMargin: 16
|
|
||||||
|
|
||||||
text: qsTr("Use AmneziaDNS if installed on the server")
|
text: qsTr("Use AmneziaDNS if installed on the server")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue