@@ -25,6 +25,7 @@ class TimerViewController : NSViewController, NSUserNotificationCenterDelegate{
25
25
26
26
var isStart = Bool ( false )
27
27
var isPause = Bool ( false )
28
+ var isDark = Bool ( true )
28
29
29
30
var myQueue = OperationQueue ( )
30
31
let myActivity = ProcessInfo . processInfo. beginActivity (
@@ -44,6 +45,18 @@ class TimerViewController : NSViewController, NSUserNotificationCenterDelegate{
44
45
45
46
override func viewDidLoad( ) {
46
47
super. viewDidLoad ( )
48
+ let defau = UserDefaults . standard
49
+ let dark = defau. bool ( forKey: " DarkThemeTimer? " )
50
+ if !dark {
51
+ changeLight ( )
52
+ } else {
53
+ changeDark ( )
54
+ }
55
+ NotificationCenter . default. addObserver ( self , selector: #selector( changeDark) , name: NSNotification . Name. init ( " SCTIMERDARK " ) , object: nil )
56
+ NotificationCenter . default. addObserver ( self , selector: #selector( changeLight) , name: NSNotification . Name. init ( " SCTIMERLIGHT " ) , object: nil )
57
+ NotificationCenter . default. addObserver ( self , selector: #selector( start) , name: NSNotification . Name. init ( " SCTIMERSTART " ) , object: nil )
58
+ NotificationCenter . default. addObserver ( self , selector: #selector( pause) , name: NSNotification . Name. init ( " SCTIMERPAUSE " ) , object: nil )
59
+ NotificationCenter . default. addObserver ( self , selector: #selector( end) , name: NSNotification . Name. init ( " SCTIMEREND " ) , object: nil )
47
60
timer = Timer . scheduledTimer ( withTimeInterval: 1.0 , repeats: true , block: { ( timer) in
48
61
self . timerMain ( )
49
62
} )
@@ -53,6 +66,36 @@ class TimerViewController : NSViewController, NSUserNotificationCenterDelegate{
53
66
}
54
67
}
55
68
69
+ override func viewWillDisappear( ) {
70
+ let defau = UserDefaults . standard
71
+ defau. setValue ( isDark, forKey: " DarkThemeTimer? " )
72
+ super. viewWillDisappear ( )
73
+ }
74
+
75
+ @objc func changeDark( ) {
76
+ background. material = NSVisualEffectView . Material. dark
77
+ TimerText . textColor = NSColor . white
78
+ hourLabel. textColor = NSColor . white
79
+ minuteLabel. textColor = NSColor . white
80
+ secondLabel. textColor = NSColor . white
81
+ HourText . textColor = NSColor . white
82
+ MinuteText . textColor = NSColor . white
83
+ SecondText . textColor = NSColor . white
84
+ isDark = true
85
+ }
86
+
87
+ @objc func changeLight( ) {
88
+ background. material = NSVisualEffectView . Material. mediumLight
89
+ TimerText . textColor = NSColor . black
90
+ hourLabel. textColor = NSColor . black
91
+ minuteLabel. textColor = NSColor . black
92
+ secondLabel. textColor = NSColor . black
93
+ HourText . textColor = NSColor . black
94
+ MinuteText . textColor = NSColor . black
95
+ SecondText . textColor = NSColor . black
96
+ isDark = false
97
+ }
98
+
56
99
func timerMain( ) -> Void {
57
100
if TimerText . stringValue == " 00:00:00 " {
58
101
timer. fireDate = Date . distantFuture
@@ -86,9 +129,12 @@ class TimerViewController : NSViewController, NSUserNotificationCenterDelegate{
86
129
}
87
130
88
131
}
89
-
90
132
91
- @IBAction func StartTimer( _ sender: NSButton ) {
133
+ @objc func start( ) {
134
+ StartTimer ( Any . self)
135
+ }
136
+
137
+ @IBAction func StartTimer( _ sender: Any ) {
92
138
if isStart== false {
93
139
isStart = true
94
140
if ( SecondText . stringValue. count> 10 || MinuteText . stringValue. count> 10 || HourText . stringValue. count> 10 ) {
@@ -128,16 +174,23 @@ class TimerViewController : NSViewController, NSUserNotificationCenterDelegate{
128
174
}
129
175
}
130
176
131
- @IBAction func PauseTimer( _ sender: NSButton ) {
177
+ @objc func pause( ) {
178
+ PauseTimer ( Any . self)
179
+ }
180
+
181
+ @IBAction func PauseTimer( _ sender: Any ) {
132
182
if isStart {
133
183
isPause = true
134
184
timer. fireDate = Date . distantFuture
135
185
NSSound ( named: " Pop.aiff " ) ? . play ( )
136
186
}
137
187
}
138
188
189
+ @objc func end( ) {
190
+ EndTimer ( Any . self)
191
+ }
139
192
140
- @IBAction func EndTimer( _ sender: NSButton ) {
193
+ @IBAction func EndTimer( _ sender: Any ) {
141
194
if isStart {
142
195
isStart = false
143
196
timer. fireDate = Date . distantFuture
0 commit comments