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
|
||||
// if (m_parser.isSet("a")) m_uiLogic->showOnStartup();
|
||||
// else emit m_uiLogic->show();
|
||||
// #else
|
||||
// m_uiLogic->showOnStartup();
|
||||
// #endif
|
||||
#ifdef Q_OS_WIN
|
||||
if (m_parser.isSet("a"))
|
||||
m_pageController->showOnStartup();
|
||||
else
|
||||
emit m_pageController->raiseMainWindow();
|
||||
#else
|
||||
m_pageController->showOnStartup();
|
||||
#endif
|
||||
|
||||
// TODO - fix
|
||||
// TODO - fix
|
||||
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
|
||||
if (isPrimary()) {
|
||||
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_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_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_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_installController.reset(new InstallController(m_serversModel, m_containersModel, m_settings));
|
||||
|
|
|
@ -5,9 +5,13 @@
|
|||
#include "../../platforms/android/androidutils.h"
|
||||
#include <QJniObject>
|
||||
#endif
|
||||
#if defined Q_OS_MAC
|
||||
#include "ui/macos_util.h"
|
||||
#endif
|
||||
|
||||
PageController::PageController(const QSharedPointer<ServersModel> &serversModel, QObject *parent)
|
||||
: QObject(parent), m_serversModel(serversModel)
|
||||
PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const std::shared_ptr<Settings> &settings, QObject *parent)
|
||||
: QObject(parent), m_serversModel(serversModel), m_settings(settings)
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
// Change color of navigation and status bar's
|
||||
|
@ -23,6 +27,9 @@ PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
|
|||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
connect(this, &PageController::raiseMainWindow, []() { setDockIconVisible(true); });
|
||||
connect(this, &PageController::hideMainWindow, []() { setDockIconVisible(false); });
|
||||
}
|
||||
|
||||
QString PageController::getInitialPage()
|
||||
|
@ -88,3 +95,16 @@ void PageController::updateNavigationBarColor(const int color)
|
|||
});
|
||||
#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
|
||||
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:
|
||||
QString getInitialPage();
|
||||
|
@ -75,6 +76,8 @@ public slots:
|
|||
unsigned int getInitialPageNavigationBarColor();
|
||||
void updateNavigationBarColor(const int color);
|
||||
|
||||
void showOnStartup();
|
||||
|
||||
signals:
|
||||
void goToPageHome();
|
||||
void goToPageSettings();
|
||||
|
@ -100,6 +103,8 @@ signals:
|
|||
|
||||
private:
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
};
|
||||
|
||||
#endif // PAGECONTROLLER_H
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "fileUtilites.h"
|
||||
#include "logger.h"
|
||||
#include "ui/qautostart.h"
|
||||
#include "version.h"
|
||||
|
||||
SettingsController::SettingsController(const QSharedPointer<ServersModel> &serversModel,
|
||||
|
@ -137,3 +138,23 @@ void SettingsController::toggleAutoConnect(bool 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();
|
||||
void toggleAutoConnect(bool enable);
|
||||
|
||||
bool isAutoStartEnabled();
|
||||
void toggleAutoStart(bool enable);
|
||||
|
||||
bool isStartMinimizedEnabled();
|
||||
void toggleStartMinimized(bool enable);
|
||||
|
||||
signals:
|
||||
void primaryDnsChanged();
|
||||
void secondaryDnsChanged();
|
||||
|
|
|
@ -1,60 +1,86 @@
|
|||
#include <QMainWindow>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include "macos_util.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QProcess>
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#import <Foundation/Foundation.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)
|
||||
{
|
||||
if (!visible) {
|
||||
[NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
if (visible) {
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
} else {
|
||||
[NSApp setActivationPolicy: NSApplicationActivationPolicyRegular];
|
||||
TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
|
||||
}
|
||||
}
|
||||
|
||||
//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
|
||||
@interface ButtonPasser : NSObject{
|
||||
// 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
|
||||
@interface ButtonPasser : NSObject {
|
||||
}
|
||||
@property(readwrite) QMainWindow* window;
|
||||
@property (readwrite) QMainWindow *window;
|
||||
+ (void)closeButtonAction:(id)sender;
|
||||
- (void)zoomButtonAction:(id)sender;
|
||||
@end
|
||||
|
||||
@implementation ButtonPasser{
|
||||
@implementation ButtonPasser {
|
||||
}
|
||||
+ (void)closeButtonAction:(id)sender
|
||||
{
|
||||
Q_UNUSED(sender);
|
||||
ProcessSerialNumber pn;
|
||||
GetFrontProcess (&pn);
|
||||
ShowHideProcess(&pn,false);
|
||||
GetFrontProcess(&pn);
|
||||
ShowHideProcess(&pn, false);
|
||||
}
|
||||
- (void)zoomButtonAction:(id)sender
|
||||
{
|
||||
Q_UNUSED(sender);
|
||||
if (0 == self.window) return;
|
||||
if (self.window->isMaximized()) self.window->showNormal();
|
||||
else self.window->showMaximized();
|
||||
if (0 == self.window)
|
||||
return;
|
||||
if (self.window->isMaximized())
|
||||
self.window->showNormal();
|
||||
else
|
||||
self.window->showMaximized();
|
||||
}
|
||||
@end
|
||||
|
||||
void fixWidget(QWidget *widget)
|
||||
{
|
||||
NSView *view = (NSView *)widget->winId();
|
||||
if (0 == view) return;
|
||||
if (0 == view)
|
||||
return;
|
||||
NSWindow *window = view.window;
|
||||
if (0 == window) return;
|
||||
if (0 == window)
|
||||
return;
|
||||
|
||||
//override the action of close button
|
||||
//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
|
||||
// NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
|
||||
// [closeButton setTarget:[ButtonPasser class]];
|
||||
// [closeButton setAction:@selector(closeButtonAction:)];
|
||||
// override the action of close button
|
||||
// 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
|
||||
// NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
|
||||
// [closeButton setTarget:[ButtonPasser class]];
|
||||
// [closeButton setAction:@selector(closeButtonAction:)];
|
||||
|
||||
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
||||
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
||||
|
|
|
@ -43,9 +43,50 @@ PageType {
|
|||
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 {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 16
|
||||
|
||||
text: qsTr("Language")
|
||||
descriptionText: LanguageModel.currentLanguageName
|
||||
|
|
|
@ -42,11 +42,10 @@ PageType {
|
|||
}
|
||||
|
||||
SwitcherType {
|
||||
visible: !GC.isMobile()
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 16
|
||||
Layout.bottomMargin: 16
|
||||
Layout.leftMargin: 16
|
||||
Layout.rightMargin: 16
|
||||
Layout.margins: 16
|
||||
|
||||
text: qsTr("Auto connect")
|
||||
descriptionText: qsTr("Connect to VPN on app start")
|
||||
|
@ -59,12 +58,13 @@ PageType {
|
|||
}
|
||||
}
|
||||
|
||||
DividerType {
|
||||
visible: !GC.isMobile()
|
||||
}
|
||||
|
||||
SwitcherType {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 16
|
||||
Layout.bottomMargin: 16
|
||||
Layout.leftMargin: 16
|
||||
Layout.rightMargin: 16
|
||||
Layout.margins: 16
|
||||
|
||||
text: qsTr("Use AmneziaDNS if installed on the server")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue