This repository was archived by the owner on Oct 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,21 @@ struct ActivityMonitor {
66
66
}
67
67
} ( )
68
68
69
+ async let userDefaultsTask : ( ) = { @MainActor in
70
+ let store = UserDefaults . standard
71
+ for await value in store. updates ( forKeyPath: " reset " , type: Bool . self, initial: true ) {
72
+ logger. log ( " Received UserDefaults \" reset \" change " )
73
+ if value == true {
74
+ state. deactivate ( )
75
+ state. activate ( )
76
+ }
77
+ if value != nil {
78
+ logger. debug ( " Cleaning up \" reset \" key " )
79
+ store. removeObject ( forKey: " reset " )
80
+ }
81
+ }
82
+ } ( )
83
+
69
84
while !Task. isCancelled {
70
85
let lastUserEvent = secondsSinceLastUserEvent ( )
71
86
let idleRemaining = configuration. userIdle - lastUserEvent
@@ -89,6 +104,7 @@ struct ActivityMonitor {
89
104
}
90
105
91
106
await notificationsTask
107
+ await userDefaultsTask
92
108
93
109
assert ( Task . isCancelled)
94
110
try Task . checkCancellation ( )
Original file line number Diff line number Diff line change @@ -80,6 +80,21 @@ struct ActivityMonitor {
80
80
}
81
81
} ( )
82
82
83
+ async let userDefaultsTask : ( ) = { @MainActor in
84
+ let store = UserDefaults . standard
85
+ for await value in store. updates ( forKeyPath: " reset " , type: Bool . self, initial: true ) {
86
+ logger. log ( " Received UserDefaults \" reset \" change " )
87
+ if value == true {
88
+ state. deactivate ( )
89
+ state. activate ( )
90
+ }
91
+ if value != nil {
92
+ logger. debug ( " Cleaning up \" reset \" key " )
93
+ store. removeObject ( forKey: " reset " )
94
+ }
95
+ }
96
+ } ( )
97
+
83
98
let notificationNames = [
84
99
UIApplication . didEnterBackgroundNotification,
85
100
UIApplication . willEnterForegroundNotification,
@@ -143,6 +158,7 @@ struct ActivityMonitor {
143
158
}
144
159
145
160
try await driftTask
161
+ await userDefaultsTask
146
162
147
163
assert ( Task . isCancelled)
148
164
try Task . checkCancellation ( )
You can’t perform that action at this time.
0 commit comments