Skip to content

Commit ffff498

Browse files
authored
Merge pull request #661 from BrawlerXull/fix/home-screen-bugs
fix: stop logging sync credentials; fix waiting filter, UTC times, nightly widget crash, empty project
2 parents 90700d4 + bafae83 commit ffff498

11 files changed

Lines changed: 121 additions & 16 deletions

File tree

‎lib/app/modules/home/controllers/home_controller.dart‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import 'package:taskwarrior/app/utils/taskfunctions/comparator.dart';
2929
import 'package:taskwarrior/app/utils/taskfunctions/projects.dart';
3030
import 'package:taskwarrior/app/utils/taskfunctions/query.dart';
3131
import 'package:taskwarrior/app/utils/taskfunctions/tags.dart';
32+
import 'package:taskwarrior/app/utils/taskfunctions/waiting.dart';
3233
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
3334
import 'package:taskwarrior/app/v3/champion/replica.dart';
3435
import 'package:taskwarrior/app/v3/champion/models/task_for_replica.dart';
@@ -43,6 +44,7 @@ class HomeController extends GetxController {
4344
final SplashController splashController = Get.find<SplashController>();
4445
late Storage storage;
4546
final RxBool pendingFilter = false.obs;
47+
4648
/// Which status the list is filtered to: pending / completed / deleted /
4749
/// recurring.
4850
/// Supersedes [pendingFilter], which can only express the first two; that
@@ -263,11 +265,12 @@ class HomeController extends GetxController {
263265
queriedTasks.value = storage.data.completedData();
264266
}
265267

268+
// The switch is labelled "Hide Waiting" while on, so on means waiting
269+
// tasks are left out (Taskwarrior's default), not that only they show.
266270
if (waitingFilter.value) {
267271
var currentTime = DateTime.now();
268-
queriedTasks.value = queriedTasks
269-
.where((task) => task.wait != null && task.wait!.isAfter(currentTime))
270-
.toList();
272+
queriedTasks.value =
273+
queriedTasks.where((task) => !isWaiting(task, currentTime)).toList();
271274
}
272275

273276
if (projectFilter.value.isNotEmpty) {
@@ -736,8 +739,12 @@ class HomeController extends GetxController {
736739
HomeWidget.saveWidgetData(
737740
"themeMode", AppSettings.isDarkMode ? "dark" : "light");
738741
HomeWidget.updateWidget(
739-
androidName: "TaskWarriorWidgetProvider",
740-
iOSName: "TaskWarriorWidgets");
742+
qualifiedAndroidName: kAndroidWidgetProvider,
743+
iOSName: "TaskWarriorWidgets")
744+
.catchError((Object e) {
745+
debugPrint('Error updating widget theme: $e');
746+
return null;
747+
});
741748
// print("called and value is${isDarkModeOn.value}");
742749
}
743750

@@ -795,8 +802,7 @@ class HomeController extends GetxController {
795802
/// Which projects column the filter drawer is currently showing. The two sit
796803
/// behind mutually exclusive `Visibility` widgets, so only one of
797804
/// [projectsKey] / [projectsKeyTaskc] is ever laid out.
798-
bool get usesTaskchampionProjects =>
799-
taskchampion.value || taskReplica.value;
805+
bool get usesTaskchampionProjects => taskchampion.value || taskReplica.value;
800806

801807
void initFilterDrawerTour() {
802808
tutorialCoachMark = TutorialCoachMark(

‎lib/app/modules/home/controllers/widget.controller.dart‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ import 'package:taskwarrior/app/modules/splash/controllers/splash_controller.dar
1616
import 'package:taskwarrior/app/utils/taskfunctions/urgency.dart';
1717
// import 'package:taskwarrior/widgets/taskfunctions/datetime_differences.dart';
1818

19+
/// Fully qualified home-screen widget provider class.
20+
///
21+
/// home_widget otherwise prefixes the provider name with the application id,
22+
/// which is `com.ccextractor.taskwarriorflutter.nightly` for the nightly
23+
/// flavor, while the Kotlin class always lives in the base package; the
24+
/// lookup then fails with ClassNotFoundException.
25+
const String kAndroidWidgetProvider =
26+
'com.ccextractor.taskwarriorflutter.TaskWarriorWidgetProvider';
27+
1928
class WidgetController extends GetxController {
2029
final HomeController storageWidget = Get.find<HomeController>();
2130
late Storage storage;
@@ -181,8 +190,11 @@ class WidgetController extends GetxController {
181190

182191
Future updateWidget() async {
183192
try {
184-
return HomeWidget.updateWidget(
185-
name: 'TaskWarriorWidgetProvider', iOSName: 'TaskWarriorWidgets');
193+
// Awaited so a failure is caught here instead of surfacing as an
194+
// unhandled exception.
195+
return await HomeWidget.updateWidget(
196+
qualifiedAndroidName: kAndroidWidgetProvider,
197+
iOSName: 'TaskWarriorWidgets');
186198
} on PlatformException catch (exception) {
187199
debugPrint('Error Updating Widget. $exception');
188200
}

‎lib/app/modules/home/views/add_task_bottom_sheet_new.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ class AddTaskBottomSheet extends StatelessWidget {
391391
..priority = homeController.priority.value == 'X'
392392
? null
393393
: homeController.priority.value)
394-
.rebuild((t) => t..project = homeController.projectcontroller.text)
394+
.rebuild((t) => t
395+
..project = resolveProject(
396+
homeController.projectcontroller.text, t.project))
395397
.rebuild((t) =>
396398
t..wait = getWaitDate(homeController.selectedDates)?.toUtc())
397399
.rebuild((t) =>

‎lib/app/modules/home/views/home_page_app_bar.dart‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ class HomePageAppBar extends StatelessWidget implements PreferredSizeWidget {
136136
var c = await CredentialsStorage.getClientId();
137137
var e =
138138
await CredentialsStorage.getEncryptionSecret();
139-
debugPrint(
140-
"controller.taskReplica.value ${controller.taskReplica.value} Replica Credentials: c=$c e=$e");
139+
// Never log the credentials themselves; debugPrint
140+
// is persisted to the in-app Logs page.
141+
debugPrint("Replica refresh "
142+
"(clientId set: ${c != null}, "
143+
"encryptionSecret set: ${e != null})");
141144
if (c == null || e == null) {
142145
_showResultSnackBar(
143146
context,

‎lib/app/utils/taskfunctions/add_task_dialog_utils.dart‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ DateTime? getSchedDate(List<DateTime?> dates) {
4040
DateTime? getUntilDate(List<DateTime?> dates) {
4141
return dates[3];
4242
}
43+
44+
/// The project for a new task: the Project field when it has text, otherwise
45+
/// whatever the description set (e.g. `project:home`), otherwise none.
46+
String? resolveProject(String fieldText, String? parsedProject) {
47+
final String project = fieldText.trim();
48+
return project.isEmpty ? parsedProject : project;
49+
}

‎lib/app/utils/taskfunctions/datetime_differences.dart‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ String age(DateTime dt, {bool? use24HourFormat}) {
2525

2626
// Format the time part according to the format preference
2727
String timeFormat = format ? 'HH:mm' : 'hh:mm a';
28-
String formattedTime = DateFormat(timeFormat).format(dt);
28+
// Task dates are stored in UTC; show the clock time the user expects.
29+
String formattedTime = DateFormat(timeFormat).format(dt.toLocal());
2930

3031
return '$result ago ($formattedTime)';
3132
}
@@ -54,7 +55,8 @@ String when(DateTime dt, {bool? use24HourFormat}) {
5455

5556
// Format the time part according to the format preference
5657
String timeFormat = format ? 'HH:mm' : 'hh:mm a';
57-
String formattedTime = DateFormat(timeFormat).format(dt);
58+
// Task dates are stored in UTC; show the clock time the user expects.
59+
String formattedTime = DateFormat(timeFormat).format(dt.toLocal());
5860

5961
return '$result ($formattedTime)';
6062
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'package:taskwarrior/app/models/models.dart';
2+
3+
/// Whether [task] is waiting: hidden until its wait date, as in Taskwarrior.
4+
bool isWaiting(Task task, DateTime now) =>
5+
task.wait != null && task.wait!.isAfter(now);

‎lib/app/v3/champion/replica.dart‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Replica {
2525
// interprets. The desktop CLI is what acts on it.
2626
"recur",
2727
];
28+
2829
/// Create a task, returning null on success or the reason it was refused.
2930
///
3031
/// This used to answer with a success/failure sentinel that no caller read —
@@ -194,8 +195,11 @@ class Replica {
194195
var url = await CredentialsStorage.getApiUrl();
195196
var clientId = await CredentialsStorage.getClientId();
196197
var encryptionSecret = await CredentialsStorage.getEncryptionSecret();
197-
debugPrint(
198-
"Syncing Replica with url=$url clientId=$clientId encryptionSecret=$encryptionSecret");
198+
// Never log the client id or encryption secret: debugPrint output is
199+
// persisted to the debug-log database shown on the Logs page.
200+
debugPrint("Syncing Replica with url=$url "
201+
"(clientId set: ${clientId?.isNotEmpty ?? false}, "
202+
"encryptionSecret set: ${encryptionSecret?.isNotEmpty ?? false})");
199203
await sync_(
200204
taskdbDirPath: taskdbDirPath,
201205
url: url ?? "",

‎test/utils/taskfunctions/datetime_differences_test.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter_test/flutter_test.dart';
22
import 'package:get/get.dart';
3+
import 'package:intl/intl.dart';
34
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
45
import 'package:taskwarrior/app/utils/taskfunctions/datetime_differences.dart';
56

@@ -89,4 +90,19 @@ void main() {
8990
expect(when(dt), matches(r'.*\d{1,2}:\d{2}\)'));
9091
});
9192
});
93+
94+
group('time of day is shown in local time', () {
95+
// Task dates are stored in UTC. These only distinguish UTC from local
96+
// time when the test machine is not itself on UTC.
97+
final utc = DateTime.now().toUtc().subtract(const Duration(hours: 3));
98+
final local = DateFormat('hh:mm a').format(utc.toLocal());
99+
100+
test('age', () {
101+
expect(age(utc), endsWith('($local)'));
102+
});
103+
104+
test('when', () {
105+
expect(when(utc), endsWith('($local)'));
106+
});
107+
});
92108
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:taskwarrior/app/utils/taskfunctions/add_task_dialog_utils.dart';
3+
import 'package:taskwarrior/app/utils/taskfunctions/taskparser.dart';
4+
5+
void main() {
6+
test('an empty Project field leaves the project unset', () {
7+
expect(resolveProject('', null), isNull);
8+
expect(resolveProject(' ', null), isNull);
9+
});
10+
11+
test('the Project field is used when filled in', () {
12+
expect(resolveProject('home', null), 'home');
13+
expect(resolveProject(' home ', 'work'), 'home');
14+
});
15+
16+
test('an empty field keeps a project typed in the description', () {
17+
final parsed = taskParser('buy milk project:home');
18+
expect(resolveProject('', parsed.project), 'home');
19+
});
20+
}

0 commit comments

Comments
 (0)