aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-05-20 14:04:47 +0530
committerRoopesh Chander <roop@roopc.net>2019-05-20 16:42:28 +0530
commit40b1f0bac804985d1fceaef9422eb4c5f0ad204e (patch)
tree4308b55c1441dd6a636cb40a050a78710e0abdaf /WireGuard
parentmacOS: Login item: Get helper app version from xcconfig (diff)
downloadwireguard-apple-40b1f0bac804985d1fceaef9422eb4c5f0ad204e.tar.xz
wireguard-apple-40b1f0bac804985d1fceaef9422eb4c5f0ad204e.zip
macOS: Don't show manage window when launched at login
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard.xcodeproj/project.pbxproj4
-rw-r--r--WireGuard/WireGuard/UI/macOS/AppDelegate.swift13
-rw-r--r--WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift21
-rw-r--r--WireGuard/WireGuard/UI/macOS/LoginItemHelper/Info.plist2
-rw-r--r--WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m11
5 files changed, 44 insertions, 7 deletions
diff --git a/WireGuard/WireGuard.xcodeproj/project.pbxproj b/WireGuard/WireGuard.xcodeproj/project.pbxproj
index c59bbb1..ead1556 100644
--- a/WireGuard/WireGuard.xcodeproj/project.pbxproj
+++ b/WireGuard/WireGuard.xcodeproj/project.pbxproj
@@ -68,6 +68,7 @@
6F628C3D217F09E9003482A3 /* TunnelViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F628C3C217F09E9003482A3 /* TunnelViewModel.swift */; };
6F628C3F217F3413003482A3 /* DNSServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F628C3E217F3413003482A3 /* DNSServer.swift */; };
6F628C41217F47DB003482A3 /* TunnelDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F628C40217F47DB003482A3 /* TunnelDetailTableViewController.swift */; };
+ 6F6483E7229293300075BA15 /* LaunchedAtLoginDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F6483E6229293300075BA15 /* LaunchedAtLoginDetector.swift */; };
6F6899A62180447E0012E523 /* x25519.c in Sources */ = {isa = PBXBuildFile; fileRef = 6F6899A52180447E0012E523 /* x25519.c */; };
6F6899A8218044FC0012E523 /* Curve25519.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F6899A7218044FC0012E523 /* Curve25519.swift */; };
6F693A562179E556008551C1 /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F693A552179E556008551C1 /* Endpoint.swift */; };
@@ -320,6 +321,7 @@
6F628C3C217F09E9003482A3 /* TunnelViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelViewModel.swift; sourceTree = "<group>"; };
6F628C3E217F3413003482A3 /* DNSServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSServer.swift; sourceTree = "<group>"; };
6F628C40217F47DB003482A3 /* TunnelDetailTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TunnelDetailTableViewController.swift; sourceTree = "<group>"; };
+ 6F6483E6229293300075BA15 /* LaunchedAtLoginDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchedAtLoginDetector.swift; sourceTree = "<group>"; };
6F689999218043390012E523 /* WireGuard-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WireGuard-Bridging-Header.h"; sourceTree = "<group>"; };
6F6899A42180447E0012E523 /* x25519.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x25519.h; sourceTree = "<group>"; };
6F6899A52180447E0012E523 /* x25519.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x25519.c; sourceTree = "<group>"; };
@@ -638,6 +640,7 @@
6FBA104121D6BC210051C35F /* ErrorPresenter.swift */,
6FCD99AE21E0EA1700BA4C82 /* ImportPanelPresenter.swift */,
6F2449E7226587B80047B9E9 /* MacAppStoreUpdateDetector.swift */,
+ 6F6483E6229293300075BA15 /* LaunchedAtLoginDetector.swift */,
6FB1BD6121D2607E00A991BF /* Assets.xcassets */,
6FB1BD6621D2607E00A991BF /* Info.plist */,
6FB1BD6721D2607E00A991BF /* WireGuard.entitlements */,
@@ -1295,6 +1298,7 @@
6F3E02E9228000F6001FE7E3 /* MainMenu.swift in Sources */,
5F52D0BF21E3788900283CEA /* NSColor+Hex.swift in Sources */,
6FB1BDBE21D50F0200A991BF /* Logger.swift in Sources */,
+ 6F6483E7229293300075BA15 /* LaunchedAtLoginDetector.swift in Sources */,
6FB1BDBF21D50F0200A991BF /* TunnelConfiguration+WgQuickConfig.swift in Sources */,
6FADE96C2254B8C300B838A4 /* UnusableTunnelDetailViewController.swift in Sources */,
6FFACD2021E4D8D500E9A2A5 /* ParseError+WireGuardAppError.swift in Sources */,
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
index a68e08a..0860166 100644
--- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
@@ -18,7 +18,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Logger.configureGlobal(tagged: "APP", withFilePath: FileManager.logFileURL?.path)
registerLoginItem(shouldLaunchAtLogin: true)
- NSApp.setActivationPolicy(.regular)
+ var isLaunchedAtLogin = false
+ if let appleEvent = NSAppleEventManager.shared().currentAppleEvent {
+ isLaunchedAtLogin = LaunchedAtLoginDetector.isLaunchedAtLogin(openAppleEvent: appleEvent)
+ }
+
+ if !isLaunchedAtLogin {
+ NSApp.setActivationPolicy(.regular)
+ }
NSApp.mainMenu = MainMenu()
TunnelsManager.create { [weak self] result in
@@ -42,7 +49,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.tunnelsTracker = tunnelsTracker
self.statusItemController = statusItemController
- self.showManageTunnelsWindow(completion: nil)
+ if !isLaunchedAtLogin {
+ self.showManageTunnelsWindow(completion: nil)
+ }
}
}
}
diff --git a/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift
new file mode 100644
index 0000000..53a4dae
--- /dev/null
+++ b/WireGuard/WireGuard/UI/macOS/LaunchedAtLoginDetector.swift
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+class LaunchedAtLoginDetector {
+ static func isLaunchedAtLogin(openAppleEvent: NSAppleEventDescriptor) -> Bool {
+ let launchCode = "LaunchedByWireGuardLoginItemHelper"
+ guard isOpenEvent(openAppleEvent) else { return false }
+ guard let propData = openAppleEvent.paramDescriptor(forKeyword: keyAEPropData) else { return false }
+ return propData.stringValue == launchCode
+ }
+}
+
+private func isOpenEvent(_ event: NSAppleEventDescriptor) -> Bool {
+ if let eventClassDescriptor = event.attributeDescriptor(forKeyword: keyEventClassAttr),
+ let eventIdDescriptor = event.attributeDescriptor(forKeyword: keyEventIDAttr) {
+ return eventClassDescriptor.typeCodeValue == kCoreEventClass && eventIdDescriptor.typeCodeValue == kAEOpenApplication
+ }
+ return false
+}
diff --git a/WireGuard/WireGuard/UI/macOS/LoginItemHelper/Info.plist b/WireGuard/WireGuard/UI/macOS/LoginItemHelper/Info.plist
index f7bcf8d..7ddff91 100644
--- a/WireGuard/WireGuard/UI/macOS/LoginItemHelper/Info.plist
+++ b/WireGuard/WireGuard/UI/macOS/LoginItemHelper/Info.plist
@@ -30,5 +30,7 @@
<string>NSApplication</string>
<key>LSBackgroundOnly</key>
<true/>
+ <key>com.wireguard.macos.app_id</key>
+ <string>$(APP_ID_MACOS)</string>
</dict>
</plist>
diff --git a/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m b/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m
index 51b73fd..1010b49 100644
--- a/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m
+++ b/WireGuard/WireGuard/UI/macOS/LoginItemHelper/main.m
@@ -5,12 +5,13 @@
int main(int argc, char *argv[])
{
- NSURL *bundleURL = [NSBundle.mainBundle bundleURL];
+ NSString *appIdInfoDictionaryKey = @"com.wireguard.macos.app_id";
+ NSString *appId = [NSBundle.mainBundle objectForInfoDictionaryKey:appIdInfoDictionaryKey];
- // From <path>/WireGuard.app/Contents/Library/LoginItems/WireGuardLoginItemHelper.app, derive <path>/WireGuard.app
- for (int i = 0; i < 4; ++i)
- bundleURL = [bundleURL URLByDeletingLastPathComponent];
+ NSString *launchCode = @"LaunchedByWireGuardLoginItemHelper";
+ NSAppleEventDescriptor *paramDescriptor = [NSAppleEventDescriptor descriptorWithString:launchCode];
- [NSWorkspace.sharedWorkspace launchApplication:[bundleURL path]];
+ [NSWorkspace.sharedWorkspace launchAppWithBundleIdentifier:appId options:NSWorkspaceLaunchWithoutActivation
+ additionalEventParamDescriptor:paramDescriptor launchIdentifier:NULL];
return 0;
}