|
1 | 1 | #include "ImmutableMac.h"
|
| 2 | + |
| 3 | +#include "Engine/GameEngine.h" |
| 4 | + |
2 | 5 | #include "Immutable/ImmutablePassport.h"
|
3 | 6 | #include "Immutable/ImmutableSubsystem.h"
|
4 |
| -#include "Engine/GameEngine.h" |
5 | 7 |
|
6 | 8 | #if WITH_EDITOR
|
7 | 9 | #include "Editor.h"
|
8 | 10 | #endif
|
9 | 11 |
|
10 | 12 | ASWebAuthenticationSession *_authSession;
|
11 | 13 |
|
| 14 | +// Remove the global automation mode variable |
| 15 | +static NSString* _pendingRedirectScheme = nil; |
| 16 | + |
12 | 17 | @implementation ImmutableMac
|
13 | 18 |
|
14 | 19 | - (instancetype)init {
|
@@ -67,6 +72,13 @@ ASWebAuthenticationSession *_authSession;
|
67 | 72 | }
|
68 | 73 |
|
69 | 74 | - (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri {
|
| 75 | + // For automation, use the browser-based method |
| 76 | + if (GIsAutomationTesting) { |
| 77 | + NSLog(@"Using automation mode for authentication (GIsAutomationTesting is true)"); |
| 78 | + [self launchUrlInBrowser:url forRedirectUri:redirectUri]; |
| 79 | + return; |
| 80 | + } |
| 81 | + |
70 | 82 | if (@available(macOS 10.15, *)) {
|
71 | 83 | NSURL *URL =
|
72 | 84 | [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
|
@@ -104,6 +116,43 @@ ASWebAuthenticationSession *_authSession;
|
104 | 116 | }
|
105 | 117 | }
|
106 | 118 |
|
| 119 | +- (void)launchUrlInBrowser:(const char *)url forRedirectUri:(const char *)redirectUri { |
| 120 | + // Add redundant check to ensure this only runs for automated testing |
| 121 | + if (!GIsAutomationTesting) { |
| 122 | + return; |
| 123 | + } |
| 124 | + |
| 125 | + // Create URL object |
| 126 | + NSURL *URL = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]]; |
| 127 | + |
| 128 | + // Extract the callback scheme from redirect URI |
| 129 | + NSString *redirectUriString = [[NSString alloc] initWithUTF8String:redirectUri]; |
| 130 | + NSString *callbackURLScheme = [[redirectUriString componentsSeparatedByString:@":"] objectAtIndex:0]; |
| 131 | + |
| 132 | + // Store the redirect scheme for use when handling the callback |
| 133 | + _pendingRedirectScheme = callbackURLScheme; |
| 134 | + |
| 135 | + // Register for custom URL scheme notifications (will need to be implemented in AppDelegate) |
| 136 | + [[NSNotificationCenter defaultCenter] addObserverForName:@"ImmutableCustomURLSchemeCallback" |
| 137 | + object:nil |
| 138 | + queue:[NSOperationQueue mainQueue] |
| 139 | + usingBlock:^(NSNotification *notification) { |
| 140 | + if (notification.userInfo) { |
| 141 | + NSString *callbackURLString = notification.userInfo[@"url"]; |
| 142 | + if (callbackURLString) { |
| 143 | + UImmutablePassport* passport = [ImmutableMac getPassport]; |
| 144 | + if (passport) { |
| 145 | + passport->HandleDeepLink(callbackURLString); |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + }]; |
| 150 | + |
| 151 | + // Open URL in default browser |
| 152 | + [[NSWorkspace sharedWorkspace] openURL:URL]; |
| 153 | + NSLog(@"Opened URL in browser for automation: %@", URL); |
| 154 | +} |
| 155 | + |
107 | 156 | - (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:
|
108 | 157 | (ASWebAuthenticationSession *)session API_AVAILABLE(macos(10.15)) {
|
109 | 158 | return [[[NSApplication sharedApplication] windows] firstObject];
|
|
0 commit comments