18
18
#include "services/crypto/crypto.h"
19
19
#include "cli/cli.h"
20
20
21
- #define IDLE_TIMEOUT (60000)
22
-
23
21
static void render_callback (Canvas * const canvas , void * ctx ) {
24
22
furi_assert (ctx );
25
23
PluginState * plugin_state = ctx ;
@@ -106,6 +104,17 @@ static bool totp_activate_initial_scene(PluginState* const plugin_state) {
106
104
return true;
107
105
}
108
106
107
+ static bool on_user_idle (void * context ) {
108
+ PluginState * plugin_state = context ;
109
+ if (plugin_state -> current_scene != TotpSceneAuthentication &&
110
+ plugin_state -> current_scene != TotpSceneStandby ) {
111
+ totp_scene_director_activate_scene (plugin_state , TotpSceneAuthentication );
112
+ return true;
113
+ }
114
+
115
+ return false;
116
+ }
117
+
109
118
static bool totp_plugin_state_init (PluginState * const plugin_state ) {
110
119
plugin_state -> gui = furi_record_open (RECORD_GUI );
111
120
plugin_state -> notification_app = furi_record_open (RECORD_NOTIFICATION );
@@ -127,10 +136,22 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
127
136
}
128
137
#endif
129
138
139
+ if (plugin_state -> pin_set ) {
140
+ plugin_state -> idle_timeout_context = idle_timeout_alloc (TOTP_AUTO_LOCK_IDLE_TIMEOUT_SEC , & on_user_idle , plugin_state );
141
+ idle_timeout_start (plugin_state -> idle_timeout_context );
142
+ } else {
143
+ plugin_state -> idle_timeout_context = NULL ;
144
+ }
145
+
130
146
return true;
131
147
}
132
148
133
149
static void totp_plugin_state_free (PluginState * plugin_state ) {
150
+ if (plugin_state -> idle_timeout_context != NULL ) {
151
+ idle_timeout_stop (plugin_state -> idle_timeout_context );
152
+ idle_timeout_free (plugin_state -> idle_timeout_context );
153
+ }
154
+
134
155
furi_record_close (RECORD_GUI );
135
156
furi_record_close (RECORD_NOTIFICATION );
136
157
furi_record_close (RECORD_DIALOGS );
@@ -184,26 +205,20 @@ int32_t totp_app() {
184
205
185
206
PluginEvent event ;
186
207
bool processing = true;
187
- uint32_t last_user_interaction_time = furi_get_tick ();
188
208
while (processing ) {
189
- FuriStatus event_status = furi_message_queue_get (event_queue , & event , 100 );
209
+ FuriStatus event_status = furi_message_queue_get (event_queue , & event , FuriWaitForever );
190
210
191
211
if (furi_mutex_acquire (plugin_state -> mutex , FuriWaitForever ) == FuriStatusOk ) {
192
212
if (event_status == FuriStatusOk ) {
193
- if (event .type == EventTypeKey ) {
194
- last_user_interaction_time = furi_get_tick ( );
213
+ if (event .type == EventTypeKey && plugin_state -> idle_timeout_context != NULL ) {
214
+ idle_timeout_report_activity ( plugin_state -> idle_timeout_context );
195
215
}
196
216
197
217
if (event .type == EventForceCloseApp ) {
198
218
processing = false;
199
219
} else {
200
220
processing = totp_scene_director_handle_event (& event , plugin_state );
201
221
}
202
- } else if (
203
- plugin_state -> pin_set && plugin_state -> current_scene != TotpSceneAuthentication &&
204
- plugin_state -> current_scene != TotpSceneStandby &&
205
- furi_get_tick () - last_user_interaction_time > IDLE_TIMEOUT ) {
206
- totp_scene_director_activate_scene (plugin_state , TotpSceneAuthentication );
207
222
}
208
223
209
224
view_port_update (view_port );
0 commit comments