fix: Enable logging in production

This commit is contained in:
Anton Stubenbord
2023-10-19 18:26:02 +02:00
parent 7d1c0dffe4
commit 520bfbd7b1
104 changed files with 632 additions and 257 deletions

View File

@@ -1,7 +1,7 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:paperless_mobile/features/notifications/models/notification_actions.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_tap/notification_tap_response_payload.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_tap/open_downloaded_document_payload.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_tap/open_directory_notification_response_payload.dart';
class NotificationTapResponsePayloadConverter
implements
@@ -11,8 +11,8 @@ class NotificationTapResponsePayloadConverter
NotificationTapResponsePayload fromJson(Map<String, dynamic> json) {
final type = NotificationResponseOpenAction.values.byName(json['type']);
switch (type) {
case NotificationResponseOpenAction.openDownloadedDocumentPath:
return OpenDownloadedDocumentPayload.fromJson(
case NotificationResponseOpenAction.openDirectory:
return OpenDirectoryNotificationResponsePayload.fromJson(
json,
);
}

View File

@@ -7,5 +7,5 @@ enum NotificationResponseButtonAction {
@JsonEnum()
enum NotificationResponseOpenAction {
openDownloadedDocumentPath;
openDirectory;
}

View File

@@ -1,6 +1,7 @@
enum NotificationChannel {
task("task_channel", "Paperless tasks"),
documentDownload("document_download_channel", "Document downloads");
documentDownload("document_download_channel", "Document downloads"),
fileDownload("file_download_channel", "File downloads");
final String id;
final String name;

View File

@@ -0,0 +1,22 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:paperless_mobile/features/notifications/models/notification_actions.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_tap/notification_tap_response_payload.dart';
part 'open_directory_notification_response_payload.g.dart';
@JsonSerializable()
class OpenDirectoryNotificationResponsePayload
extends NotificationTapResponsePayload {
final String filePath;
OpenDirectoryNotificationResponsePayload({
required this.filePath,
super.type = NotificationResponseOpenAction.openDirectory,
});
factory OpenDirectoryNotificationResponsePayload.fromJson(
Map<String, dynamic> json) =>
_$OpenDirectoryNotificationResponsePayloadFromJson(json);
@override
Map<String, dynamic> toJson() =>
_$OpenDirectoryNotificationResponsePayloadToJson(this);
}

View File

@@ -1,19 +0,0 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:paperless_mobile/features/notifications/models/notification_actions.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_tap/notification_tap_response_payload.dart';
part 'open_downloaded_document_payload.g.dart';
@JsonSerializable()
class OpenDownloadedDocumentPayload extends NotificationTapResponsePayload {
final String filePath;
OpenDownloadedDocumentPayload({
required this.filePath,
super.type = NotificationResponseOpenAction.openDownloadedDocumentPath,
});
factory OpenDownloadedDocumentPayload.fromJson(Map<String, dynamic> json) =>
_$OpenDownloadedDocumentPayloadFromJson(json);
@override
Map<String, dynamic> toJson() => _$OpenDownloadedDocumentPayloadToJson(this);
}

View File

@@ -6,10 +6,10 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:open_filex/open_filex.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/notifications/converters/notification_tap_response_payload.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_action/create_document_success_payload.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_tap/open_downloaded_document_payload.dart';
import 'package:paperless_mobile/features/notifications/models/notification_actions.dart';
import 'package:paperless_mobile/features/notifications/models/notification_channels.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_action/create_document_success_payload.dart';
import 'package:paperless_mobile/features/notifications/models/notification_payloads/notification_tap/open_directory_notification_response_payload.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
class LocalNotificationService {
@@ -48,6 +48,31 @@ class LocalNotificationService {
}
Future<void> notifyFileDownload({
required String filePath,
}) async {
await _plugin.show(
filePath.hashCode,
filePath,
"File download complete.",
NotificationDetails(
android: AndroidNotificationDetails(
NotificationChannel.fileDownload.id + "_${filePath.hashCode}",
NotificationChannel.fileDownload.name,
importance: Importance.max,
priority: Priority.high,
showProgress: false,
when: DateTime.now().millisecondsSinceEpoch,
category: AndroidNotificationCategory.status,
icon: 'file_download_done',
),
),
payload: jsonEncode(
OpenDirectoryNotificationResponsePayload(filePath: filePath)
.toJson()),
);
}
Future<void> notifyDocumentDownload({
required DocumentModel document,
required String filename,
required String filePath,
@@ -89,7 +114,7 @@ class LocalNotificationService {
),
),
payload: jsonEncode(
OpenDownloadedDocumentPayload(
OpenDirectoryNotificationResponsePayload(
filePath: filePath,
).toJson(),
),
@@ -139,7 +164,7 @@ class LocalNotificationService {
),
),
payload: jsonEncode(
OpenDownloadedDocumentPayload(filePath: filePath).toJson(),
OpenDirectoryNotificationResponsePayload(filePath: filePath).toJson(),
),
);
}
@@ -281,9 +306,10 @@ class LocalNotificationService {
NotificationResponse response,
) {
switch (type) {
case NotificationResponseOpenAction.openDownloadedDocumentPath:
final payload = OpenDownloadedDocumentPayload.fromJson(
jsonDecode(response.payload!));
case NotificationResponseOpenAction.openDirectory:
final payload = OpenDirectoryNotificationResponsePayload.fromJson(
jsonDecode(response.payload!),
);
OpenFilex.open(payload.filePath);
break;
}