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
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue