Browse Source

Organizing and tests.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
eab4bd00cb
  1. 278
      Clocker/ClockerUnitTests/ThemerTests.swift
  2. 125
      Clocker/Overall App/Themer.swift

278
Clocker/ClockerUnitTests/ThemerTests.swift

@ -0,0 +1,278 @@
// Copyright © 2015 Abhishek Banthia
import XCTest
@testable import Clocker
class ThemerTests: XCTestCase {
func testLightTheme() throws {
let subject = Themer(index: 0) // 0 is for light theme
let expectedSliderKnobColor = NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9)
let expectedSliderRightColor = NSColor.gray
let expectedBackgroundColor = NSColor.white
let expectedTextColor = NSColor.black
let expectedTextBackgroundColor = NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle"
let expectedSunriseImageName = "sunrise.fill"
let expectedSunsetImageName = "sunset.fill"
let expectedRemoveImageName = "xmark"
let expectedExtraOptionsImage = "Extra"
let expectedMenubarOnboardingImage = "Light Menubar"
let expectedExtraOptionsHighlightedImage = "ExtraHighlighted"
let expectedSharingImage = "square.and.arrow.up.on.square.fill"
let expectedCurrentLocationImage = "location.fill"
let expectedPopoverApperarance = NSAppearance(named: NSAppearance.Name.vibrantLight)!
let expectedAddImage = "plus"
let expectedAddImageHighlighted = "Add Highlighted"
let expectedPrivacyTabImage = "lock"
let expectedAppearanceTabImage = "eye"
let expectedCalendarTabImage = "calendar"
let expectedGeneralTabImage = "gearshape"
let expectedAboutTabImage = "info.circle"
let expectedVideoCallImage = "video.circle.fill"
let expectedFilledTrashImage = "trash.fill"
let expectedBackwardsImage = "gobackward.15"
let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
XCTAssertEqual(subject.mainTextColor(), expectedTextColor)
XCTAssertEqual(subject.textBackgroundColor(), expectedTextBackgroundColor)
XCTAssertEqual(subject.shutdownImage().accessibilityDescription, expectedShutdownImageName)
XCTAssertEqual(subject.preferenceImage().accessibilityDescription, expectedPreferenceImageName)
XCTAssertEqual(subject.pinImage().accessibilityDescription, expectedPinImageName)
XCTAssertEqual(subject.sunriseImage().accessibilityDescription, expectedSunriseImageName)
XCTAssertEqual(subject.sunsetImage().accessibilityDescription, expectedSunsetImageName)
XCTAssertEqual(subject.removeImage().accessibilityDescription, expectedRemoveImageName)
XCTAssertEqual(subject.extraOptionsImage().name(), expectedExtraOptionsImage)
XCTAssertEqual(subject.menubarOnboardingImage().name(), expectedMenubarOnboardingImage)
XCTAssertEqual(subject.extraOptionsHighlightedImage().name(), expectedExtraOptionsHighlightedImage)
XCTAssertEqual(subject.sharingImage().accessibilityDescription, expectedSharingImage)
XCTAssertEqual(subject.currentLocationImage().accessibilityDescription, expectedCurrentLocationImage)
XCTAssertEqual(subject.popoverAppearance(), expectedPopoverApperarance)
XCTAssertEqual(subject.addImage().accessibilityDescription, expectedAddImage)
XCTAssertEqual(subject.addImageHighlighted().name(), expectedAddImageHighlighted)
XCTAssertEqual(subject.privacyTabImage().accessibilityDescription, expectedPrivacyTabImage)
XCTAssertEqual(subject.appearanceTabImage().accessibilityDescription, expectedAppearanceTabImage)
XCTAssertEqual(subject.calendarTabImage().accessibilityDescription, expectedCalendarTabImage)
XCTAssertEqual(subject.generalTabImage()?.accessibilityDescription, expectedGeneralTabImage)
XCTAssertEqual(subject.aboutTabImage()?.accessibilityDescription, expectedAboutTabImage)
XCTAssertEqual(subject.videoCallImage()?.accessibilityDescription, expectedVideoCallImage)
XCTAssertEqual(subject.filledTrashImage()?.accessibilityDescription, expectedFilledTrashImage)
XCTAssertEqual(subject.goBackwardsImage()?.accessibilityDescription, expectedBackwardsImage)
XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage)
XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage)
}
func testDarkTheme() throws {
let subject = Themer(index: 1) // 1 is for dark theme
let expectedSliderKnobColor = NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
let expectedSliderRightColor = NSColor.white
let expectedBackgroundColor = NSColor(deviceRed: 42.0 / 255.0, green: 42.0 / 255.0, blue: 42.0 / 255.0, alpha: 1.0)
let expectedTextColor = NSColor.white
let expectedTextBackgroundColor = NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle"
let expectedSunriseImageName = "sunrise.fill"
let expectedSunsetImageName = "sunset.fill"
let expectedRemoveImageName = "xmark"
let expectedExtraOptionsImage = "ExtraWhite"
let expectedMenubarOnboardingImage = "Light Menubar"
let expectedExtraOptionsHighlightedImage = "ExtraWhiteHighlighted"
let expectedSharingImage = "square.and.arrow.up.on.square.fill"
let expectedCurrentLocationImage = "location.fill"
let expectedPopoverApperarance = NSAppearance(named: NSAppearance.Name.vibrantDark)!
let expectedAddImage = "plus"
let expectedAddImageHighlighted = "Add White"
let expectedPrivacyTabImage = "lock"
let expectedAppearanceTabImage = "eye"
let expectedCalendarTabImage = "calendar"
let expectedGeneralTabImage = "gearshape"
let expectedAboutTabImage = "info.circle"
let expectedVideoCallImage = "video.circle.fill"
let expectedFilledTrashImage = "trash.fill"
let expectedBackwardsImage = "gobackward.15"
let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
XCTAssertEqual(subject.mainTextColor(), expectedTextColor)
XCTAssertEqual(subject.textBackgroundColor(), expectedTextBackgroundColor)
XCTAssertEqual(subject.shutdownImage().accessibilityDescription, expectedShutdownImageName)
XCTAssertEqual(subject.preferenceImage().accessibilityDescription, expectedPreferenceImageName)
XCTAssertEqual(subject.pinImage().accessibilityDescription, expectedPinImageName)
XCTAssertEqual(subject.sunriseImage().accessibilityDescription, expectedSunriseImageName)
XCTAssertEqual(subject.sunsetImage().accessibilityDescription, expectedSunsetImageName)
XCTAssertEqual(subject.removeImage().accessibilityDescription, expectedRemoveImageName)
XCTAssertEqual(subject.extraOptionsImage().name(), expectedExtraOptionsImage)
XCTAssertEqual(subject.menubarOnboardingImage().name(), expectedMenubarOnboardingImage)
XCTAssertEqual(subject.extraOptionsHighlightedImage().name(), expectedExtraOptionsHighlightedImage)
XCTAssertEqual(subject.sharingImage().accessibilityDescription, expectedSharingImage)
XCTAssertEqual(subject.currentLocationImage().accessibilityDescription, expectedCurrentLocationImage)
XCTAssertEqual(subject.popoverAppearance(), expectedPopoverApperarance)
XCTAssertEqual(subject.addImage().accessibilityDescription, expectedAddImage)
XCTAssertEqual(subject.addImageHighlighted().name(), expectedAddImageHighlighted)
XCTAssertEqual(subject.privacyTabImage().accessibilityDescription, expectedPrivacyTabImage)
XCTAssertEqual(subject.appearanceTabImage().accessibilityDescription, expectedAppearanceTabImage)
XCTAssertEqual(subject.calendarTabImage().accessibilityDescription, expectedCalendarTabImage)
XCTAssertEqual(subject.generalTabImage()?.accessibilityDescription, expectedGeneralTabImage)
XCTAssertEqual(subject.aboutTabImage()?.accessibilityDescription, expectedAboutTabImage)
XCTAssertEqual(subject.videoCallImage()?.accessibilityDescription, expectedVideoCallImage)
XCTAssertEqual(subject.filledTrashImage()?.accessibilityDescription, expectedFilledTrashImage)
XCTAssertEqual(subject.goBackwardsImage()?.accessibilityDescription, expectedBackwardsImage)
XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage)
XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage)
XCTAssertEqual(subject.description, "Current Theme is \(Theme.dark)")
}
func testSolarizedLightTheme() throws {
let subject = Themer(index: 3) // 3 is for solarized light theme
let expectedSliderKnobColor = NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
let expectedSliderRightColor = NSColor.gray
let expectedBackgroundColor = NSColor(deviceRed: 253.0 / 255.0, green: 246.0 / 255.0, blue: 227.0 / 255.0, alpha: 1.0)
let expectedTextColor = NSColor.black
let expectedTextBackgroundColor = NSColor(deviceRed: 238.0 / 255.0, green: 232.0 / 255.0, blue: 213.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle"
let expectedSunriseImageName = "sunrise.fill"
let expectedSunsetImageName = "sunset.fill"
let expectedRemoveImageName = "xmark"
let expectedExtraOptionsImage = "Extra"
let expectedMenubarOnboardingImage = "Light Menubar"
let expectedExtraOptionsHighlightedImage = "ExtraHighlighted"
let expectedSharingImage = "square.and.arrow.up.on.square.fill"
let expectedCurrentLocationImage = "location.fill"
let expectedPopoverApperarance = NSAppearance(named: NSAppearance.Name.vibrantLight)!
let expectedAddImage = "plus"
let expectedAddImageHighlighted = "Add White"
let expectedPrivacyTabImage = "lock"
let expectedAppearanceTabImage = "eye"
let expectedCalendarTabImage = "calendar"
let expectedGeneralTabImage = "gearshape"
let expectedAboutTabImage = "info.circle"
let expectedVideoCallImage = "video.circle.fill"
let expectedFilledTrashImage = "trash.fill"
let expectedBackwardsImage = "gobackward.15"
let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
XCTAssertEqual(subject.mainTextColor(), expectedTextColor)
XCTAssertEqual(subject.textBackgroundColor(), expectedTextBackgroundColor)
XCTAssertEqual(subject.shutdownImage().accessibilityDescription, expectedShutdownImageName)
XCTAssertEqual(subject.preferenceImage().accessibilityDescription, expectedPreferenceImageName)
XCTAssertEqual(subject.pinImage().accessibilityDescription, expectedPinImageName)
XCTAssertEqual(subject.sunriseImage().accessibilityDescription, expectedSunriseImageName)
XCTAssertEqual(subject.sunsetImage().accessibilityDescription, expectedSunsetImageName)
XCTAssertEqual(subject.removeImage().accessibilityDescription, expectedRemoveImageName)
XCTAssertEqual(subject.extraOptionsImage().name(), expectedExtraOptionsImage)
XCTAssertEqual(subject.menubarOnboardingImage().name(), expectedMenubarOnboardingImage)
XCTAssertEqual(subject.extraOptionsHighlightedImage().name(), expectedExtraOptionsHighlightedImage)
XCTAssertEqual(subject.sharingImage().accessibilityDescription, expectedSharingImage)
XCTAssertEqual(subject.currentLocationImage().accessibilityDescription, expectedCurrentLocationImage)
XCTAssertEqual(subject.popoverAppearance(), expectedPopoverApperarance)
XCTAssertEqual(subject.addImage().accessibilityDescription, expectedAddImage)
XCTAssertEqual(subject.addImageHighlighted().name(), expectedAddImageHighlighted)
XCTAssertEqual(subject.privacyTabImage().accessibilityDescription, expectedPrivacyTabImage)
XCTAssertEqual(subject.appearanceTabImage().accessibilityDescription, expectedAppearanceTabImage)
XCTAssertEqual(subject.calendarTabImage().accessibilityDescription, expectedCalendarTabImage)
XCTAssertEqual(subject.generalTabImage()?.accessibilityDescription, expectedGeneralTabImage)
XCTAssertEqual(subject.aboutTabImage()?.accessibilityDescription, expectedAboutTabImage)
XCTAssertEqual(subject.videoCallImage()?.accessibilityDescription, expectedVideoCallImage)
XCTAssertEqual(subject.filledTrashImage()?.accessibilityDescription, expectedFilledTrashImage)
XCTAssertEqual(subject.goBackwardsImage()?.accessibilityDescription, expectedBackwardsImage)
XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage)
XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage)
}
func testSolarizedDarkTheme() throws {
let subject = Themer(index: 4) // 4 is for solarized dark theme
let expectedSliderKnobColor = NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
let expectedSliderRightColor = NSColor.gray
let expectedBackgroundColor = NSColor(deviceRed: 7.0 / 255.0, green: 54.0 / 255.0, blue: 66.0 / 255.0, alpha: 1.0)
let expectedTextColor = NSColor.white
let expectedTextBackgroundColor = NSColor(deviceRed: 88.0 / 255.0, green: 110.0 / 255.0, blue: 117.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle"
let expectedSunriseImageName = "sunrise.fill"
let expectedSunsetImageName = "sunset.fill"
let expectedRemoveImageName = "xmark"
let expectedExtraOptionsImage = "ExtraWhite"
let expectedMenubarOnboardingImage = "Light Menubar"
let expectedExtraOptionsHighlightedImage = "ExtraWhiteHighlighted"
let expectedSharingImage = "square.and.arrow.up.on.square.fill"
let expectedCurrentLocationImage = "location.fill"
let expectedPopoverApperarance = NSAppearance(named: NSAppearance.Name.vibrantDark)!
let expectedAddImage = "plus"
let expectedAddImageHighlighted = "Add White"
let expectedPrivacyTabImage = "lock"
let expectedAppearanceTabImage = "eye"
let expectedCalendarTabImage = "calendar"
let expectedGeneralTabImage = "gearshape"
let expectedAboutTabImage = "info.circle"
let expectedVideoCallImage = "video.circle.fill"
let expectedFilledTrashImage = "trash.fill"
let expectedBackwardsImage = "gobackward.15"
let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
XCTAssertEqual(subject.mainTextColor(), expectedTextColor)
XCTAssertEqual(subject.textBackgroundColor(), expectedTextBackgroundColor)
XCTAssertEqual(subject.shutdownImage().accessibilityDescription, expectedShutdownImageName)
XCTAssertEqual(subject.preferenceImage().accessibilityDescription, expectedPreferenceImageName)
XCTAssertEqual(subject.pinImage().accessibilityDescription, expectedPinImageName)
XCTAssertEqual(subject.sunriseImage().accessibilityDescription, expectedSunriseImageName)
XCTAssertEqual(subject.sunsetImage().accessibilityDescription, expectedSunsetImageName)
XCTAssertEqual(subject.removeImage().accessibilityDescription, expectedRemoveImageName)
XCTAssertEqual(subject.extraOptionsImage().name(), expectedExtraOptionsImage)
XCTAssertEqual(subject.menubarOnboardingImage().name(), expectedMenubarOnboardingImage)
XCTAssertEqual(subject.extraOptionsHighlightedImage().name(), expectedExtraOptionsHighlightedImage)
XCTAssertEqual(subject.sharingImage().accessibilityDescription, expectedSharingImage)
XCTAssertEqual(subject.currentLocationImage().accessibilityDescription, expectedCurrentLocationImage)
XCTAssertEqual(subject.popoverAppearance(), expectedPopoverApperarance)
XCTAssertEqual(subject.addImage().accessibilityDescription, expectedAddImage)
XCTAssertEqual(subject.addImageHighlighted().name(), expectedAddImageHighlighted)
XCTAssertEqual(subject.privacyTabImage().accessibilityDescription, expectedPrivacyTabImage)
XCTAssertEqual(subject.appearanceTabImage().accessibilityDescription, expectedAppearanceTabImage)
XCTAssertEqual(subject.calendarTabImage().accessibilityDescription, expectedCalendarTabImage)
XCTAssertEqual(subject.generalTabImage()?.accessibilityDescription, expectedGeneralTabImage)
XCTAssertEqual(subject.aboutTabImage()?.accessibilityDescription, expectedAboutTabImage)
XCTAssertEqual(subject.videoCallImage()?.accessibilityDescription, expectedVideoCallImage)
XCTAssertEqual(subject.filledTrashImage()?.accessibilityDescription, expectedFilledTrashImage)
XCTAssertEqual(subject.goBackwardsImage()?.accessibilityDescription, expectedBackwardsImage)
XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage)
XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage)
}
}

125
Clocker/Overall App/Themer.swift

@ -2,14 +2,6 @@
import Cocoa import Cocoa
func isDarkModeOn() -> Bool {
if #available(macOS 10.14, *) {
return NSAppearance.current.name == NSAppearance.Name.darkAqua
}
return false
}
extension Notification.Name { extension Notification.Name {
static let themeDidChangeNotification = Notification.Name(rawValue: "ThemeDidChangeNotification") static let themeDidChangeNotification = Notification.Name(rawValue: "ThemeDidChangeNotification")
} }
@ -23,7 +15,7 @@ enum Theme: Int {
} }
class Themer: NSObject { class Themer: NSObject {
private static var sharedInstance = Themer() private static var sharedInstance = Themer(index: UserDefaults.standard.integer(forKey: CLThemeKey))
private var effectiveApperanceObserver: NSKeyValueObservation? private var effectiveApperanceObserver: NSKeyValueObservation?
private var themeIndex: Theme { private var themeIndex: Theme {
@ -32,10 +24,8 @@ class Themer: NSObject {
} }
} }
override init() { init(index: Int) {
let defaultTheme = UserDefaults.standard.integer(forKey: CLThemeKey) switch index {
switch defaultTheme {
case 0: case 0:
themeIndex = Theme.light themeIndex = Theme.light
case 1: case 1:
@ -62,7 +52,7 @@ class Themer: NSObject {
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {
effectiveApperanceObserver = NSApp.observe(\.effectiveAppearance) { [weak self] (app, _) in effectiveApperanceObserver = NSApp.observe(\.effectiveAppearance) { [weak self] (app, _) in
if let sSelf = self { if let sSelf = self {
sSelf.respondToInterfaceStyle() sSelf.setAppAppearance()
NotificationCenter.default.post(name: .themeDidChangeNotification, object: nil) NotificationCenter.default.post(name: .themeDidChangeNotification, object: nil)
} }
} }
@ -103,20 +93,8 @@ extension Themer {
self.setAppAppearance() self.setAppAppearance()
} }
} }
private func setAppAppearance() { //MARK: Color
if #available(OSX 10.14, *) {
var appAppearance = NSAppearance(named: .aqua)
if themeIndex == .dark {
appAppearance = NSAppearance(named: .darkAqua)
} else if themeIndex == .system {
appAppearance = retrieveCurrentSystem() == .dark ? NSAppearance(named: .darkAqua) : NSAppearance(named: .aqua)
}
NSApp.appearance = appAppearance
}
}
func sliderKnobColor() -> NSColor { func sliderKnobColor() -> NSColor {
return themeIndex == .light ? NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9) : NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9) return themeIndex == .light ? NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9) : NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
} }
@ -143,16 +121,26 @@ extension Themer {
return themeIndex == .light ? NSColor.white : NSColor(deviceRed: 55.0 / 255.0, green: 71.0 / 255.0, blue: 79.0 / 255.0, alpha: 1.0) return themeIndex == .light ? NSColor.white : NSColor(deviceRed: 55.0 / 255.0, green: 71.0 / 255.0, blue: 79.0 / 255.0, alpha: 1.0)
} }
private func retrieveCurrentSystem() -> Theme { func textBackgroundColor() -> NSColor {
if #available(OSX 10.14, *) { if #available(macOS 10.14, *) {
if let appleInterfaceStyle = UserDefaults.standard.object(forKey: "AppleInterfaceStyle") as? String { switch themeIndex {
if appleInterfaceStyle.lowercased().contains("dark") { case .light:
return .dark return NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0)
} case .dark:
return NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0)
case .system:
return retrieveCurrentSystem() == .light ? NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0) : NSColor.controlBackgroundColor
case .solarizedLight:
return NSColor(deviceRed: 238.0 / 255.0, green: 232.0 / 255.0, blue: 213.0 / 255.0, alpha: 1.0)
case .solarizedDark:
return NSColor(deviceRed: 88.0 / 255.0, green: 110.0 / 255.0, blue: 117.0 / 255.0, alpha: 1.0)
} }
} }
return .light
return themeIndex == .light ?
NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0) :
NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0)
} }
func mainTextColor() -> NSColor { func mainTextColor() -> NSColor {
@ -173,7 +161,8 @@ extension Themer {
return themeIndex == .light ? NSColor.black : NSColor.white return themeIndex == .light ? NSColor.black : NSColor.white
} }
//MARK: Images
func shutdownImage() -> NSImage { func shutdownImage() -> NSImage {
if let symbolImageForShutdown = symbolImage(for: "ellipsis.circle") { if let symbolImageForShutdown = symbolImage(for: "ellipsis.circle") {
return symbolImageForShutdown return symbolImageForShutdown
@ -481,27 +470,6 @@ extension Themer {
return symbolImage(for: "info.circle") return symbolImage(for: "info.circle")
} }
func textBackgroundColor() -> NSColor {
if #available(macOS 10.14, *) {
switch themeIndex {
case .light:
return NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0)
case .dark:
return NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0)
case .system:
return retrieveCurrentSystem() == .light ? NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0) : NSColor.controlBackgroundColor
case .solarizedLight:
return NSColor(deviceRed: 238.0 / 255.0, green: 232.0 / 255.0, blue: 213.0 / 255.0, alpha: 1.0)
case .solarizedDark:
return NSColor(deviceRed: 88.0 / 255.0, green: 110.0 / 255.0, blue: 117.0 / 255.0, alpha: 1.0)
}
}
return themeIndex == .light ?
NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0) :
NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0)
}
func videoCallImage() -> NSImage? { func videoCallImage() -> NSImage? {
if #available(macOS 11.0, *) { if #available(macOS 11.0, *) {
let symbolConfig = NSImage.SymbolConfiguration(pointSize: 20, weight: .regular) let symbolConfig = NSImage.SymbolConfiguration(pointSize: 20, weight: .regular)
@ -531,6 +499,21 @@ extension Themer {
return removeImage() return removeImage()
} }
//MARK: Debug Description
override var debugDescription: String {
if themeIndex == .system {
return "System Theme is \(retrieveCurrentSystem())"
}
return "Current Theme is \(themeIndex)"
}
override var description: String {
return debugDescription
}
//MARK: Private
private func symbolImage(for name: String) -> NSImage? { private func symbolImage(for name: String) -> NSImage? {
assert(name.isEmpty == false) assert(name.isEmpty == false)
@ -543,14 +526,28 @@ extension Themer {
return nil return nil
} }
override var debugDescription: String { private func retrieveCurrentSystem() -> Theme {
if themeIndex == .system { if #available(OSX 10.14, *) {
return "System Theme is \(retrieveCurrentSystem())" if let appleInterfaceStyle = UserDefaults.standard.object(forKey: "AppleInterfaceStyle") as? String {
if appleInterfaceStyle.lowercased().contains("dark") {
return .dark
}
}
} }
return "Current Theme is \(themeIndex)" return .light
} }
override var description: String { private func setAppAppearance() {
return debugDescription if #available(OSX 10.14, *) {
var appAppearance = NSAppearance(named: .aqua)
if themeIndex == .dark {
appAppearance = NSAppearance(named: .darkAqua)
} else if themeIndex == .system {
appAppearance = retrieveCurrentSystem() == .dark ? NSAppearance(named: .darkAqua) : NSAppearance(named: .aqua)
}
NSApp.appearance = appAppearance
}
} }
} }

Loading…
Cancel
Save