@@ -420,6 +420,9 @@ public class ThemeManager: NSObject {
420
420
// MARK: -
421
421
// MARK: Theme Switching
422
422
423
+ /// Animate theme transitions?
424
+ public var animateThemeTransitions : Bool = true
425
+
423
426
/// Keypath for string `values.ThemeKitTheme`.
424
427
private var themeChangeKVOKeyPath : String = " values. \( ThemeManager . userDefaultsThemeKey) "
425
428
@@ -487,57 +490,59 @@ public class ThemeManager: NSObject {
487
490
applyAndPropagate ( newTheme)
488
491
}
489
492
490
- // Animate theme transition
491
- Thread . onMain {
492
- // Find windows to animate
493
- let windows = NSWindow . windowsCompliantWithWindowThemePolicy ( )
494
- guard windows. count > 0 else {
495
- // Change theme without animation
496
- makeThemeEffective ( newTheme)
497
- return
498
- }
499
-
500
- // Create transition windows off-screen
501
- var transitionWindows = [ Int: NSWindow] ( )
502
- for window in windows {
503
- let windowNumber = window. windowNumber
504
- /* Make sure the window has a number, and that it's not one of our
505
- * existing transition windows */
506
- if windowNumber > 0 && !self . themeTransitionWindows. contains ( window) {
507
- let transitionWindow = window. makeScreenshotWindow ( )
508
- transitionWindows [ windowNumber] = transitionWindow
509
- self . themeTransitionWindows. insert ( transitionWindow)
493
+ Thread . onMain { [ unowned self] in
494
+ // Animate theme transition
495
+ if self . animateThemeTransitions {
496
+ // Find windows to animate
497
+ let windows = NSWindow . windowsCompliantWithWindowThemePolicy ( )
498
+ guard windows. count > 0 else {
499
+ // Change theme without animation
500
+ makeThemeEffective ( newTheme)
501
+ return
510
502
}
511
- }
512
503
513
- // Show (if we have at least one window to animate)
514
- if transitionWindows. count > 0 {
515
- // Show them all (hidden)
516
- for (windowNumber, transitionWindow) in transitionWindows {
517
- transitionWindow. alphaValue = 0.0
518
- let parentWindow = NSApp . window ( withWindowNumber: windowNumber)
519
- parentWindow? . addChildWindow ( transitionWindow, ordered: . above)
504
+ // Create transition windows off-screen
505
+ var transitionWindows = [ Int: NSWindow] ( )
506
+ for window in windows {
507
+ let windowNumber = window. windowNumber
508
+ /* Make sure the window has a number, and that it's not one of our
509
+ * existing transition windows */
510
+ if windowNumber > 0 && !self . themeTransitionWindows. contains ( window) {
511
+ let transitionWindow = window. makeScreenshotWindow ( )
512
+ transitionWindows [ windowNumber] = transitionWindow
513
+ self . themeTransitionWindows. insert ( transitionWindow)
514
+ }
520
515
}
521
516
522
- // Setup animation
523
- NSAnimationContext . beginGrouping ( )
524
- let ctx = NSAnimationContext . current
525
- ctx. duration = 0.3
526
- ctx. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionEaseInEaseOut)
527
- ctx. completionHandler = { ( ) -> Void in
517
+ // Show (if we have at least one window to animate)
518
+ if transitionWindows. count > 0 {
519
+ // Show them all (hidden)
520
+ for (windowNumber, transitionWindow) in transitionWindows {
521
+ transitionWindow. alphaValue = 0.0
522
+ let parentWindow = NSApp . window ( withWindowNumber: windowNumber)
523
+ parentWindow? . addChildWindow ( transitionWindow, ordered: . above)
524
+ }
525
+
526
+ // Setup animation
527
+ NSAnimationContext . beginGrouping ( )
528
+ let ctx = NSAnimationContext . current
529
+ ctx. duration = 0.3
530
+ ctx. timingFunction = CAMediaTimingFunction ( name: kCAMediaTimingFunctionEaseInEaseOut)
531
+ ctx. completionHandler = { ( ) -> Void in
532
+ for transitionWindow in transitionWindows. values {
533
+ transitionWindow. orderOut ( self )
534
+ self . themeTransitionWindows. remove ( transitionWindow)
535
+ }
536
+ }
537
+
538
+ // Show them all and fade out
528
539
for transitionWindow in transitionWindows. values {
529
- transitionWindow. orderOut ( self )
530
- self . themeTransitionWindows . remove ( transitionWindow )
540
+ transitionWindow. alphaValue = 1.0
541
+ transitionWindow . animator ( ) . alphaValue = 0.0
531
542
}
532
- }
543
+ NSAnimationContext . endGrouping ( )
533
544
534
- // Show them all and fade out
535
- for transitionWindow in transitionWindows. values {
536
- transitionWindow. alphaValue = 1.0
537
- transitionWindow. animator ( ) . alphaValue = 0.0
538
545
}
539
- NSAnimationContext . endGrouping ( )
540
-
541
546
}
542
547
543
548
// Actually change theme
0 commit comments