File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ func getLastRebootDays() -> Int? {
83
83
// Calculate the difference in days
84
84
let calendar = Calendar . current
85
85
let daysSinceReboot = calendar. dateComponents ( [ . day] , from: bootDate, to: currentDate) . day
86
-
86
+
87
87
return daysSinceReboot
88
88
}
89
89
@@ -180,3 +180,33 @@ class IPAddressMonitor {
180
180
monitor. cancel ( )
181
181
}
182
182
}
183
+
184
+ class LastRebootMonitor {
185
+ static let shared = LastRebootMonitor ( )
186
+ private var updateHandler : ( ( Int ) -> Void ) ?
187
+
188
+ private init ( ) { }
189
+
190
+ func startMonitoring( onUpdate: @escaping ( Int ) -> Void ) {
191
+ self . updateHandler = onUpdate
192
+
193
+ // Check if 24 hours have passed since the last update
194
+ let lastRunKey = " LastRebootMonitorLastRun "
195
+ let defaults = UserDefaults . standard
196
+ let now = Date ( )
197
+
198
+ if let lastRun = defaults. object ( forKey: lastRunKey) as? Date , now. timeIntervalSince ( lastRun) < 86400 {
199
+ // 24 hours haven't passed, skip this run
200
+ return
201
+ }
202
+
203
+ // Update the last run time
204
+ defaults. set ( now, forKey: lastRunKey)
205
+
206
+ // Perform the reboot check
207
+ let lastRebootDays = getLastRebootDays ( )
208
+ DispatchQueue . main. async {
209
+ self . updateHandler ? ( lastRebootDays ?? 0 )
210
+ }
211
+ }
212
+ }
You can’t perform that action at this time.
0 commit comments