diff options
author | rowanbeentje <rowan@beent.je> | 2010-07-25 12:05:13 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-07-25 12:05:13 +0000 |
commit | 550c112216171aa81487b32c41d7aa64adc2ec7f (patch) | |
tree | 1ddbbd28c4d46dec359caeede81e899f5970a0e5 /Source | |
parent | 0dff71796759307023398775fde082e3bdd41d31 (diff) | |
download | sequelpro-550c112216171aa81487b32c41d7aa64adc2ec7f.tar.gz sequelpro-550c112216171aa81487b32c41d7aa64adc2ec7f.tar.bz2 sequelpro-550c112216171aa81487b32c41d7aa64adc2ec7f.zip |
- Replace core animation fade of task progress window with custom drawing code, in an attempt to fix Issue #677. It appears from testing that this is only a partial fix, but does reduce hang frequency.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPDatabaseDocument.h | 4 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 51 |
2 files changed, 31 insertions, 24 deletions
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index 40a221d0..9d027b4f 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -154,7 +154,7 @@ CGFloat taskDisplayLastValue; CGFloat taskProgressValueDisplayInterval; NSTimer *taskDrawTimer; - NSViewAnimation *taskFadeAnimator; + NSDate *taskFadeInStartDate; BOOL taskCanBeCancelled; id taskCancellationCallbackObject; SEL taskCancellationCallbackSelector; @@ -221,7 +221,7 @@ // Task progress and notification methods - (void)startTaskWithDescription:(NSString *)description; -- (void)showTaskProgressWindow:(NSTimer *)theTimer; +- (void)fadeInTaskProgressWindow:(NSTimer *)theTimer; - (void)setTaskDescription:(NSString *)description; - (void)setTaskPercentage:(CGFloat)taskPercentage; - (void)setTaskProgressToIndeterminateAfterDelay:(BOOL)afterDelay; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 43b5e844..bace5cb5 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -119,7 +119,7 @@ taskProgressValue = 0; taskProgressValueDisplayInterval = 1; taskDrawTimer = nil; - taskFadeAnimator = nil; + taskFadeInStartDate = nil; taskCanBeCancelled = NO; taskCancellationCallbackObject = nil; taskCancellationCallbackSelector = NULL; @@ -1304,27 +1304,37 @@ [mainToolbar validateVisibleItems]; [chooseDatabaseButton setEnabled:NO]; - // Schedule appearance of the task window in the near future - taskDrawTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showTaskProgressWindow:) userInfo:nil repeats:NO] retain]; + // Schedule appearance of the task window in the near future, using a frame timer. + taskFadeInStartDate = [[NSDate alloc] init]; + taskDrawTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 / 30.0 target:self selector:@selector(fadeInTaskProgressWindow:) userInfo:nil repeats:YES] retain]; } } /** * Show the task progress window, after a small delay to minimise flicker. */ -- (void) showTaskProgressWindow:(NSTimer *)theTimer +- (void) fadeInTaskProgressWindow:(NSTimer *)theTimer { - if (taskDrawTimer) [taskDrawTimer invalidate], [taskDrawTimer release], taskDrawTimer = nil; + float timeSinceFadeInStart = [[NSDate date] timeIntervalSinceDate:taskFadeInStartDate]; - // Center the task window and fade it in - [self centerTaskWindow]; - NSDictionary *animationDetails = [NSDictionary dictionaryWithObjectsAndKeys: - NSViewAnimationFadeInEffect, NSViewAnimationEffectKey, - taskProgressWindow, NSViewAnimationTargetKey, - nil]; - taskFadeAnimator = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:animationDetails]]; - [taskFadeAnimator setDuration:0.6]; - [taskFadeAnimator startAnimation]; + // Keep the window hidden for the first ~0.5 secs + if (timeSinceFadeInStart < 0.5) return; + + CGFloat alphaValue = [taskProgressWindow alphaValue]; + + // If the task progress window is still hidden, center it before revealing it + if (alphaValue == 0) [self centerTaskWindow]; + + // Fade in the task window over 0.6 seconds + alphaValue = (timeSinceFadeInStart - 0.5) / 0.6; + if (alphaValue > 1.0) alphaValue = 1.0; + [taskProgressWindow setAlphaValue:alphaValue]; + + // If the window has been fully faded in, clean up the timer. + if (alphaValue == 1.0) { + [taskDrawTimer invalidate], [taskDrawTimer release], taskDrawTimer = nil; + [taskFadeInStartDate release], taskFadeInStartDate = nil; + } } @@ -1405,12 +1415,9 @@ if (!_isWorkingLevel) { // Cancel the draw timer if it exists - if (taskDrawTimer) [taskDrawTimer invalidate], [taskDrawTimer release], taskDrawTimer = nil; - - // Cancel the fade-in animator if it exists - if (taskFadeAnimator) { - if ([taskFadeAnimator isAnimating]) [taskFadeAnimator stopAnimation]; - [taskFadeAnimator release], taskFadeAnimator = nil; + if (taskDrawTimer) { + [taskDrawTimer invalidate], [taskDrawTimer release], taskDrawTimer = nil; + [taskFadeInStartDate release], taskFadeInStartDate = nil; } // Hide the task interface and reset to indeterminate @@ -4625,8 +4632,8 @@ if (mySQLConnection) [mySQLConnection release]; if (selectedDatabase) [selectedDatabase release]; if (mySQLVersion) [mySQLVersion release]; - if (taskDrawTimer) [taskDrawTimer release]; - if (taskFadeAnimator) [taskFadeAnimator release]; + if (taskDrawTimer) [taskDrawTimer invalidate], [taskDrawTimer release]; + if (taskFadeInStartDate) [taskFadeInStartDate release]; if (queryEditorInitString) [queryEditorInitString release]; if (spfFileURL) [spfFileURL release]; if (spfPreferences) [spfPreferences release]; |