initialize method
Initialize and set up the app controller.
Caches app tasks based on the studyDeploymentId
, if
Settings().saveAppTaskQueue
is true
.
If enableNotifications
is true, a notification will be added to
the phone's notification system when a task is enqueued via the
enqueue method.
Implementation
Future<void> initialize({bool enableNotifications = true}) async {
if (Settings().saveAppTaskQueue) {
// listen to events and save the queue every time it is modified
userTaskEvents.listen((_) async => await saveQueue());
}
// set up a timer which cleans up in the queue once an hour
Timer.periodic(const Duration(hours: 1), (timer) {
for (var task in userTasks) {
if (task.expiresIn != null && task.expiresIn!.isNegative) {
expire(task.id);
}
}
});
notificationsEnabled = enableNotifications;
if (notificationsEnabled) {
await SmartPhoneClientManager().notificationController?.initialize();
}
}