Skip to content

Commit

Permalink
Provide option to not blindly foreground app's lastWindow from deepLi…
Browse files Browse the repository at this point in the history
…nks (microsoft#1355)

Messenger Desktop is a multi-window application (chat, calling, settings, …) and we maintain the various windows with a windowNativeModule which allows JS interaction.

When receiving deep-links from other apps we don’t want to necessary re-open the lastWindow open as the deep-link might contain information about a particular scenario (open login page, start a call). Hence, we need to disable this behavior app wide and use our windowNativeModule to forward the specific window related to the deep link.

- This change has 0 effect on other apps
- We could make this property an ivar, but then we need to manually register RCTLinkingManager.mm ….
- We could append a special url property to deep-links, but I think that would make the ‘API’ harder to use`
  • Loading branch information
christophpurrer authored and Shawn Dempsey committed Nov 21, 2022
1 parent 76c5a37 commit d7db0b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions Libraries/LinkingIOS/RCTLinkingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#if TARGET_OS_OSX // [TODO(macOS GH#774)
+ (void)getUrlEventHandler:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
+ (void)setAlwaysForegroundLastWindow:(BOOL)alwaysForeground;
#else // ]TODO(macOS GH#774)
+ (BOOL)application:(nonnull UIApplication *)app
openURL:(nonnull NSURL *)URL
Expand Down
17 changes: 12 additions & 5 deletions Libraries/LinkingIOS/macos/RCTLinkingManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

static NSString *initialURL = nil;
static BOOL moduleInitalized = NO;
static BOOL alwaysForegroundLastWindow = YES;

static void postNotificationWithURL(NSString *url, id sender)
{
Expand Down Expand Up @@ -60,6 +61,11 @@ - (void)stopObserving
return @[@"url"];
}

+ (void)setAlwaysForegroundLastWindow:(BOOL)alwaysForeground
{
alwaysForegroundLastWindow = alwaysForeground;
}

+ (void)getUrlEventHandler:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
// extract url value from the event
Expand All @@ -76,12 +82,13 @@ + (void)getUrlEventHandler:(NSAppleEventDescriptor *)event withReplyEvent:(NSApp

- (void)handleOpenURLNotification:(NSNotification *)notification
{
// foreground top level window, need to grab it like this, because [NSApp mainWindow] returns nil when the app is hidden
// and another app is maximized
// Activate app, because [NSApp mainWindow] returns nil when the app is hidden and another app is maximized
[NSApp activateIgnoringOtherApps:YES];
NSWindow *lastWindow = [[NSApp windows] lastObject];
[lastWindow makeKeyAndOrderFront:nil];

// foreground top level window
if (alwaysForegroundLastWindow) {
NSWindow *lastWindow = [[NSApp windows] lastObject];
[lastWindow makeKeyAndOrderFront:nil];
}
[self sendEventWithName:@"url" body:notification.userInfo];
}

Expand Down

0 comments on commit d7db0b2

Please sign in to comment.