-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathTemperatureTouchBarController.m
70 lines (54 loc) · 2.92 KB
/
TemperatureTouchBarController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// TouchBarController.m
// GoodNight
//
// Created by Anthony Agatiello on 11/24/16.
// Copyright © 2016 ADA Tech, LLC. All rights reserved.
//
#import "TemperatureTouchBarController.h"
#import "MacGammaController.h"
#import "TemperatureViewController.h"
@implementation TemperatureTouchBarController
- (void)awakeFromNib {
[self.touchBarTemperatureSlider.slider setFloatValue:[userDefaults floatForKey:@"orangeValue"]];
self.touchBarTemperatureSlider.label = [NSString stringWithFormat:@"%dK", (int)round((((self.touchBarTemperatureSlider.slider.maxValue - self.touchBarTemperatureSlider.slider.floatValue) * 45 + 20) * 10) * 10)];
[defNotifCenter addObserver:self selector:@selector(defaultsChanged) name:NSUserDefaultsDidChangeNotification object:nil];
}
- (void)defaultsChanged {
[self.touchBarTemperatureSlider.slider setFloatValue:[userDefaults floatForKey:@"orangeValue"]];
self.touchBarTemperatureSlider.label = [NSString stringWithFormat:@"%dK", (int)round((((self.touchBarTemperatureSlider.slider.maxValue - self.touchBarTemperatureSlider.slider.floatValue) * 45 + 20) * 10) * 10)];
if ([userDefaults boolForKey:@"darkroomEnabled"]) {
[self.touchBarDarkroomButton setTitle:@"Disable Darkroom"];
}
else {
[self.touchBarDarkroomButton setTitle:@"Enable Darkroom"];
}
}
- (IBAction)touchBarSliderValueDidChange:(NSSliderTouchBarItem *)slider {
[self.touchBarDarkroomButton setTitle:@"Enable Darkroom"];
[userDefaults setFloat:self.touchBarTemperatureSlider.slider.floatValue forKey:@"orangeValue"];
[MacGammaController setGammaWithOrangeness:[userDefaults floatForKey:@"orangeValue"]];
if (self.touchBarTemperatureSlider.slider.floatValue == 0) {
[self resetTemperature:nil];
}
self.touchBarTemperatureSlider.label = [NSString stringWithFormat:@"%dK", (int)round((((self.touchBarTemperatureSlider.slider.maxValue - self.touchBarTemperatureSlider.slider.floatValue) * 45 + 20) * 10) * 10)];
[userDefaults setFloat:1 forKey:@"brightnessValue"];
[userDefaults setFloat:0.5 forKey:@"whitePointValue"];
[userDefaults setBool:NO forKey:@"darkroomEnabled"];
[userDefaults synchronize];
}
- (IBAction)resetTemperature:(NSButton *)button {
[MacGammaController resetAllAdjustments];
}
- (IBAction)toggleDarkroom:(NSButton *)button {
[self.touchBarTemperatureSlider.slider setFloatValue:[userDefaults floatForKey:@"orangeValue"]];
self.touchBarTemperatureSlider.label = [NSString stringWithFormat:@"%dK", (int)round((((self.touchBarTemperatureSlider.slider.maxValue - self.touchBarTemperatureSlider.slider.floatValue) * 45 + 20) * 10) * 10)];
if ([self.touchBarDarkroomButton.title isEqualToString:@"Enable Darkroom"]) {
[self.touchBarDarkroomButton setTitle:@"Disable Darkroom"];
}
else {
[self.touchBarDarkroomButton setTitle:@"Enable Darkroom"];
}
[MacGammaController toggleDarkroom];
}
@end