Skip to content

Commit 85f37eb

Browse files
committed
Fix issue with app beachballing when connecting from external URL (#2903)
Let’s hope this won’t break on older OS versions now…
1 parent 06380f9 commit 85f37eb

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

Interfaces/English.lproj/ConnectionView.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
</customObject>
6565
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
6666
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
67-
<customView wantsLayer="YES" id="5739" userLabel="ConnectionView" customClass="SPFlippedView">
67+
<customView id="5739" userLabel="ConnectionView" customClass="SPFlippedView">
6868
<rect key="frame" x="0.0" y="0.0" width="882" height="513"/>
6969
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
7070
<subviews>
@@ -261,7 +261,7 @@
261261
<rect key="frame" x="0.0" y="0.0" width="681" height="480"/>
262262
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
263263
<subviews>
264-
<customView id="4888" customClass="NSCustomView">
264+
<customView wantsLayer="YES" id="4888" customClass="NSCustomView">
265265
<rect key="frame" x="116" y="5" width="446" height="472"/>
266266
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
267267
<subviews>

Source/SPConnectionController.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#endif
5959
#import "SPSplitView.h"
6060
#import "SPColorSelectorView.h"
61+
#import "SPFunctions.h"
6162

6263
#import <SPMySQL/SPMySQL.h>
6364

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

19371945
// Update the "Save" button state as appropriate
19381946
[saveFavoriteButton setEnabled:([self selectedFavorite] != nil)];
@@ -2975,6 +2983,13 @@ - (void)scrollViewFrameChanged:(NSNotification *)aNotification
29752983
// Otherwise, center
29762984
else {
29772985
connectionDetailsFrame.origin.y = (scrollViewFrame.size.height - connectionDetailsFrame.size.height)/3;
2986+
// the division may lead to values that are not valid for the current screen size (e.g. non-integer values on a
2987+
// @1x non-retina screen). The OS works something out when not using layer-backed views, but in the latter
2988+
// case the result will look like garbage if we don't fix this.
2989+
// This code is taken from Apple's "BlurryView" example code.
2990+
connectionDetailsFrame = [[connectionDetailsScrollView superview] convertRectToBase:connectionDetailsFrame];
2991+
connectionDetailsFrame.origin.y = round(connectionDetailsFrame.origin.y);
2992+
connectionDetailsFrame = [[connectionDetailsScrollView superview] convertRectFromBase:connectionDetailsFrame];
29782993
[connectionResizeContainer setFrame:connectionDetailsFrame];
29792994
scrollDocumentFrame.size.height = scrollViewFrame.size.height;
29802995
[[connectionDetailsScrollView documentView] setFrame:scrollDocumentFrame];

Source/SPFunctions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
*/
3636
void SPMainQSync(void (^block)(void));
3737

38+
/**
39+
* Asynchronously execute a block on the main run loop.
40+
* This function is equivalent to calling -[[NSRunLoop mainRunLoop] performBlock:] on 10.12+
41+
*/
42+
void SPMainLoopAsync(void (^block)(void));
43+
3844
/**
3945
* Copies count bytes into buf provided by caller
4046
* @param buf Base address to copy to

Source/SPFunctions.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ void SPMainQSync(void (^block)(void))
4242
}
4343
}
4444

45+
void SPMainLoopAsync(void (^block)(void))
46+
{
47+
NSArray *modes = @[NSDefaultRunLoopMode];
48+
CFRunLoopPerformBlock(CFRunLoopGetMain(), modes, block);
49+
}
50+
4551
int SPBetterRandomBytes(uint8_t *buf, size_t count)
4652
{
4753
if([SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0]) {

0 commit comments

Comments
 (0)