Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client/cordova/apple): assorted cleanups #2071

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
522987042C4F273E009EE577 /* PacketTunnelProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PacketTunnelProvider.m; sourceTree = "<group>"; };
5229870D2C4F2873009EE577 /* Tun2socks.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Tun2socks.xcframework; path = ../../../../output/build/apple/Tun2socks.xcframework; sourceTree = "<group>"; };
522C98B62B0D673200E6E4A9 /* OutlineAppleLib */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = OutlineAppleLib; path = ../OutlineAppleLib; sourceTree = "<group>"; };
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 = "<group>"; };
Expand All @@ -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;
};
Expand All @@ -67,7 +51,6 @@
52334DE02B0D56D600817E56 = {
isa = PBXGroup;
children = (
522C98B62B0D673200E6E4A9 /* OutlineAppleLib */,
52334EB02B0D58AD00817E56 /* VpnExtension */,
52334EAD2B0D58AD00817E56 /* Frameworks */,
52334DEB2B0D56D600817E56 /* Products */,
Expand Down Expand Up @@ -111,7 +94,6 @@
52334EA82B0D58AD00817E56 /* Sources */,
52334EA92B0D58AD00817E56 /* Frameworks */,
52334EAA2B0D58AD00817E56 /* Resources */,
522987102C4F2873009EE577 /* Embed Frameworks */,
);
buildRules = (
);
Expand All @@ -121,7 +103,7 @@
name = VpnExtension;
packageProductDependencies = (
522987072C4F278E009EE577 /* CocoaLumberjack */,
5229870B2C4F2850009EE577 /* OutlineTunnel */,
523E5C372C530C63001EE0A7 /* OutlineTunnel */,
);
productName = VpnExtension;
productReference = 52334EAC2B0D58AD00817E56 /* VpnExtension.appex */;
Expand Down Expand Up @@ -221,9 +203,8 @@
);
mainGroup = 52334DE02B0D56D600817E56;
packageReferences = (
52334EFA2B0D619D00817E56 /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
5260B0682C4F114000CDF289 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */,
522987062C4F278E009EE577 /* XCRemoteSwiftPackageReference "CocoaLumberjack" */,
523E5C362C530C63001EE0A7 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */,
);
productRefGroup = 52334DEB2B0D56D600817E56 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -480,6 +461,10 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
523E5C362C530C63001EE0A7 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../OutlineAppleLib;
};
5260B0682C4F114000CDF289 /* XCLocalSwiftPackageReference "../OutlineAppleLib" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../OutlineAppleLib;
Expand All @@ -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 */
Expand All @@ -511,7 +488,7 @@
package = 522987062C4F278E009EE577 /* XCRemoteSwiftPackageReference "CocoaLumberjack" */;
productName = CocoaLumberjack;
};
5229870B2C4F2850009EE577 /* OutlineTunnel */ = {
523E5C372C530C63001EE0A7 /* OutlineTunnel */ = {
isa = XCSwiftPackageProductDependency;
productName = OutlineTunnel;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +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 */; };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aargh, I forgot to copy the project changes back into the rsync'd file. Hopefully we won't need much of that in the future!

This should fix the build.

FC7D56051F86969E00ABD5CA /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC7D56041F86969E00ABD5CA /* EventMonitor.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -133,8 +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 = "<group>"; };
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 = "<group>"; };
FC7D56041F86969E00ABD5CA /* EventMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -268,10 +264,8 @@
70BD686818FFB0BF00A1EFCF /* Classes */ = {
isa = PBXGroup;
children = (
FC6E7F8D204DC1BE003CB365 /* CDVMacOsUrlHandler.swift */,
70BD686918FFB0BF00A1EFCF /* AppDelegate.h */,
70BD686A18FFB0BF00A1EFCF /* AppDelegate.m */,
FC7D56041F86969E00ABD5CA /* EventMonitor.swift */,
70BD686B18FFB0BF00A1EFCF /* MainViewController.h */,
70BD686C18FFB0BF00A1EFCF /* MainViewController.m */,
);
Expand Down Expand Up @@ -494,10 +488,8 @@
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 */,
DBBA975361C94599B9DD3891 /* CDVClipboard.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -74,7 +73,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];
}
Expand Down Expand Up @@ -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];
Expand Down

This file was deleted.

This file was deleted.

41 changes: 35 additions & 6 deletions client/src/cordova/plugin/apple/src/OutlinePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading