From ed1bd4bf46ce8faceeda02becdfc66f36a746f5d Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 11 Jan 2017 13:37:50 +0100 Subject: [PATCH] Share colors between view and TouchBar --- Muse/ViewController.swift | 8 -------- Muse/WindowController.swift | 13 ++++++++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Muse/ViewController.swift b/Muse/ViewController.swift index ce2b8e4..258b835 100644 --- a/Muse/ViewController.swift +++ b/Muse/ViewController.swift @@ -263,14 +263,6 @@ class ViewController: NSViewController { } else if let image = object as? NSImage { fullSongArtworkView.image = image } - - // Update the colors with a completion handler - // This avoids blocking the main UI thread - fullSongArtworkView.image?.getColors(scaleDownSize: NSMakeSize(25, 25)) { colors in - // We also set an aggressive scaling size - // to optimize performace and memory usage - self.colorViews(with: colors) - } } func colorButtonImages(with color: NSColor) { diff --git a/Muse/WindowController.swift b/Muse/WindowController.swift index 19d1302..eee5771 100644 --- a/Muse/WindowController.swift +++ b/Muse/WindowController.swift @@ -702,10 +702,17 @@ class WindowController: NSWindowController, NSWindowDelegate { // TODO: Move this elsewhere songArtworkTitleButton.image = image.resized(to: NSMakeSize(30, 30)) - // Set bezel color - // TODO: Share this colors with ViewController - image.getColors(scaleDownSize: NSMakeSize(10, 10)) { colors in + // Fetch image colors + // We also set an aggressive scaling size + // to optimize performace and memory usage + image.getColors(scaleDownSize: NSMakeSize(25, 25)) { colors in + // Set colors on TouchBar button self.songArtworkTitleButton.bezelColor = colors.primary.blended(withFraction: 0.5, of: .darkGray) + + // Set colors on main view + self.onViewController { controller in + controller.colorViews(with: colors) + } } }