From 3a9073454c574b527410969ac2d2ed4fde50e685 Mon Sep 17 00:00:00 2001 From: MaandagDev Date: Tue, 10 Dec 2019 10:45:04 +0100 Subject: [PATCH 1/2] Fixed widget not showing up, also made it possible to pause the timer and reset it --- MTMR/CustomButtonTouchBarItem.swift | 2 +- MTMR/Info.plist | 2 +- MTMR/Widgets/PomodoroBarItem.swift | 77 ++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index 6b734d2..76b0ef2 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -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 } diff --git a/MTMR/Info.plist b/MTMR/Info.plist index 99603a5..fbbd4a0 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 0.25 CFBundleVersion - 297 + 317 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MTMR/Widgets/PomodoroBarItem.swift b/MTMR/Widgets/PomodoroBarItem.swift index 7b824f7..dc46c12 100644 --- a/MTMR/Widgets/PomodoroBarItem.swift +++ b/MTMR/Widgets/PomodoroBarItem.swift @@ -16,11 +16,11 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { case workTime case restTime } - + let container = try decoder.container(keyedBy: CodingKeys.self) let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime) let restTime = try container.decodeIfPresent(Double.self, forKey: .restTime) - + return ( item: .pomodoro(workTime: workTime ?? 1500.00, restTime: restTime ?? 300), action: .none, @@ -28,24 +28,26 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { parameters: [:] ) } - + private enum TimeTypes { case work case rest case none } - - private let defaultTitle = "🍅" + //Vars are used for pausing the timer. + private var started = false + private var timerPaused: Bool = false; + + 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) + return String(format: "%.2i:%.2i ", timeLeft / 60, timeLeft % 60) } - + init(identifier: NSTouchBarItem.Identifier, workTime: TimeInterval, restTime: TimeInterval) { self.workTime = workTime self.restTime = restTime @@ -53,30 +55,54 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { tapClosure = { [weak self] in self?.startStopWork() } longTapClosure = { [weak self] in self?.startStopRest() } } - + required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") } - + deinit { timer?.cancel() timer = nil } - @objc func startStopWork() { - typeTime = .work - startStopTimer() + 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() } - + func startStopTimer() { 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") @@ -84,25 +110,30 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { timer?.schedule(deadline: .now(), repeating: .seconds(1), leeway: .never) timer?.setEventHandler(handler: tick) timer?.resume() - + NSSound.beep() } - + private func finish() { if typeTime != .none { sendNotification() } - + reset() } - + private func reset() { typeTime = .none timer?.cancel() + if timerPaused { + resumeTimer() + } timer = nil title = defaultTitle + timerPaused = false + started = false } - + private func tick() { timeLeft -= 1 DispatchQueue.main.async { @@ -113,7 +144,7 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { } } } - + private func sendNotification() { let notification: NSUserNotification = NSUserNotification() notification.title = "Pomodoro" @@ -121,4 +152,6 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { notification.soundName = "Submarine" NSUserNotificationCenter.default.deliver(notification) } + + } From 712448f207f568d88402f0e9df575fcd7e23a997 Mon Sep 17 00:00:00 2001 From: bobrosoft Date: Mon, 30 Dec 2019 11:51:27 +0400 Subject: [PATCH 2/2] YandexWeather: update matching array with English translations as some users getting English version instead of Russian --- MTMR/Widgets/YandexWeatherBarItem.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MTMR/Widgets/YandexWeatherBarItem.swift b/MTMR/Widgets/YandexWeatherBarItem.swift index c6a050b..740ea2c 100644 --- a/MTMR/Widgets/YandexWeatherBarItem.swift +++ b/MTMR/Widgets/YandexWeatherBarItem.swift @@ -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!