Skip to content

Commit 5bf8d7c

Browse files
committed
Fix reboot timer bug
1 parent 3fc11b7 commit 5bf8d7c

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

SupportCompanion/Helpers/DeviceInfoHelpers.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,6 @@ class LastRebootMonitor {
190190
func startMonitoring(onUpdate: @escaping (Int) -> Void) {
191191
self.updateHandler = onUpdate
192192

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-
206193
// Perform the reboot check
207194
let lastRebootDays = getLastRebootDays()
208195
DispatchQueue.main.async {

SupportCompanion/ViewModels/DeviceInfoManager.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import Foundation
99
import Combine
1010

1111
class DeviceInfoManager: ObservableObject {
12-
private var timer: AnyCancellable?
12+
//private var timer: AnyCancellable?
13+
private var timer: Timer?
1314

1415
static let shared = DeviceInfoManager(
1516
deviceInfo: DeviceInfo(
@@ -34,17 +35,16 @@ class DeviceInfoManager: ObservableObject {
3435

3536
func startMonitoring() {
3637
Logger.shared.logDebug("Starting device info monitoring")
38+
timer?.invalidate()
3739
refresh()
38-
timer = Timer.publish(every: 86400, on: .main, in: .common)
39-
.autoconnect()
40-
.sink { _ in
41-
self.refresh()
42-
}
40+
timer = Timer.scheduledTimer(withTimeInterval: 86400, repeats: true) { _ in
41+
self.refresh()
42+
}
4343
}
4444

4545
func stopMonitoring() {
4646
Logger.shared.logDebug("Stopping device info monitoring")
47-
timer?.cancel()
47+
timer?.invalidate()
4848
}
4949

5050
func refresh() {

0 commit comments

Comments
 (0)