Skip to content

Commit d1a9e0c

Browse files
author
Inderjeet Singh
committed
fix(taskserver): resolve bugs and improve CCSync v3 integration
1 parent 66aef29 commit d1a9e0c

15 files changed

Lines changed: 197 additions & 23 deletions

File tree

lib/app/modules/home/views/show_tasks.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,17 @@ class TaskViewBuilder extends StatelessWidget {
230230
TaskDatabase taskDatabase = TaskDatabase();
231231
await taskDatabase.open();
232232
taskDatabase.markTaskAsCompleted(uuid);
233-
completeTask('email', uuid);
233+
try {
234+
await completeTask('email', uuid);
235+
} catch (e) {
236+
debugPrint('Error completing task on server: $e');
237+
Get.snackbar(
238+
'Sync Error',
239+
'Failed to mark task complete on server',
240+
snackPosition: SnackPosition.BOTTOM,
241+
duration: const Duration(seconds: 3),
242+
);
243+
}
234244
}
235245

236246
void _markTaskAsDeleted(String uuid) async {

lib/app/modules/manage_task_champion_creds/controllers/manage_task_champion_creds_controller.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:get/get.dart';
55
import 'package:shared_preferences/shared_preferences.dart';
66
import 'package:taskwarrior/app/modules/splash/controllers/splash_controller.dart';
77
import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart';
8-
import 'package:taskwarrior/app/v3/net/origin.dart';
98
import 'package:http/http.dart' as http;
109

1110
class ManageTaskChampionCredsController extends GetxController {
@@ -46,11 +45,11 @@ class ManageTaskChampionCredsController extends GetxController {
4645
String encryptionSecret = encryptionSecretController.text;
4746
try {
4847
String url =
49-
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
48+
'$baseUrl/tasks?email=email&origin=$baseUrl&UUID=$uuid&encryptionSecret=$encryptionSecret';
5049

5150
var response = await http.get(Uri.parse(url), headers: {
5251
"Content-Type": "application/json",
53-
}).timeout(const Duration(seconds: 10000));
52+
}).timeout(const Duration(seconds: 10));
5453
debugPrint("Fetch tasks response: ${response.statusCode}");
5554
debugPrint("Fetch tasks body: ${response.body}");
5655
if (response.statusCode == 200) {

lib/app/modules/profile/views/profile_view.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ class ProfileView extends GetView<ProfileController> {
8383
currentProfileKey: controller.currentProfileKey,
8484
addNewProfileKey: controller.addNewProfileKey,
8585
manageSelectedProfileKey: controller.manageSelectedProfileKey,
86+
getModeLabel: (profile) {
87+
switch (controller.profilesWidget.getMode(profile)) {
88+
case 'TW3C':
89+
return 'Taskchampion (v3)';
90+
case 'TW3':
91+
return 'CCSync (v3)';
92+
default:
93+
return 'TaskServer';
94+
}
95+
},
8696
controller.profilesMap,
8797
controller.currentProfile.value,
8898
controller.profilesWidget.addProfile,

lib/app/modules/profile/views/profiles_list.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ProfilesList extends StatelessWidget {
1919
required this.currentProfileKey,
2020
required this.addNewProfileKey,
2121
required this.manageSelectedProfileKey,
22+
this.getModeLabel,
2223
super.key,
2324
});
2425

@@ -32,6 +33,7 @@ class ProfilesList extends StatelessWidget {
3233
final void Function(String) copy;
3334
final void Function(dynamic) delete;
3435
final void Function(String) changeMode;
36+
final String Function(String)? getModeLabel;
3537
final GlobalKey currentProfileKey;
3638
final GlobalKey addNewProfileKey;
3739
final GlobalKey manageSelectedProfileKey;
@@ -197,6 +199,17 @@ class ProfilesList extends StatelessWidget {
197199
color: AppSettings.isDarkMode
198200
? TaskWarriorColors.kprimaryTextColor
199201
: TaskWarriorColors.kLightPrimaryTextColor)),
202+
subtitle: getModeLabel != null
203+
? Text(
204+
getModeLabel!(profileId),
205+
style: TextStyle(
206+
color: AppSettings.isDarkMode
207+
? Colors.grey[400]
208+
: Colors.grey[700],
209+
fontSize: 12.0,
210+
),
211+
)
212+
: null,
200213
onTap: () {
201214
changeMode(profileId);
202215
},

lib/app/v3/db/update.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ Future<void> updateTasksInDatabase(List<TaskForC> tasks) async {
7777
? localTask.tags!.map((e) => e.toString()).toList()
7878
: []);
7979
if (localTask.status == 'completed') {
80-
completeTask('email', localTask.uuid!);
80+
try {
81+
await completeTask('email', localTask.uuid!);
82+
} catch (e) {
83+
debugPrint('Failed to complete task on server: $e');
84+
}
8185
} else if (localTask.status == 'deleted') {
8286
deleteTask('email', localTask.uuid!);
8387
}

lib/app/v3/models/task.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ class TaskForC {
6464
recur: json['recur'],
6565
depends:
6666
json['depends']?.map<String>((d) => d.toString()).toList() ?? [],
67-
annotations: <Annotation>[]);
67+
annotations: (json['annotations'] as List?)
68+
?.map((a) => Annotation.fromJson(a as Map<String, dynamic>))
69+
.toList() ??
70+
[]);
6871
}
6972

7073
Map<String, dynamic> toJson() {

lib/app/v3/net/complete.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import 'dart:convert';
22
import 'package:http/http.dart' as http;
3-
import 'package:flutter/material.dart';
3+
import 'package:flutter/foundation.dart';
44
import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart';
5-
import 'package:path/path.dart';
65

7-
Future<void> completeTask(String email, String taskUuid) async {
6+
Future<void> completeTask(String email, String taskUuid,
7+
{http.Client? client}) async {
8+
final httpClient = client ?? http.Client();
89
var c = await CredentialsStorage.getClientId();
910
var e = await CredentialsStorage.getEncryptionSecret();
1011
var baseUrl = await CredentialsStorage.getApiUrl();
@@ -17,7 +18,7 @@ Future<void> completeTask(String email, String taskUuid) async {
1718
});
1819

1920
try {
20-
final response = await http.post(
21+
final response = await httpClient.post(
2122
url,
2223
headers: {
2324
'Content-Type': 'application/json',
@@ -29,13 +30,10 @@ Future<void> completeTask(String email, String taskUuid) async {
2930
debugPrint('Task completed successfully on server');
3031
} else {
3132
debugPrint('Failed to complete task: ${response.statusCode}');
32-
ScaffoldMessenger.of(context as BuildContext).showSnackBar(const SnackBar(
33-
content: Text(
34-
"Failed to complete task!",
35-
style: TextStyle(color: Colors.red),
36-
)));
33+
throw Exception('Failed to complete task: ${response.statusCode}');
3734
}
38-
} catch (e) {
39-
debugPrint('Error completing task: $e');
35+
} catch (e, s) {
36+
debugPrint('Error completing task: $e\n$s');
37+
rethrow;
4038
}
4139
}

lib/app/v3/net/fetch.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import 'dart:convert';
33
import 'package:flutter/material.dart';
44
import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart';
55
import 'package:taskwarrior/app/v3/models/task.dart';
6-
import 'package:taskwarrior/app/v3/net/origin.dart';
76
import 'package:http/http.dart' as http;
87

98
Future<List<TaskForC>> fetchTasks(String uuid, String encryptionSecret) async {
109
var baseUrl = await CredentialsStorage.getApiUrl();
1110
try {
1211
String url =
13-
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
12+
'$baseUrl/tasks?email=email&origin=$baseUrl&UUID=$uuid&encryptionSecret=$encryptionSecret';
1413

1514
var response = await http.get(Uri.parse(url), headers: {
1615
"Content-Type": "application/json",

lib/app/v3/net/origin.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
String origin = 'http://localhost:8080';
1+
import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart';
2+
3+
Future<String> getOrigin() async => await CredentialsStorage.getApiUrl() ?? '';

linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <file_selector_linux/file_selector_plugin.h>
1010
#include <flutter_timezone/flutter_timezone_plugin.h>
11+
#include <gtk/gtk_plugin.h>
1112
#include <url_launcher_linux/url_launcher_plugin.h>
1213

1314
void fl_register_plugins(FlPluginRegistry* registry) {
@@ -17,6 +18,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
1718
g_autoptr(FlPluginRegistrar) flutter_timezone_registrar =
1819
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterTimezonePlugin");
1920
flutter_timezone_plugin_register_with_registrar(flutter_timezone_registrar);
21+
g_autoptr(FlPluginRegistrar) gtk_registrar =
22+
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
23+
gtk_plugin_register_with_registrar(gtk_registrar);
2024
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
2125
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
2226
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

0 commit comments

Comments
 (0)