From 9aab9de004c18dbd9adf056f449e194631fae84c Mon Sep 17 00:00:00 2001 From: Jason Gavris Date: Sun, 26 Dec 2021 09:05:42 -0500 Subject: [PATCH] Fix cast of non Objective-C pointer in shared_ptr Upstream-Status: Submitted [https://github.com/textmate/textmate/pull/1457] --- Applications/TextMate/src/RMateServer.mm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Applications/TextMate/src/RMateServer.mm b/Applications/TextMate/src/RMateServer.mm index f839026e2..095b49f9f 100644 --- ./Applications/TextMate/src/RMateServer.mm +++ ./Applications/TextMate/src/RMateServer.mm @@ -334,16 +334,17 @@ bool write_data () const { reactivate_callback_t () : _shared_count(std::make_shared(0)) { - _terminal = std::make_shared([NSWorkspace.sharedWorkspace frontmostApplication]); + _terminal = [[NSWorkspace sharedWorkspace] frontmostApplication]; - auto terminal = _terminal; - if([*terminal isEqual:NSRunningApplication.currentApplication]) + __block auto terminal = _terminal; + + if([terminal isEqual:NSRunningApplication.currentApplication]) { // If we call ‘mate -w’ in quick succession there is a chance that we have not yet re-activated the terminal app when we are asked to open a new document. For this reason, we monitor the NSApplicationDidResignActiveNotification for 200 ms to see if the “real” frontmost application becomes active. __weak __block id token = [NSNotificationCenter.defaultCenter addObserverForName:NSApplicationDidResignActiveNotification object:NSApp queue:nil usingBlock:^(NSNotification*){ [NSNotificationCenter.defaultCenter removeObserver:token]; - *terminal = [NSWorkspace.sharedWorkspace frontmostApplication]; + terminal = [NSWorkspace.sharedWorkspace frontmostApplication]; }]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 5), dispatch_get_main_queue(), ^{ @@ -355,19 +356,19 @@ bool write_data () const void watch_document (OakDocument* document) { auto counter = _shared_count; - auto terminal = _terminal; + __block auto terminal = _terminal; ++*counter; __weak __block id token = [NSNotificationCenter.defaultCenter addObserverForName:OakDocumentWillCloseNotification object:document queue:nil usingBlock:^(NSNotification*){ if(--*counter == 0) - [*terminal activateWithOptions:NSApplicationActivateIgnoringOtherApps]; + [terminal activateWithOptions:NSApplicationActivateIgnoringOtherApps]; [NSNotificationCenter.defaultCenter removeObserver:token]; }]; } private: std::shared_ptr _shared_count; - std::shared_ptr _terminal; + NSRunningApplication* _terminal; }; }