From 78b43f5f63f8c5aacdcda366b5d9cadaa44e254a Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 11 Apr 2023 10:48:48 +0200 Subject: [PATCH] Adding more logs --- LeCountdown/AppDelegate.swift | 3 ++- LeCountdown/Conductor.swift | 2 ++ LeCountdown/Utils/Date+Extensions.swift | 8 ++++++++ LeCountdown/Views/ContentView.swift | 4 +++- LeCountdown/Views/LiveTimerListView.swift | 2 ++ LeCountdown/Views/LogsView.swift | 4 ++-- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/LeCountdown/AppDelegate.swift b/LeCountdown/AppDelegate.swift index 0ade17d..514fdca 100644 --- a/LeCountdown/AppDelegate.swift +++ b/LeCountdown/AppDelegate.swift @@ -9,6 +9,7 @@ import Foundation import UIKit import AVFoundation import FirebaseCore +import FirebaseCrashlytics class AppDelegate : NSObject, UIApplicationDelegate { @@ -84,8 +85,8 @@ extension AppDelegate: UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async { print("didReceive notification") + FileLogger.log("userNotificationCenter didReceive > cancelling sound player") let timerId = self._timerId(notificationId: response.notification.request.identifier) -// Conductor.maestro.cancelCountdown(id: timerId) Conductor.maestro.cancelSoundPlayer(id: timerId) } diff --git a/LeCountdown/Conductor.swift b/LeCountdown/Conductor.swift index e667704..0ac746e 100644 --- a/LeCountdown/Conductor.swift +++ b/LeCountdown/Conductor.swift @@ -166,6 +166,8 @@ class Conductor: ObservableObject { } func cancelCountdown(id: TimerID) { + + FileLogger.log("Cancel \(id)") CountdownScheduler.master.cancelCurrentNotifications(countdownId: id) self.cancelSoundPlayer(id: id) self.cancelledCountdowns.append(id) diff --git a/LeCountdown/Utils/Date+Extensions.swift b/LeCountdown/Utils/Date+Extensions.swift index 1dfe57d..7c639a9 100644 --- a/LeCountdown/Utils/Date+Extensions.swift +++ b/LeCountdown/Utils/Date+Extensions.swift @@ -22,6 +22,13 @@ extension Date { return df }() + static let dateTimeFormatter = { + let df = DateFormatter() + df.dateStyle = .short + df.timeStyle = .short + return df + }() + var startOfDay: Date { return Calendar.current.startOfDay(for: self) } @@ -36,5 +43,6 @@ extension Date { var formattedYear: String { return "\(self.year)" } var formattedMonth: String { return Date.monthYearFormatter.string(from: self) } var formattedDay: String { return Date.dayFormatter.string(from: self) } + var formattedDateTime: String { return Date.dateTimeFormatter.string(from: self) } } diff --git a/LeCountdown/Views/ContentView.swift b/LeCountdown/Views/ContentView.swift index 8a30fed..e6b343f 100644 --- a/LeCountdown/Views/ContentView.swift +++ b/LeCountdown/Views/ContentView.swift @@ -196,7 +196,9 @@ struct MainToolbarView: ToolbarContent { Image(systemName: "list.dash") } .sheet(isPresented: self.$showLogsSheet, content: { - LogsView() + NavigationStack { + LogsView().navigationTitle("Logs") + } }) if self.haveRecords() { Button { diff --git a/LeCountdown/Views/LiveTimerListView.swift b/LeCountdown/Views/LiveTimerListView.swift index 8c636e2..f603335 100644 --- a/LeCountdown/Views/LiveTimerListView.swift +++ b/LeCountdown/Views/LiveTimerListView.swift @@ -203,6 +203,8 @@ struct LiveCountdownView: View { } fileprivate func _actionHandler() { + + FileLogger.log("_actionHandler") withAnimation { if conductor.currentCountdowns[self.countdown.stringId] != nil { self._cancelCountdown() diff --git a/LeCountdown/Views/LogsView.swift b/LeCountdown/Views/LogsView.swift index afd23d2..df2e961 100644 --- a/LeCountdown/Views/LogsView.swift +++ b/LeCountdown/Views/LogsView.swift @@ -10,7 +10,7 @@ import SwiftUI struct LogsView: View { var body: some View { List { - ForEach(FileLogger.main.logs) { log in + ForEach(FileLogger.main.logs.reversed()) { log in LogView(log: log) } } @@ -24,7 +24,7 @@ struct LogView: View { var body: some View { VStack(alignment: .leading) { - Text(log.date, style: .time) + Text(log.date.formattedDateTime) .foregroundColor(.gray) Text(log.content) }.font(.footnote)