Skip to content

Commit

Permalink
Fix issue with app beachballing when connecting from external URL (#2903
Browse files Browse the repository at this point in the history
)

Let’s hope this won’t break on older OS versions now…
  • Loading branch information
dmoagx committed Apr 20, 2018
1 parent 06380f9 commit 85f37eb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Interfaces/English.lproj/ConnectionView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView wantsLayer="YES" id="5739" userLabel="ConnectionView" customClass="SPFlippedView">
<customView id="5739" userLabel="ConnectionView" customClass="SPFlippedView">
<rect key="frame" x="0.0" y="0.0" width="882" height="513"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -261,7 +261,7 @@
<rect key="frame" x="0.0" y="0.0" width="681" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<subviews>
<customView id="4888" customClass="NSCustomView">
<customView wantsLayer="YES" id="4888" customClass="NSCustomView">
<rect key="frame" x="116" y="5" width="446" height="472"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
Expand Down
19 changes: 17 additions & 2 deletions Source/SPConnectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#endif
#import "SPSplitView.h"
#import "SPColorSelectorView.h"
#import "SPFunctions.h"

#import <SPMySQL/SPMySQL.h>

Expand Down Expand Up @@ -1931,8 +1932,15 @@ - (void)_startEditingConnection
[editButtonsView setAlphaValue:0.0f];
[editButtonsView setHidden:NO];
[editButtonsView setFrameOrigin:NSMakePoint([editButtonsView frame].origin.x, [editButtonsView frame].origin.y - 30)];
[[editButtonsView animator] setFrameOrigin:NSMakePoint([editButtonsView frame].origin.x, [editButtonsView frame].origin.y + 30)];
[[editButtonsView animator] setAlphaValue:1.0f];
// The animation is started async because there is a bug/oddity with layer-backed views and animating frameOrigin (at least in 10.13):
// If both calls to -setFrameOrigin: are in the same method, CA would only animate the difference between those calls (which is 0 here).
// This works fine when not using layers, but then there is another issue with the progress indicator (#2903)
SPMainLoopAsync(^{
[NSAnimationContext beginGrouping];
[[editButtonsView animator] setFrameOrigin:NSMakePoint([editButtonsView frame].origin.x, [editButtonsView frame].origin.y + 30)];
[[editButtonsView animator] setAlphaValue:1.0f];
[NSAnimationContext endGrouping];
});

// Update the "Save" button state as appropriate
[saveFavoriteButton setEnabled:([self selectedFavorite] != nil)];
Expand Down Expand Up @@ -2975,6 +2983,13 @@ - (void)scrollViewFrameChanged:(NSNotification *)aNotification
// Otherwise, center
else {
connectionDetailsFrame.origin.y = (scrollViewFrame.size.height - connectionDetailsFrame.size.height)/3;
// the division may lead to values that are not valid for the current screen size (e.g. non-integer values on a
// @1x non-retina screen). The OS works something out when not using layer-backed views, but in the latter
// case the result will look like garbage if we don't fix this.
// This code is taken from Apple's "BlurryView" example code.
connectionDetailsFrame = [[connectionDetailsScrollView superview] convertRectToBase:connectionDetailsFrame];
connectionDetailsFrame.origin.y = round(connectionDetailsFrame.origin.y);
connectionDetailsFrame = [[connectionDetailsScrollView superview] convertRectFromBase:connectionDetailsFrame];
[connectionResizeContainer setFrame:connectionDetailsFrame];
scrollDocumentFrame.size.height = scrollViewFrame.size.height;
[[connectionDetailsScrollView documentView] setFrame:scrollDocumentFrame];
Expand Down
6 changes: 6 additions & 0 deletions Source/SPFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
*/
void SPMainQSync(void (^block)(void));

/**
* Asynchronously execute a block on the main run loop.
* This function is equivalent to calling -[[NSRunLoop mainRunLoop] performBlock:] on 10.12+
*/
void SPMainLoopAsync(void (^block)(void));

/**
* Copies count bytes into buf provided by caller
* @param buf Base address to copy to
Expand Down
6 changes: 6 additions & 0 deletions Source/SPFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ void SPMainQSync(void (^block)(void))
}
}

void SPMainLoopAsync(void (^block)(void))
{
NSArray *modes = @[NSDefaultRunLoopMode];
CFRunLoopPerformBlock(CFRunLoopGetMain(), modes, block);
}

int SPBetterRandomBytes(uint8_t *buf, size_t count)
{
if([SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0]) {
Expand Down

0 comments on commit 85f37eb

Please sign in to comment.