From a088f030ee979988958a31d69c3596dca6542bb7 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Thu, 25 Jul 2024 19:55:29 -0400 Subject: [PATCH 1/4] clean(client/cordova/apple): assorted cleanups --- .../NSNotification+Outline.swift | 2 + .../OutlineLib.xcodeproj/project.pbxproj | 41 +++--------- .../xcode/macos/Outline/Classes/AppDelegate.m | 2 +- .../Outline/Classes/CDVMacOsUrlHandler.swift | 65 ------------------- .../plugin/apple/src/OutlinePlugin.swift | 41 ++++++++++-- 5 files changed, 47 insertions(+), 104 deletions(-) delete mode 100644 client/src/cordova/apple/xcode/macos/Outline/Classes/CDVMacOsUrlHandler.swift diff --git a/client/src/cordova/apple/OutlineAppleLib/Sources/OutlineNotification/NSNotification+Outline.swift b/client/src/cordova/apple/OutlineAppleLib/Sources/OutlineNotification/NSNotification+Outline.swift index 72e168e277..4743eee912 100644 --- a/client/src/cordova/apple/OutlineAppleLib/Sources/OutlineNotification/NSNotification+Outline.swift +++ b/client/src/cordova/apple/OutlineAppleLib/Sources/OutlineNotification/NSNotification+Outline.swift @@ -19,12 +19,14 @@ import Foundation public extension Notification.Name { static let kAppQuit = Notification.Name("appQuit") + static let kHandleUrl = Notification.Name("handleUrl") static let kVpnConnected = Notification.Name("vpnConnected") static let kVpnDisconnected = Notification.Name("vpnDisconnected") } @objc public extension NSNotification { static let kAppQuit = Notification.Name.kAppQuit + static let kHandleUrl = Notification.Name.kHandleUrl static let kVpnConnected = Notification.Name.kVpnConnected static let kVpnDisconnected = Notification.Name.kVpnDisconnected } diff --git a/client/src/cordova/apple/OutlineLib/OutlineLib.xcodeproj/project.pbxproj b/client/src/cordova/apple/OutlineLib/OutlineLib.xcodeproj/project.pbxproj index 322fd5b3e0..3345a1c056 100644 --- a/client/src/cordova/apple/OutlineLib/OutlineLib.xcodeproj/project.pbxproj +++ b/client/src/cordova/apple/OutlineLib/OutlineLib.xcodeproj/project.pbxproj @@ -9,31 +9,15 @@ /* Begin PBXBuildFile section */ 522987052C4F273E009EE577 /* PacketTunnelProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 522987042C4F273E009EE577 /* PacketTunnelProvider.m */; }; 522987082C4F278E009EE577 /* CocoaLumberjack in Frameworks */ = {isa = PBXBuildFile; productRef = 522987072C4F278E009EE577 /* CocoaLumberjack */; }; - 5229870C2C4F2850009EE577 /* OutlineTunnel in Frameworks */ = {isa = PBXBuildFile; productRef = 5229870B2C4F2850009EE577 /* OutlineTunnel */; }; 5229870E2C4F2873009EE577 /* Tun2socks.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5229870D2C4F2873009EE577 /* Tun2socks.xcframework */; }; - 5229870F2C4F2873009EE577 /* Tun2socks.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5229870D2C4F2873009EE577 /* Tun2socks.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 52334EAF2B0D58AD00817E56 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52334EAE2B0D58AD00817E56 /* NetworkExtension.framework */; }; + 523E5C382C530C63001EE0A7 /* OutlineTunnel in Frameworks */ = {isa = PBXBuildFile; productRef = 523E5C372C530C63001EE0A7 /* OutlineTunnel */; }; /* End PBXBuildFile section */ -/* Begin PBXCopyFilesBuildPhase section */ - 522987102C4F2873009EE577 /* Embed Frameworks */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - 5229870F2C4F2873009EE577 /* Tun2socks.xcframework in Embed Frameworks */, - ); - name = "Embed Frameworks"; - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - /* Begin PBXFileReference section */ 522987032C4F273E009EE577 /* PacketTunnelProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PacketTunnelProvider.h; sourceTree = ""; }; 522987042C4F273E009EE577 /* PacketTunnelProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PacketTunnelProvider.m; sourceTree = ""; }; 5229870D2C4F2873009EE577 /* Tun2socks.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Tun2socks.xcframework; path = ../../../../output/build/apple/Tun2socks.xcframework; sourceTree = ""; }; - 522C98B62B0D673200E6E4A9 /* OutlineAppleLib */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = OutlineAppleLib; path = ../OutlineAppleLib; sourceTree = ""; }; 52334EAC2B0D58AD00817E56 /* VpnExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = VpnExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 52334EAE2B0D58AD00817E56 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; }; 52334EB32B0D58AD00817E56 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -48,7 +32,7 @@ 5229870E2C4F2873009EE577 /* Tun2socks.xcframework in Frameworks */, 522987082C4F278E009EE577 /* CocoaLumberjack in Frameworks */, 52334EAF2B0D58AD00817E56 /* NetworkExtension.framework in Frameworks */, - 5229870C2C4F2850009EE577 /* OutlineTunnel in Frameworks */, + 523E5C382C530C63001EE0A7 /* OutlineTunnel in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -67,7 +51,6 @@ 52334DE02B0D56D600817E56 = { isa = PBXGroup; children = ( - 522C98B62B0D673200E6E4A9 /* OutlineAppleLib */, 52334EB02B0D58AD00817E56 /* VpnExtension */, 52334EAD2B0D58AD00817E56 /* Frameworks */, 52334DEB2B0D56D600817E56 /* Products */, @@ -111,7 +94,6 @@ 52334EA82B0D58AD00817E56 /* Sources */, 52334EA92B0D58AD00817E56 /* Frameworks */, 52334EAA2B0D58AD00817E56 /* Resources */, - 522987102C4F2873009EE577 /* Embed Frameworks */, ); buildRules = ( ); @@ -121,7 +103,7 @@ name = VpnExtension; packageProductDependencies = ( 522987072C4F278E009EE577 /* CocoaLumberjack */, - 5229870B2C4F2850009EE577 /* OutlineTunnel */, + 523E5C372C530C63001EE0A7 /* OutlineTunnel */, ); productName = VpnExtension; productReference = 52334EAC2B0D58AD00817E56 /* VpnExtension.appex */; @@ -221,9 +203,8 @@ ); mainGroup = 52334DE02B0D56D600817E56; packageReferences = ( - 52334EFA2B0D619D00817E56 /* XCRemoteSwiftPackageReference "sentry-cocoa" */, - 5260B0682C4F114000CDF289 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */, 522987062C4F278E009EE577 /* XCRemoteSwiftPackageReference "CocoaLumberjack" */, + 523E5C362C530C63001EE0A7 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */, ); productRefGroup = 52334DEB2B0D56D600817E56 /* Products */; projectDirPath = ""; @@ -480,6 +461,10 @@ /* End XCConfigurationList section */ /* Begin XCLocalSwiftPackageReference section */ + 523E5C362C530C63001EE0A7 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../OutlineAppleLib; + }; 5260B0682C4F114000CDF289 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */ = { isa = XCLocalSwiftPackageReference; relativePath = ../OutlineAppleLib; @@ -495,14 +480,6 @@ minimumVersion = 3.8.5; }; }; - 52334EFA2B0D619D00817E56 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/getsentry/sentry-cocoa"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 8.0.0; - }; - }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -511,7 +488,7 @@ package = 522987062C4F278E009EE577 /* XCRemoteSwiftPackageReference "CocoaLumberjack" */; productName = CocoaLumberjack; }; - 5229870B2C4F2850009EE577 /* OutlineTunnel */ = { + 523E5C372C530C63001EE0A7 /* OutlineTunnel */ = { isa = XCSwiftPackageProductDependency; productName = OutlineTunnel; }; diff --git a/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m b/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m index e8665261d9..67a531f2ce 100644 --- a/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m +++ b/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m @@ -74,7 +74,7 @@ - (void)handleURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent { NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; [[NSNotificationCenter defaultCenter] - postNotificationName:CDVMacOsUrlHandler.kCDVHandleOpenURLNotification object:url]; + postNotificationName:NSNotification.kHandleUrl object:url]; if (!self.popover.isShown) { [self showPopover]; } diff --git a/client/src/cordova/apple/xcode/macos/Outline/Classes/CDVMacOsUrlHandler.swift b/client/src/cordova/apple/xcode/macos/Outline/Classes/CDVMacOsUrlHandler.swift deleted file mode 100644 index 8a7dc553d0..0000000000 --- a/client/src/cordova/apple/xcode/macos/Outline/Classes/CDVMacOsUrlHandler.swift +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2018 The Outline Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import Foundation - -// Class to handle URL interception in Cordova MacOS by surfacing the intercepted URL to JavaScript. -@objcMembers -class CDVMacOsUrlHandler: NSObject { - static let kCDVHandleOpenURLNotification = "CDVOpenURLNotification" - static let kHandleOpenUrlJsFormat = "document.addEventListener('deviceready',function(){" + - "if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}});" - static let kPageLoadWaitSecs = 0.5 - - private let webView: WebView - private var url: String? = nil - - init(_ webView: WebView) { - self.webView = webView - super.init() - - NotificationCenter.default.addObserver( - self, selector: #selector(self.handleOpenUrl), - name: NSNotification.Name(rawValue:CDVMacOsUrlHandler.kCDVHandleOpenURLNotification), - object: nil) - } - - deinit { - NotificationCenter.default.removeObserver(self) - } - - @objc private func handleOpenUrl(_ notification: Notification) { - guard let url = notification.object as? String else { - return NSLog("Received non-String object."); - } - self.url = url - NSLog("Intercepted URL."); - Thread.detachNewThreadSelector(#selector(self.sendUrlToJs), toTarget: self, with: nil); - } - - @objc func sendUrlToJs() { - guard let url = self.url else { - return - } - while (self.webView.isLoading) { - // Wait until the page is loaded in case the app launched with the intercepted URL. - Thread.sleep(forTimeInterval: CDVMacOsUrlHandler.kPageLoadWaitSecs) - } - let handleOpenUrlJs = String.init(format: CDVMacOsUrlHandler.kHandleOpenUrlJsFormat, url) - DispatchQueue.main.async { - self.webView.stringByEvaluatingJavaScript(from: handleOpenUrlJs) - self.url = nil - } - } -} diff --git a/client/src/cordova/plugin/apple/src/OutlinePlugin.swift b/client/src/cordova/plugin/apple/src/OutlinePlugin.swift index f6ff6ef9c5..5adb8eac4c 100644 --- a/client/src/cordova/plugin/apple/src/OutlinePlugin.swift +++ b/client/src/cordova/plugin/apple/src/OutlinePlugin.swift @@ -35,11 +35,6 @@ class OutlinePlugin: CDVPlugin { private var sentryLogger: OutlineSentryLogger! private var callbacks: [String: String]! -#if os(macOS) - // cordova-osx does not support URL interception. Until it does, we have version-controlled - // AppDelegate.m (intercept) and Outline-Info.plist (register protocol) to handle ss:// URLs. - private var urlHandler: CDVMacOsUrlHandler? -#endif #if os(macOS) || targetEnvironment(macCatalyst) private static let kPlatform = "macOS" @@ -56,7 +51,12 @@ class OutlinePlugin: CDVPlugin { OutlineVpn.shared.onVpnStatusChange(onVpnStatusChange) #if os(macOS) - self.urlHandler = CDVMacOsUrlHandler.init(self.webView) + // cordova-osx does not support URL interception. Until it does, we have version-controlled + // AppDelegate.m (intercept) and Outline-Info.plist (register protocol) to handle ss:// URLs. + NotificationCenter.default.addObserver( + self, selector: #selector(self.handleOpenUrl), + name: .kHandleUrl, + object: nil) #endif #if os(macOS) || targetEnvironment(macCatalyst) @@ -189,6 +189,35 @@ class OutlinePlugin: CDVPlugin { // MARK: Helpers +#if os(macOS) + @objc private func handleOpenUrl(_ notification: Notification) { + guard let url = notification.object as? String else { + return NSLog("Received non-String object."); + } + NSLog("Intercepted URL."); + guard let urlJson = try? JSONEncoder().encode(url), + let encodedUrl = String(data: urlJson, encoding: .utf8) else { + return NSLog("Failed to JS-encode intercepted URL") + } + DispatchQueue.global(qos: .background).async { + while (self.webView.isLoading) { + // Wait until the page is loaded in case the app launched with the intercepted URL. + Thread.sleep(forTimeInterval: 0.5) + } + DispatchQueue.main.async { + let handleOpenUrlJs = """ + document.addEventListener('deviceready', function() { + if (typeof handleOpenURL === 'function') { + handleOpenURL(\(encodedUrl)); + } + }); + """ + self.webView.stringByEvaluatingJavaScript(from: handleOpenUrlJs) + } + } + } +#endif + @objc private func stopVpnOnAppQuit() { if let activeTunnelId = OutlineVpn.shared.activeTunnelId { OutlineVpn.shared.stop(activeTunnelId) From 126921e2cd8aca9ea3133d022d653153667ede6c Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 26 Jul 2024 10:17:12 -0400 Subject: [PATCH 2/4] Update project --- .../apple/xcode/macos/Outline.xcodeproj/project.pbxproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj b/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj index 9dad9bf10f..9fad74e5a2 100644 --- a/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj +++ b/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj @@ -31,7 +31,6 @@ FC0799F72037543F00A1C822 /* OutlineLauncher.app in Copy OutlineLauncher */ = {isa = PBXBuildFile; fileRef = FC0799E62037532900A1C822 /* OutlineLauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; FC0799F92037545D00A1C822 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC0799F82037545D00A1C822 /* ServiceManagement.framework */; }; FC5FF9501F3E1FD40032A745 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC5FF9461F3E1E8B0032A745 /* NetworkExtension.framework */; }; - FC6E7F8E204DC1BE003CB365 /* CDVMacOsUrlHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC6E7F8D204DC1BE003CB365 /* CDVMacOsUrlHandler.swift */; }; FC7D56051F86969E00ABD5CA /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC7D56041F86969E00ABD5CA /* EventMonitor.swift */; }; /* End PBXBuildFile section */ @@ -133,7 +132,6 @@ FC0799F82037545D00A1C822 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; }; FC5FF9121F3E1D1B0032A745 /* Outline.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Outline.entitlements; sourceTree = ""; }; FC5FF9461F3E1E8B0032A745 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; }; - FC6E7F8D204DC1BE003CB365 /* CDVMacOsUrlHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDVMacOsUrlHandler.swift; sourceTree = ""; }; FC7D56041F86969E00ABD5CA /* EventMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -268,7 +266,6 @@ 70BD686818FFB0BF00A1EFCF /* Classes */ = { isa = PBXGroup; children = ( - FC6E7F8D204DC1BE003CB365 /* CDVMacOsUrlHandler.swift */, 70BD686918FFB0BF00A1EFCF /* AppDelegate.h */, 70BD686A18FFB0BF00A1EFCF /* AppDelegate.m */, FC7D56041F86969E00ABD5CA /* EventMonitor.swift */, @@ -494,7 +491,6 @@ files = ( 70BD683318FFB02D00A1EFCF /* main.m in Sources */, 70BD686D18FFB0BF00A1EFCF /* AppDelegate.m in Sources */, - FC6E7F8E204DC1BE003CB365 /* CDVMacOsUrlHandler.swift in Sources */, 70BD686E18FFB0BF00A1EFCF /* MainViewController.m in Sources */, 737FCE3329B34151A67331B4 /* OutlinePlugin.swift in Sources */, FC7D56051F86969E00ABD5CA /* EventMonitor.swift in Sources */, From aceaa769f6f874517fd3228f0a567455d2228249 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 26 Jul 2024 10:30:32 -0400 Subject: [PATCH 3/4] Remove EventMonitor --- .../macos/Outline.xcodeproj/project.pbxproj | 4 -- .../macos/Outline/Classes/EventMonitor.swift | 42 ------------------- 2 files changed, 46 deletions(-) delete mode 100644 client/src/cordova/apple/xcode/macos/Outline/Classes/EventMonitor.swift diff --git a/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj b/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj index 9fad74e5a2..a6a785111c 100644 --- a/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj +++ b/client/src/cordova/apple/xcode/macos/Outline.xcodeproj/project.pbxproj @@ -31,7 +31,6 @@ FC0799F72037543F00A1C822 /* OutlineLauncher.app in Copy OutlineLauncher */ = {isa = PBXBuildFile; fileRef = FC0799E62037532900A1C822 /* OutlineLauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; FC0799F92037545D00A1C822 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC0799F82037545D00A1C822 /* ServiceManagement.framework */; }; FC5FF9501F3E1FD40032A745 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC5FF9461F3E1E8B0032A745 /* NetworkExtension.framework */; }; - FC7D56051F86969E00ABD5CA /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC7D56041F86969E00ABD5CA /* EventMonitor.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -132,7 +131,6 @@ FC0799F82037545D00A1C822 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; }; FC5FF9121F3E1D1B0032A745 /* Outline.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Outline.entitlements; sourceTree = ""; }; FC5FF9461F3E1E8B0032A745 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; }; - FC7D56041F86969E00ABD5CA /* EventMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -268,7 +266,6 @@ children = ( 70BD686918FFB0BF00A1EFCF /* AppDelegate.h */, 70BD686A18FFB0BF00A1EFCF /* AppDelegate.m */, - FC7D56041F86969E00ABD5CA /* EventMonitor.swift */, 70BD686B18FFB0BF00A1EFCF /* MainViewController.h */, 70BD686C18FFB0BF00A1EFCF /* MainViewController.m */, ); @@ -493,7 +490,6 @@ 70BD686D18FFB0BF00A1EFCF /* AppDelegate.m in Sources */, 70BD686E18FFB0BF00A1EFCF /* MainViewController.m in Sources */, 737FCE3329B34151A67331B4 /* OutlinePlugin.swift in Sources */, - FC7D56051F86969E00ABD5CA /* EventMonitor.swift in Sources */, DBBA975361C94599B9DD3891 /* CDVClipboard.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/client/src/cordova/apple/xcode/macos/Outline/Classes/EventMonitor.swift b/client/src/cordova/apple/xcode/macos/Outline/Classes/EventMonitor.swift deleted file mode 100644 index 2068bed561..0000000000 --- a/client/src/cordova/apple/xcode/macos/Outline/Classes/EventMonitor.swift +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2018 The Outline Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -@objcMembers -public class EventMonitor: NSObject { - private var monitor: Any? - private let mask: NSEvent.EventTypeMask - private let handler: (NSEvent?) -> Void - - public init(mask: NSEvent.EventTypeMask, handler: @escaping (NSEvent?) -> Void) { - self.mask = mask - self.handler = handler - } - - deinit { - stop() - } - - public func start() { - stop() - self.monitor = NSEvent.addGlobalMonitorForEvents(matching: self.mask, handler: self.handler) - } - - public func stop() { - if self.monitor != nil { - NSEvent.removeMonitor(monitor!) - self.monitor = nil - } - } -} - From 90082b8449bddc25606838d65f629ef03e8f7df3 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 26 Jul 2024 11:05:14 -0400 Subject: [PATCH 4/4] Update AppDelegate --- .../cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m b/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m index 67a531f2ce..2e211c8212 100644 --- a/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m +++ b/client/src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m @@ -22,7 +22,6 @@ @interface AppDelegate() @property (strong, nonatomic) NSStatusItem *statusItem; @property (strong, nonatomic) NSPopover *popover; -@property (strong, nonatomic) EventMonitor *eventMonitor; @property bool isSystemShuttingDown; @end @@ -132,14 +131,12 @@ - (void)togglePopover { - (void)closePopover { [self.popover close]; - [self.eventMonitor stop]; } - (void)showPopover { [self.popover showRelativeToRect:self.statusItem.button.bounds ofView:self.statusItem.button preferredEdge:NSRectEdgeMinY]; - [self.eventMonitor start]; // Activate the application in order to focus the popover. [[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];