Permalink
Browse files

add solid logic for True Tone menu item

  • Loading branch information...
thompsonate committed Sep 5, 2018
1 parent 7a6b5f0 commit f37f1b8628fab349a89b1465f94a87a2d0d5b055
View
@@ -46,20 +46,14 @@
<action selector="power:" target="YHE-ZD-Fjn" id="JXj-lp-mVz"/>
</connections>
</menuItem>
<menuItem title="Turn off True Tone" id="fW8-W0-ja9">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleTrueTone:" target="YHE-ZD-Fjn" id="fLs-gG-LhC"/>
</connections>
</menuItem>
<menuItem title="Description" id="zi6-lD-Hd5">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="Zh0-ra-bP7"/>
<menuItem title="Slider" id="NRb-4W-jcc">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="W1o-NM-zpi"/>
<menuItem isSeparatorItem="YES" id="9KJ-0B-A9w"/>
<menuItem title="Disable for app" id="ycw-C3-JG6">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
@@ -90,6 +84,13 @@
<action selector="disableCustomTime:" target="YHE-ZD-Fjn" id="tHA-tu-det"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="Myq-mS-cHa"/>
<menuItem title="Turn off True Tone" id="fW8-W0-ja9">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleTrueTone:" target="YHE-ZD-Fjn" id="fLs-gG-LhC"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="OE0-tz-FKo"/>
<menuItem title="Preferences..." id="GJi-nB-WzR">
<modifierMask key="keyEquivalentModifierMask"/>
@@ -104,7 +105,7 @@
</connections>
</menuItem>
</items>
<point key="canvasLocation" x="144.5" y="137.5"/>
<point key="canvasLocation" x="144" y="120"/>
</menu>
<customView id="xRd-3s-8Ep" customClass="SliderView" customModule="Shifty" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="247" height="21"/>
@@ -212,7 +212,8 @@ enum NightShiftManager {
return NightShiftManager.nightShiftDisableTimer != .off
}
private static var disableRuleIsActive: Bool {
///When true, app or website rule has disabled Night Shift
static var disableRuleIsActive: Bool {
return RuleManager.disableRuleIsActive
}
@@ -85,18 +85,6 @@ class StatusMenuController: NSObject, NSMenuDelegate {
preferencesMenuItem.title = NSLocalizedString("menu.preferences", comment: "Preferences...")
quitMenuItem.title = NSLocalizedString("menu.quit", comment: "Quit Shifty")
if CBTrueToneClient.shared.isTrueToneSupported {
if CBTrueToneClient.shared.isTrueToneEnabled {
trueToneMenuItem.title = "Turn off True Tone"
} else {
trueToneMenuItem.title = "Turn on True Tone"
}
trueToneMenuItem.isEnabled = CBTrueToneClient.shared.isTrueToneAvailable
} else {
trueToneMenuItem.isHidden = true
}
(NSApp.delegate as? AppDelegate)?.statusItemClicked = {
if NightShiftManager.isNightShiftEnabled {
@@ -208,6 +196,34 @@ class StatusMenuController: NSObject, NSMenuDelegate {
disableCustomMenuItem.isEnabled = true
disableCustomMenuItem.title = NSLocalizedString("menu.disabled_custom", comment: "Disabled for custom time")
}
trueToneMenuItem.isHidden = false
trueToneMenuItem.isEnabled = true
switch CBTrueToneClient.shared.state {
case .unsupported:
trueToneMenuItem.isHidden = true
case .unavailable:
trueToneMenuItem.isEnabled = false
trueToneMenuItem.title = NSLocalizedString("menu.true_tone_unavailable", comment: "True Tone is not available")
case .enabled:
trueToneMenuItem.title = NSLocalizedString("menu.true_tone_off", comment: "Turn off True Tone")
case .disabled:
if NightShiftManager.disableRuleIsActive {
trueToneMenuItem.isEnabled = false
if RuleManager.disabledForDomain {
trueToneMenuItem.title = String(format: NSLocalizedString("menu.true_tone_disabled_for", comment: "True Tone is disabled for %@"), BrowserManager.currentDomain ?? "")
} else if RuleManager.ruleForSubdomain == .disabled {
trueToneMenuItem.title = String(format: NSLocalizedString("menu.true_tone_disabled_for", comment: "True Tone is disabled for %@"), BrowserManager.currentSubdomain ?? "")
} else {
trueToneMenuItem.title = String(format: NSLocalizedString("menu.true_tone_disabled_for", comment: "True Tone is disabled for %@"), currentAppName)
}
} else {
trueToneMenuItem.title = NSLocalizedString("menu.true_tone_on", comment: "Turn on True Tone")
}
}
}
@@ -314,16 +330,6 @@ class StatusMenuController: NSObject, NSMenuDelegate {
NightShiftManager.respond(to: .userEnabledNightShift)
}
}
@IBAction func toggleTrueTone(_ sender: NSMenuItem) {
if CBTrueToneClient.shared.isTrueToneEnabled {
sender.title = "Turn off True Tone"
} else {
sender.title = "Turn on True Tone"
}
CBTrueToneClient.shared.isTrueToneEnabled = !CBTrueToneClient.shared.isTrueToneEnabled
}
@IBAction func disableForApp(_ sender: Any) {
if RuleManager.disabledForApp {
@@ -404,6 +410,10 @@ class StatusMenuController: NSObject, NSMenuDelegate {
NightShiftManager.respond(to: .nightShiftDisableTimerEnded)
}
}
@IBAction func toggleTrueTone(_ sender: NSMenuItem) {
CBTrueToneClient.shared.isTrueToneEnabled = !CBTrueToneClient.shared.isTrueToneEnabled
}
@IBAction func preferencesClicked(_ sender: NSMenuItem) {
NSApp.activate(ignoringOtherApps: true)
@@ -7,14 +7,21 @@
import Foundation
enum State {
case unsupported
case unavailable
case enabled
case disabled
}
extension CBTrueToneClient {
static var shared = CBTrueToneClient()
var isTrueToneSupported: Bool {
private var isTrueToneSupported: Bool {
return CBTrueToneClient.shared.supported()
}
var isTrueToneAvailable: Bool {
private var isTrueToneAvailable: Bool {
return CBTrueToneClient.shared.available()
}
@@ -26,4 +33,11 @@ extension CBTrueToneClient {
CBTrueToneClient.shared.setEnabled(newValue)
}
}
var state: State {
if !isTrueToneSupported { return .unsupported }
else if !isTrueToneAvailable { return .unavailable }
else if isTrueToneEnabled { return .enabled }
else { return .disabled }
}
}
@@ -20,6 +20,12 @@
"menu.disabled_hour" = "Disabled for an hour";
"menu.disable_custom" = "Disable for custom time...";
"menu.disabled_custom" = "Disabled for custom time";
"menu.true_tone_on" = "Turn on True Tone";
"menu.true_tone_off" = "Turn off True Tone";
"menu.true_tone_unavailable" = "True Tone is not available";
"menu.true_tone_disabled_for" = "True Tone is disabled for %@";
"menu.preferences" = "Preferences...";
"menu.quit" = "Quit Shifty";

0 comments on commit f37f1b8

Please sign in to comment.