From c41be2a29d0798fb0fd68ef1727d3a849561e1ae Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Fri, 28 Dec 2018 00:33:31 +0530 Subject: [PATCH] Make app groups work on both iOS and macOS --- WireGuard/Shared/FileManager+Extension.swift | 7 ++++++- WireGuard/WireGuard.xcodeproj/project.pbxproj | 8 ++++++++ WireGuard/WireGuard/UI/iOS/Info.plist | 2 +- WireGuard/WireGuard/UI/macOS/Info.plist | 2 ++ WireGuard/WireGuard/UI/macOS/WireGuard.entitlements | 4 ++++ WireGuard/WireGuardNetworkExtension/Info.plist | 4 +++- .../WireGuardNetworkExtension_macOS.entitlements | 8 ++++++-- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/WireGuard/Shared/FileManager+Extension.swift b/WireGuard/Shared/FileManager+Extension.swift index 5873f3b..d98cd0a 100644 --- a/WireGuard/Shared/FileManager+Extension.swift +++ b/WireGuard/Shared/FileManager+Extension.swift @@ -6,7 +6,12 @@ import os.log extension FileManager { private static var sharedFolderURL: URL? { - guard let appGroupId = Bundle.main.object(forInfoDictionaryKey: "com.wireguard.ios.app_group_id") as? String else { + #if os(iOS) + let appGroupIdInfoDictionaryKey = "com.wireguard.ios.app_group_id" + #elseif os(OSX) + let appGroupIdInfoDictionaryKey = "com.wireguard.macos.app_group_id" + #endif + guard let appGroupId = Bundle.main.object(forInfoDictionaryKey: appGroupIdInfoDictionaryKey) as? String else { os_log("Cannot obtain app group ID from bundle", log: OSLog.default, type: .error) return nil } diff --git a/WireGuard/WireGuard.xcodeproj/project.pbxproj b/WireGuard/WireGuard.xcodeproj/project.pbxproj index eab1a2a..c5c5486 100644 --- a/WireGuard/WireGuard.xcodeproj/project.pbxproj +++ b/WireGuard/WireGuard.xcodeproj/project.pbxproj @@ -689,6 +689,9 @@ 6FB1BD5C21D2607A00A991BF = { CreatedOnToolsVersion = 10.1; SystemCapabilities = { + com.apple.ApplicationGroups.Mac = { + enabled = 1; + }; com.apple.NetworkExtensions = { enabled = 1; }; @@ -696,6 +699,11 @@ }; 6FB1BD9021D4BFE600A991BF = { CreatedOnToolsVersion = 10.1; + SystemCapabilities = { + com.apple.ApplicationGroups.Mac = { + enabled = 1; + }; + }; }; 6FDEF7DD21846BC100D8FBF6 = { CreatedOnToolsVersion = 10.0; diff --git a/WireGuard/WireGuard/UI/iOS/Info.plist b/WireGuard/WireGuard/UI/iOS/Info.plist index 9b7bc07..2a943eb 100644 --- a/WireGuard/WireGuard/UI/iOS/Info.plist +++ b/WireGuard/WireGuard/UI/iOS/Info.plist @@ -123,6 +123,6 @@ com.wireguard.ios.app_group_id - group.$(APP_ID_IOS) + group.$(APP_ID_IOS) diff --git a/WireGuard/WireGuard/UI/macOS/Info.plist b/WireGuard/WireGuard/UI/macOS/Info.plist index 01b6caa..0c09003 100644 --- a/WireGuard/WireGuard/UI/macOS/Info.plist +++ b/WireGuard/WireGuard/UI/macOS/Info.plist @@ -28,5 +28,7 @@ MainMenu NSPrincipalClass NSApplication + com.wireguard.macos.app_group_id + $(DEVELOPMENT_TEAM).group.$(APP_ID_MACOS) diff --git a/WireGuard/WireGuard/UI/macOS/WireGuard.entitlements b/WireGuard/WireGuard/UI/macOS/WireGuard.entitlements index 90b496c..fd5bd28 100644 --- a/WireGuard/WireGuard/UI/macOS/WireGuard.entitlements +++ b/WireGuard/WireGuard/UI/macOS/WireGuard.entitlements @@ -8,6 +8,10 @@ com.apple.security.app-sandbox + com.apple.security.application-groups + + $(DEVELOPMENT_TEAM).group.$(APP_ID_MACOS) + com.apple.security.files.user-selected.read-only diff --git a/WireGuard/WireGuardNetworkExtension/Info.plist b/WireGuard/WireGuardNetworkExtension/Info.plist index 1075c53..0b32ba2 100644 --- a/WireGuard/WireGuardNetworkExtension/Info.plist +++ b/WireGuard/WireGuardNetworkExtension/Info.plist @@ -30,6 +30,8 @@ $(PRODUCT_MODULE_NAME).PacketTunnelProvider com.wireguard.ios.app_group_id - group.$(APP_ID_IOS) + group.$(APP_ID_IOS) + com.wireguard.macos.app_group_id + $(DEVELOPMENT_TEAM).group.$(APP_ID_MACOS) diff --git a/WireGuard/WireGuardNetworkExtension/WireGuardNetworkExtension_macOS.entitlements b/WireGuard/WireGuardNetworkExtension/WireGuardNetworkExtension_macOS.entitlements index 3a24a44..a54ac34 100644 --- a/WireGuard/WireGuardNetworkExtension/WireGuardNetworkExtension_macOS.entitlements +++ b/WireGuard/WireGuardNetworkExtension/WireGuardNetworkExtension_macOS.entitlements @@ -2,11 +2,15 @@ - com.apple.security.app-sandbox - com.apple.developer.networking.networkextension packet-tunnel-provider + com.apple.security.app-sandbox + + com.apple.security.application-groups + + $(DEVELOPMENT_TEAM).group.$(APP_ID_MACOS) +