|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
|
|
|
|
|
import Cocoa |
|
|
|
|
|
|
|
|
|
private var defaultParagraphStyle: NSMutableParagraphStyle { |
|
|
|
|
var defaultParagraphStyle: NSMutableParagraphStyle { |
|
|
|
|
let paragraphStyle = NSMutableParagraphStyle() |
|
|
|
|
paragraphStyle.alignment = .center |
|
|
|
|
paragraphStyle.lineBreakMode = .byTruncatingTail |
|
|
|
@ -13,10 +13,39 @@ var compactModeTimeFont: NSFont {
|
|
|
|
|
return NSFont.monospacedDigitSystemFont(ofSize: 10, weight: .regular) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var timeAttributes: [NSAttributedString.Key: AnyObject] { |
|
|
|
|
var textColor = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark" ? NSColor.white : NSColor.black |
|
|
|
|
extension NSView { |
|
|
|
|
var hasDarkAppearance: Bool { |
|
|
|
|
if #available(OSX 10.14, *) { |
|
|
|
|
switch effectiveAppearance.name { |
|
|
|
|
case .darkAqua, .vibrantDark, .accessibilityHighContrastDarkAqua, .accessibilityHighContrastVibrantDark: |
|
|
|
|
return true |
|
|
|
|
default: |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
switch effectiveAppearance.name { |
|
|
|
|
case .vibrantDark: |
|
|
|
|
return true |
|
|
|
|
default: |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class StatusItemView: NSView { |
|
|
|
|
// MARK: Private variables |
|
|
|
|
|
|
|
|
|
private let locationView: NSTextField = NSTextField(labelWithString: "Hello") |
|
|
|
|
private let timeView: NSTextField = NSTextField(labelWithString: "Mon 19:14 PM") |
|
|
|
|
private var operationsObject: TimezoneDataOperations { |
|
|
|
|
return TimezoneDataOperations(with: dataObject) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private var timeAttributes: [NSAttributedString.Key: AnyObject] { |
|
|
|
|
var textColor = hasDarkAppearance ? NSColor.white : NSColor.black |
|
|
|
|
|
|
|
|
|
if #available(macOS 10.15, *) { |
|
|
|
|
if #available(macOS 10.16, *) { |
|
|
|
|
textColor = NSColor.white |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -29,19 +58,10 @@ var timeAttributes: [NSAttributedString.Key: AnyObject] {
|
|
|
|
|
return attributes |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class StatusItemView: NSView { |
|
|
|
|
// MARK: Private variables |
|
|
|
|
|
|
|
|
|
private let locationView: NSTextField = NSTextField(labelWithString: "Hello") |
|
|
|
|
private let timeView: NSTextField = NSTextField(labelWithString: "Mon 19:14 PM") |
|
|
|
|
private var operationsObject: TimezoneDataOperations { |
|
|
|
|
return TimezoneDataOperations(with: dataObject) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private var textFontAttributes: [NSAttributedString.Key: Any] { |
|
|
|
|
var textColor = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark" ? NSColor.white : NSColor.black |
|
|
|
|
var textColor = hasDarkAppearance ? NSColor.white : NSColor.black |
|
|
|
|
|
|
|
|
|
if #available(macOS 10.15, *) { |
|
|
|
|
if #available(macOS 10.16, *) { |
|
|
|
|
textColor = NSColor.white |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -89,6 +109,12 @@ class StatusItemView: NSView {
|
|
|
|
|
]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@available(OSX 10.14, *) |
|
|
|
|
override func viewDidChangeEffectiveAppearance() { |
|
|
|
|
super.viewDidChangeEffectiveAppearance() |
|
|
|
|
updateTimeInMenubar() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func updateTimeInMenubar() { |
|
|
|
|
locationView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuTitle(), attributes: textFontAttributes) |
|
|
|
|
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuSubtitle(), attributes: timeAttributes) |
|
|
|
|