mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 09:28:38 +00:00
Merge pull request #1 from maandagdev/hotfix/fixing-pomodoro-widget
Hotfix/fixing pomodoro widget
This commit is contained in:
commit
5f876acc72
@ -239,7 +239,7 @@ class LongPressGestureRecognizer: NSPressGestureRecognizer {
|
||||
|
||||
extension String {
|
||||
var defaultTouchbarAttributedString: NSAttributedString {
|
||||
let attrTitle = NSMutableAttributedString(string: self, attributes: [.foregroundColor: NSColor.white, .font: NSFont.systemFont(ofSize: 15, weight: .regular), .baselineOffset: 1])
|
||||
let attrTitle = NSMutableAttributedString(string: self, attributes: [.foregroundColor: NSColor.white, .font: NSFont.monospacedDigitSystemFont(ofSize: 15, weight: .regular), .baselineOffset: 1])
|
||||
attrTitle.setAlignment(.center, range: NSRange(location: 0, length: count))
|
||||
return attrTitle
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.25</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>297</string>
|
||||
<string>317</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@ -34,13 +34,15 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
case rest
|
||||
case none
|
||||
}
|
||||
//Vars are used for pausing the timer.
|
||||
private var started = false
|
||||
private var timerPaused: Bool = false;
|
||||
|
||||
private let defaultTitle = "🍅"
|
||||
private let defaultTitle = ""
|
||||
private let workTime: TimeInterval
|
||||
private let restTime: TimeInterval
|
||||
private var typeTime: TimeTypes = .none
|
||||
private var timer: DispatchSourceTimer?
|
||||
|
||||
private var timeLeft: Int = 0
|
||||
private var timeLeftString: String {
|
||||
return String(format: "%.2i:%.2i ", timeLeft / 60, timeLeft % 60)
|
||||
@ -62,13 +64,27 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
timer?.cancel()
|
||||
timer = nil
|
||||
}
|
||||
|
||||
@objc func startStopWork() {
|
||||
if !started {
|
||||
started = true;
|
||||
typeTime = .work
|
||||
startStopTimer()
|
||||
} else {
|
||||
if timerPaused {
|
||||
timerPaused = false;
|
||||
resumeTimer();
|
||||
} else {
|
||||
timerPaused = true;
|
||||
pauseTimer();
|
||||
|
||||
}
|
||||
}
|
||||
print("short")
|
||||
}
|
||||
|
||||
@objc func startStopRest() {
|
||||
print("looong")
|
||||
started = false;
|
||||
typeTime = .rest
|
||||
startStopTimer()
|
||||
}
|
||||
@ -77,6 +93,16 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
timer == nil ? start() : reset()
|
||||
}
|
||||
|
||||
func resumeTimer() {
|
||||
guard let timervalue = timer else { return }
|
||||
timervalue.resume();
|
||||
}
|
||||
|
||||
func pauseTimer() {
|
||||
guard let timervalue = timer else { return }
|
||||
timervalue.suspend();
|
||||
}
|
||||
|
||||
private func start() {
|
||||
timeLeft = Int(typeTime == .work ? workTime : restTime)
|
||||
let queue: DispatchQueue = DispatchQueue(label: "Timer")
|
||||
@ -99,8 +125,13 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
private func reset() {
|
||||
typeTime = .none
|
||||
timer?.cancel()
|
||||
if timerPaused {
|
||||
resumeTimer()
|
||||
}
|
||||
timer = nil
|
||||
title = defaultTitle
|
||||
timerPaused = false
|
||||
started = false
|
||||
}
|
||||
|
||||
private func tick() {
|
||||
@ -121,4 +152,6 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
notification.soundName = "Submarine"
|
||||
NSUserNotificationCenter.default.deliver(notification)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -12,7 +12,10 @@ import CoreLocation
|
||||
class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
||||
private let activity: NSBackgroundActivityScheduler
|
||||
private let unitsStr = "°C"
|
||||
private let iconsSource = ["Ясно": "☀️", "Малооблачно": "🌤", "Облачно с прояснениями": "⛅️", "Пасмурно": "☁️", "Небольшой дождь": "🌦", "Дождь": "🌧", "Ливень": "⛈", "Гроза": "🌩", "Дождь со снегом": "☔️", "Небольшой снег": "❄️", "Снег": "🌨", "Туман": "🌫"]
|
||||
private let iconsSource = [
|
||||
"Ясно": "☀️", "Малооблачно": "🌤", "Облачно с прояснениями": "⛅️", "Пасмурно": "☁️", "Небольшой дождь": "🌦", "Дождь": "🌧", "Ливень": "⛈", "Гроза": "🌩", "Дождь со снегом": "☔️", "Небольшой снег": "❄️", "Снег": "🌨", "Туман": "🌫",
|
||||
"Clear": "☀️", "Mostly clear": "🌤", "Partly cloudy": "⛅️", "Overcast": "☁️", "Light rain": "🌦", "Rain": "🌧", "Heavy rain": "⛈", "Storm": "🌩", "Sleet": "☔️", "Light snow": "❄️", "Snow": "🌨", "Fog": "🌫"
|
||||
]
|
||||
private var location: CLLocation!
|
||||
private var prevLocation: CLLocation!
|
||||
private var manager: CLLocationManager!
|
||||
|
||||
Loading…
Reference in New Issue
Block a user