aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-10-22 17:47:01 +0200
committerAndrej Mihajlov <and@mullvad.net>2020-10-22 17:47:16 +0200
commitfcac43817a14bb968256d483e6ff2a15d3c78da0 (patch)
treebfaf49810e921fb6edd91c996e453a40a8f4ca65
parentUse NSWorkspace.openApplicationAtURL on macOS 10.15+ (diff)
downloadwireguard-apple-am/modernize-login-helper.tar.xz
wireguard-apple-am/modernize-login-helper.zip
Use NSApp.isHidden to determine if it has to show UI at openam/modernize-login-helper
-rw-r--r--WireGuard/WireGuard/UI/macOS/AppDelegate.swift9
-rw-r--r--WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift10
-rw-r--r--WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m9
3 files changed, 9 insertions, 19 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
index cb240230..0f62c6b4 100644
--- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
@@ -29,13 +29,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Logger.configureGlobal(tagged: "APP", withFilePath: FileManager.logFileURL?.path)
registerLoginItem(shouldLaunchAtLogin: true)
- var isLaunchedAtLogin = false
- if let appleEvent = NSAppleEventManager.shared().currentAppleEvent {
- isLaunchedAtLogin = LaunchedAtLoginDetector.isLaunchedAtLogin(openAppleEvent: appleEvent)
- }
+ let isOpenHidden = NSApp.isHidden
NSApp.mainMenu = MainMenu()
- setDockIconAndMainMenuVisibility(isVisible: !isLaunchedAtLogin)
+ setDockIconAndMainMenuVisibility(isVisible: !isOpenHidden)
TunnelsManager.create { [weak self] result in
guard let self = self else { return }
@@ -58,7 +55,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.tunnelsTracker = tunnelsTracker
self.statusItemController = statusItemController
- if !isLaunchedAtLogin {
+ if !isOpenHidden {
self.showManageTunnelsWindow(completion: nil)
}
}
diff --git a/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift
index 0d8e3d86..2cf08179 100644
--- a/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift
+++ b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift
@@ -6,12 +6,6 @@ import Cocoa
class LaunchedAtLoginDetector {
static let launchCode = "LaunchedByWireGuardLoginItemHelper"
- static func isLaunchedAtLogin(openAppleEvent: NSAppleEventDescriptor) -> Bool {
- guard isOpenEvent(openAppleEvent) else { return false }
- guard let propData = openAppleEvent.paramDescriptor(forKeyword: keyAEPropData) else { return false }
- return propData.stringValue == launchCode
- }
-
static func isReopenedByLoginItemHelper(reopenAppleEvent: NSAppleEventDescriptor) -> Bool {
guard isReopenEvent(reopenAppleEvent) else { return false }
guard let propData = reopenAppleEvent.paramDescriptor(forKeyword: keyAEPropData) else { return false }
@@ -19,10 +13,6 @@ class LaunchedAtLoginDetector {
}
}
-private func isOpenEvent(_ event: NSAppleEventDescriptor) -> Bool {
- return event.eventClass == kCoreEventClass && event.eventID == kAEOpenApplication
-}
-
private func isReopenEvent(_ event: NSAppleEventDescriptor) -> Bool {
return event.eventClass == kCoreEventClass && event.eventID == kAEReopenApplication
}
diff --git a/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m b/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m
index 11f1d91d..3f751ba2 100644
--- a/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m
+++ b/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m
@@ -13,8 +13,9 @@ int main(int argc, char *argv[])
if (@available(macOS 10.15, *)) {
NSURL *appURL = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:appId];
- NSWorkspaceOpenConfiguration *openConfiguration = [[NSWorkspaceOpenConfiguration alloc] init];
+ NSWorkspaceOpenConfiguration *openConfiguration = [NSWorkspaceOpenConfiguration configuration];
openConfiguration.activates = NO;
+ openConfiguration.hides = YES;
openConfiguration.appleEvent = paramDescriptor;
// Create condition to block the execution until `openApplicationAtURL:configuration:completionHandler:`
@@ -25,8 +26,10 @@ int main(int argc, char *argv[])
}];
[condition wait];
} else {
- [NSWorkspace.sharedWorkspace launchAppWithBundleIdentifier:appId options:NSWorkspaceLaunchWithoutActivation
- additionalEventParamDescriptor:paramDescriptor launchIdentifier:nil];
+ [NSWorkspace.sharedWorkspace launchAppWithBundleIdentifier:appId
+ options:NSWorkspaceLaunchWithoutActivation | NSWorkspaceLaunchAndHide
+ additionalEventParamDescriptor:paramDescriptor
+ launchIdentifier:nil];
}
return 0;