mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 22:07:53 -06:00
fix: Enable logging in production
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ enum NotificationResponseButtonAction {
|
||||
|
||||
@JsonEnum()
|
||||
enum NotificationResponseOpenAction {
|
||||
openDownloadedDocumentPath;
|
||||
openDirectory;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user