Просмотр исходного кода

Allow user to disable diagnostic type MDT messages except if loop is inactive for 10+ minutes, other pumpErrors cannot be disabled

kskandis 1 год назад
Родитель
Сommit
daabfd7819
2 измененных файлов с 13 добавлено и 4 удалено
  1. 6 2
      Trio/Sources/APS/APSManager.swift
  2. 7 2
      Trio/Sources/Modules/Main/MainStateModel.swift

+ 6 - 2
Trio/Sources/APS/APSManager.swift

@@ -50,8 +50,12 @@ enum APSError: LocalizedError {
         }
     }
 
-    static func pumpMatches(message: String) -> Bool {
-        message.contains(String(localized: "Pump Error")) || message.contains(String(localized: "Invalid Pump State")) || message
+    static func pumpErrorMatches(message: String) -> Bool {
+        message.contains(String(localized: "Pump Error"))
+    }
+
+    static func pumpWarningMatches(message: String) -> Bool {
+        message.contains(String(localized: "Invalid Pump State")) || message
             .contains("PumpMessage") || message
             .contains("PumpOpsError") || message.contains("RileyLink")
     }

+ 7 - 2
Trio/Sources/Modules/Main/MainStateModel.swift

@@ -218,17 +218,22 @@ extension Main {
             if message.title == "" {
                 switch message.type {
                 case .info:
-                    if message.content.range(of: "error", options: .caseInsensitive) != nil {
+                    if message.content.range(of: "error", options: .caseInsensitive) != nil || message.content
+                        .range(of: String(localized: "Error"), options: .caseInsensitive) != nil
+                    {
                         message.title = String(localized: "Error", comment: "Error title")
                     } else {
                         message.title = String(localized: "Info", comment: "Info title")
                     }
-                    if APSError.pumpMatches(message: message.content) {
+                    if APSError.pumpWarningMatches(message: message.content) {
                         message.subtype = .pump
                         let lastLoopMinutes = Int((Date().timeIntervalSince(apsManager.lastLoopDate) - 30) / 60) + 1
                         if lastLoopMinutes > 10 {
                             message.type = .error
                         }
+                    } else if APSError.pumpErrorMatches(message: message.content) {
+                        message.subtype = .pump
+                        message.type = .error
                     }
                 case .warning:
                     message.title = String(localized: "Warning", comment: "Warning title")