From cca15438561eec07c030fb8cc37d77bdfb3d98a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 17 Jan 2024 18:34:18 +0300 Subject: [PATCH] d --- Modules/MicX/Mic/src/Mic.K.swift | 1 + Modules/MicX/MicItem/src/MicItem.Shoulds.swift | 13 +++++++++++++ Modules/MicX/MicItem/src/MicItem.V.swift | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Modules/MicX/Mic/src/Mic.K.swift b/Modules/MicX/Mic/src/Mic.K.swift index e3f8441..e3893eb 100644 --- a/Modules/MicX/Mic/src/Mic.K.swift +++ b/Modules/MicX/Mic/src/Mic.K.swift @@ -3,5 +3,6 @@ public extension Mic { public static let activityDate = "Mic.activityDate" public static let isActive = "Mic.isActive" public static let MI = "Mic.Model.Item" + public static let timeout = "Mic.timeout" } } diff --git a/Modules/MicX/MicItem/src/MicItem.Shoulds.swift b/Modules/MicX/MicItem/src/MicItem.Shoulds.swift index a8552cf..69e8cd3 100644 --- a/Modules/MicX/MicItem/src/MicItem.Shoulds.swift +++ b/Modules/MicX/MicItem/src/MicItem.Shoulds.swift @@ -10,4 +10,17 @@ public extension MicItem { return nil } + + static func shouldResetTimeout(_ c: MicItemContext) -> (delay: Int, value: Bool)? { + if + c.activityDate.isRecent, + let end = c.activityDate.value + { + let now = Date() + let timeout = now < end + return (timeout, true) + } + + return nil + } } diff --git a/Modules/MicX/MicItem/src/MicItem.V.swift b/Modules/MicX/MicItem/src/MicItem.V.swift index 780eda9..a580518 100644 --- a/Modules/MicX/MicItem/src/MicItem.V.swift +++ b/Modules/MicX/MicItem/src/MicItem.V.swift @@ -5,11 +5,12 @@ extension MicItem { public struct V: View { var id: String? @StateObject var isActive = BusUI.Value(K.isActive, false) - let processors: [Any] + let proc: [Any] public init(_ id: String? = nil) { self.id = id - self.processors = [ + self.proc = [ + Bus.DelayV(shouldResetTimeout, K.MI, K.timeout) Bus.Sync(shouldResetActivity, K.MI, K.isActive), MicItem.Controller() ]