From e87ae71f18e9579e7bbaf552766954cd8b95e396 Mon Sep 17 00:00:00 2001 From: Igor Kulman Date: Sun, 24 Jan 2021 14:22:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Catalina=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Package.swift | 2 +- Sources/ChangeMenuBarColor/Commands/Gradient.swift | 2 +- Sources/ChangeMenuBarColor/Commands/SolidColor.swift | 3 +-- .../Extensions/ImageFunctions.swift | 11 +++++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 3935e05..ddc18f3 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ import PackageDescription let package = Package( name: "ChangeMenuBarColor", platforms: [ - .macOS(.v11) + .macOS(.v10_15) ], dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.1"), diff --git a/Sources/ChangeMenuBarColor/Commands/Gradient.swift b/Sources/ChangeMenuBarColor/Commands/Gradient.swift index 85737d0..5776c73 100644 --- a/Sources/ChangeMenuBarColor/Commands/Gradient.swift +++ b/Sources/ChangeMenuBarColor/Commands/Gradient.swift @@ -52,7 +52,7 @@ final class Gradient: Command, ParsableCommand { return nil } - Log.debug("Generating gradient image from \(AXNameFromColor(startColor.cgColor)) to \(AXNameFromColor(endColor.cgColor))") + Log.debug("Generating gradient image from \(colorName(startColor)) to \(colorName(endColor))") guard let topImage = createGradientImage(startColor: startColor, endColor: endColor, width: screen.size.width, height: screen.menuBarHeight) else { return nil } diff --git a/Sources/ChangeMenuBarColor/Commands/SolidColor.swift b/Sources/ChangeMenuBarColor/Commands/SolidColor.swift index 794493d..ee3957d 100644 --- a/Sources/ChangeMenuBarColor/Commands/SolidColor.swift +++ b/Sources/ChangeMenuBarColor/Commands/SolidColor.swift @@ -5,7 +5,6 @@ // Created by Igor Kulman on 19.11.2020. // -import Accessibility import ArgumentParser import Foundation import Cocoa @@ -45,7 +44,7 @@ final class SolidColor: Command, ParsableCommand { return nil } - Log.debug("Generating \(AXNameFromColor(color.cgColor)) solid color image") + Log.debug("Generating \(colorName(color)) solid color image") guard let topImage = createSolidImage(color: color, width: screen.size.width, height: screen.menuBarHeight) else { return nil } diff --git a/Sources/ChangeMenuBarColor/Extensions/ImageFunctions.swift b/Sources/ChangeMenuBarColor/Extensions/ImageFunctions.swift index cfc7e95..1a83183 100644 --- a/Sources/ChangeMenuBarColor/Extensions/ImageFunctions.swift +++ b/Sources/ChangeMenuBarColor/Extensions/ImageFunctions.swift @@ -5,6 +5,9 @@ // Created by Igor Kulman on 19.11.2020. // +#if canImport(Accessibility) + import Accessibility +#endif import Foundation import Cocoa @@ -66,3 +69,11 @@ func combineImages(baseImage: NSImage, addedImage: NSImage) -> NSImage? { func createContext(width: CGFloat, height: CGFloat) -> CGContext? { return CGContext(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue) } + +func colorName(_ color: NSColor) -> String { + if #available(OSX 11.0, *) { + return AXNameFromColor(color.cgColor) + } else { + return color.description + } +}