Browse Source

Share todays and yesterdays log file.

Jonas Björkert 1 năm trước cách đây
mục cha
commit
321e9e3520

+ 13 - 3
LoopFollow/Log/LogManager.swift

@@ -73,11 +73,21 @@ class LogManager {
         }
         }
     }
     }
 
 
-    var currentLogFileURL: URL {
-        let today = dateFormatter.string(from: Date())
-        return logDirectory.appendingPathComponent("LoopFollow \(today).log")
+    func logFileURL(for date: Date) -> URL {
+        let dateString = dateFormatter.string(from: date)
+        return logDirectory.appendingPathComponent("LoopFollow \(dateString).log")
+    }
+
+    func logFilesForTodayAndYesterday() -> [URL] {
+        let today = logFileURL(for: Date())
+        let yesterday = logFileURL(for: Calendar.current.date(byAdding: .day, value: -1, to: Date())!)
+        return [today, yesterday].filter { fileManager.fileExists(atPath: $0.path) }
     }
     }
 
 
+    var currentLogFileURL: URL {
+        return logFileURL(for: Date())
+    }
+    
     private func append(_ message: String, to fileURL: URL) {
     private func append(_ message: String, to fileURL: URL) {
         if !fileManager.fileExists(atPath: fileURL.path) {
         if !fileManager.fileExists(atPath: fileURL.path) {
             fileManager.createFile(atPath: fileURL.path, contents: nil, attributes: nil)
             fileManager.createFile(atPath: fileURL.path, contents: nil, attributes: nil)

+ 3 - 4
LoopFollow/ViewControllers/SettingsViewController.swift

@@ -379,11 +379,10 @@ class SettingsViewController: FormViewController, NightscoutSettingsViewModelDel
     }
     }
 
 
     private func shareLogs() {
     private func shareLogs() {
-        let logManager = LogManager.shared
-        let logFileURL = logManager.currentLogFileURL
+        let logFilesToShare = LogManager.shared.logFilesForTodayAndYesterday()
 
 
-        if FileManager.default.fileExists(atPath: logFileURL.path) {
-            let activityViewController = UIActivityViewController(activityItems: [logFileURL], applicationActivities: nil)
+        if !logFilesToShare.isEmpty {
+            let activityViewController = UIActivityViewController(activityItems: logFilesToShare, applicationActivities: nil)
             activityViewController.popoverPresentationController?.sourceView = self.view
             activityViewController.popoverPresentationController?.sourceView = self.view
             present(activityViewController, animated: true, completion: nil)
             present(activityViewController, animated: true, completion: nil)
         } else {
         } else {