|
7 | 7 | #include "Editor.h"
|
8 | 8 | #endif
|
9 | 9 |
|
| 10 | +#import <AppKit/NSWorkspace.h> |
| 11 | + |
10 | 12 | ASWebAuthenticationSession *_authSession;
|
11 | 13 |
|
| 14 | +// Global variable to track if we're in automation mode |
| 15 | +static BOOL g_isInAutomationMode = NO; |
| 16 | +static NSString* _pendingRedirectScheme = nil; |
| 17 | + |
12 | 18 | @implementation ImmutableMac
|
13 | 19 |
|
14 | 20 | - (instancetype)init {
|
@@ -67,6 +73,13 @@ ASWebAuthenticationSession *_authSession;
|
67 | 73 | }
|
68 | 74 |
|
69 | 75 | - (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri {
|
| 76 | + // For automation, use the browser-based method |
| 77 | + if (g_isInAutomationMode) { |
| 78 | + NSLog(@"Using automation mode for authentication"); |
| 79 | + [self launchUrlInBrowser:url forRedirectUri:redirectUri forAutomation:YES]; |
| 80 | + return; |
| 81 | + } |
| 82 | + |
70 | 83 | if (@available(macOS 10.15, *)) {
|
71 | 84 | NSURL *URL =
|
72 | 85 | [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
|
@@ -104,9 +117,56 @@ ASWebAuthenticationSession *_authSession;
|
104 | 117 | }
|
105 | 118 | }
|
106 | 119 |
|
| 120 | +- (void)launchUrlInBrowser:(const char *)url forRedirectUri:(const char *)redirectUri forAutomation:(BOOL)forAutomation { |
| 121 | + // Set automation mode |
| 122 | + g_isInAutomationMode = forAutomation; |
| 123 | + NSLog(@"Setting automation mode: %@", g_isInAutomationMode ? @"YES" : @"NO"); |
| 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];
|
110 | 159 | }
|
111 | 160 |
|
| 161 | +// Helper method to enable automation mode |
| 162 | ++ (void)setAutomationMode:(BOOL)enabled { |
| 163 | + g_isInAutomationMode = enabled; |
| 164 | + NSLog(@"setAutomationMode called with: %@", enabled ? @"YES" : @"NO"); |
| 165 | +} |
| 166 | + |
| 167 | +// Helper method to check if we're in automation mode |
| 168 | ++ (BOOL)isInAutomationMode { |
| 169 | + return g_isInAutomationMode; |
| 170 | +} |
| 171 | + |
112 | 172 | @end
|
0 commit comments