Skip to content

Commit

Permalink
fix: Fix task being identified as a quick share
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Sep 7, 2023
1 parent b731cee commit 0d118f2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ class _ActiveSharesSheetState extends State<ActiveSharesSheet>
Iterable<Task> get quickShareTasks {
final taskService = context.read<TaskService>();

return taskService.tasks
.where((task) => task.deleteAfterRun && task.timers.length <= 1);
return taskService.tasks.where((task) => task.isQuickShare);
}

Future<bool> getAreSomeTasksRunning() async {
Expand Down
3 changes: 1 addition & 2 deletions lib/screens/locations_overview_screen_widgets/TaskTile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class _TaskTileState extends State<TaskTile> with TaskLinkGenerationMixin {

return PlatformListTile(
title: Text(widget.task.name),
subtitle: widget.task.timers.length == 1 &&
widget.task.timers[0] is DurationTimer &&
subtitle: widget.task.isFiniteQuickShare &&
(widget.task.timers[0] as DurationTimer).startDate != null
? Text(
formatStartDate(
Expand Down
13 changes: 9 additions & 4 deletions lib/services/task_service/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ class Task extends ChangeNotifier with LocationBase {
);
}

TaskCryptography get cryptography => TaskCryptography(
this,
_encryptionPassword,
);
TaskCryptography get cryptography =>
TaskCryptography(this, _encryptionPassword);

TaskPublisher get publisher => TaskPublisher(this);

Expand Down Expand Up @@ -372,6 +370,13 @@ class Task extends ChangeNotifier with LocationBase {
limit: limit,
);

bool get isQuickShare => isInfiniteQuickShare || isFiniteQuickShare;

bool get isInfiniteQuickShare => deleteAfterRun && timers.isEmpty;

bool get isFiniteQuickShare =>
deleteAfterRun && timers.length == 1 && timers[0] is DurationTimer;

@override
void dispose() {
_encryptionPassword.destroy();
Expand Down
11 changes: 6 additions & 5 deletions lib/services/task_service/task_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TaskService extends ChangeNotifier {
// await all `toJson` functions
final data = await Future.wait<Map<String, dynamic>>(
_tasks.map(
(task) => task.toJSON(),
(task) => task.toJSON(),
),
);

Expand Down Expand Up @@ -102,13 +102,14 @@ class TaskService extends ChangeNotifier {
for (final task in tasks) {
final isRunning = await task.isRunning();
final shouldRun = await task.shouldRunNow();
final isQuickShare = task.deleteAfterRun &&
task.timers.length == 1 &&
task.timers[0] is DurationTimer;

if (isQuickShare) {
if (task.isInfiniteQuickShare) {
// Infinite quick shares are completely user controlled.
// Nothing to do here.
} else if (task.isFiniteQuickShare) {
final durationTimer = task.timers[0] as DurationTimer;

// Time is over, remove task.
if (durationTimer.startDate != null && !shouldRun) {
FlutterLogs.logInfo(LOG_TAG, "Task Service", "Removing task.");

Expand Down

0 comments on commit 0d118f2

Please sign in to comment.