Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notification issue #121

Merged
merged 8 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
},
"verificationNotification": {
"title": "جارٍ التحقق",
"validatingMetaData": "التحقق من صحة البيانات الوصفية"
"validatingMetaData": "التحقق من صحة البيانات الوصفية",
"hashing": "يتم حساب قيمة التجزئة"
}
}
13 changes: 11 additions & 2 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: non_constant_identifier_names, constant_identifier_names

import 'dart:ui';
import 'package:flutter_dotenv/flutter_dotenv.dart';

final String GET_KEY_URL = dotenv.env["GET_KEY_URL"] ?? "";
final String CHECK_KEY_URL = dotenv.env["CHECK_KEY_URL"] ?? "";
final String SIGN_URL = dotenv.env["SIGN_URL"] ?? "";
final String VERIFY_URL = dotenv.env["VERIFY_URL"] ?? "";
final String SENTRY_DSN = dotenv.env["SENTRY_DSN"] ?? "";
const List<Locale> SUPPORTED_LOCALS = [
Locale("en"),
Locale("de"),
Locale("sn"),
Locale("fr"),
Locale("jp"),
Locale("zn"),
Locale("ar")
];

// ignore: constant_identifier_names
const String WIKI_URL = "https://github.com/Flajt/decentproof-app/wiki/FAQ";
17 changes: 9 additions & 8 deletions lib/features/hashing/bloc/PreparationBloc/PreparationBloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class PreparationBloc extends Bloc<MetaDataEvents, PreparationState> {
"instructions", "audio::${event.filePath}");
await foregroundService.start(
startPreperationForegroundService,
"perperationNotification.title".tr(),
"perperationNotification.initialDescription".tr());
tr("perperationNotification.title"),
tr("perperationNotification.initalDescription"));
ReceivePort port = await foregroundService.getReceivePort();
final stream = port.asBroadcastStream();
await emit.forEach(stream, onData: (message) {
Expand Down Expand Up @@ -122,10 +122,11 @@ class PreparationBloc extends Bloc<MetaDataEvents, PreparationState> {
try {
final path = await imageSavingService.saveFile();
await foregroundService.setData("instructions", "image::$path");
await foregroundService.start(
startPreperationForegroundService,
"perperationNotification.title".tr(),
"perperationNotification.initialDescription".tr());
final notificationTitle = tr("perperationNotification.title");
final notificationBody =
tr("perperationNotification.initalDescription");
await foregroundService.start(startPreperationForegroundService,
notificationTitle, notificationBody);
ReceivePort port = await foregroundService.getReceivePort();
final stream = port.asBroadcastStream();
await emit.forEach(stream, onData: (message) {
Expand Down Expand Up @@ -177,8 +178,8 @@ class PreparationBloc extends Bloc<MetaDataEvents, PreparationState> {
await foregroundService.setData("instructions", "video::$path");
await foregroundService.start(
startPreperationForegroundService,
"perperationNotification.title".tr(),
"perperationNotification.initialDescription".tr());
tr("perperationNotification.title"),
tr("perperationNotification.initalDescription"));
ReceivePort port = await foregroundService.getReceivePort();
final stream = port.asBroadcastStream();
await emit.forEach(stream, onData: (message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:decentproof/features/metadata/interfaces/IMetaDataService.dart';
import 'package:decentproof/features/metadata/models/LocationModel.dart';
import 'package:decentproof/shared/util/initSentry.dart';
import 'package:decentproof/shared/util/register.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
import 'package:get_it/get_it.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Expand All @@ -21,7 +21,7 @@ class PreperationTaskHandler extends TaskHandler {
void onStart(DateTime timestamp, SendPort? sendPort) async {
DartPluginRegistrant.ensureInitialized();
try {
await EasyLocalization.ensureInitialized();
await dotenv.load();
await initSentry();
await registar();
final getIt = GetIt.I;
Expand Down Expand Up @@ -173,7 +173,6 @@ class PreperationTaskHandler extends TaskHandler {
// Note that the app will only route to "/resume-route" when it is exited so
// it will usually be necessary to send a message through the send port to
// signal it to restore state when the app is already started.
FlutterForegroundTask.launchApp("/");
}

Future<void> sendAUpdateProgress(SendPort? sendPort, String step,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import 'package:decentproof/features/verification/models/VerificationStatusModel
import 'package:decentproof/shared/foregroundService/IForegroundService.dart';
import 'package:decentproof/shared/interface/IHashLogic.dart';
import 'package:decentproof/shared/util/initSentry.dart';
import 'package:decentproof/shared/util/loadTranslations.dart';
import 'package:decentproof/shared/util/register.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
import 'package:get_it/get_it.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:easy_localization/src/localization.dart';

class VerificationTaskHandler implements TaskHandler {
@override
Expand All @@ -33,10 +35,12 @@ class VerificationTaskHandler implements TaskHandler {
Future<void> onStart(DateTime timestamp, SendPort? sendPort) async {
DartPluginRegistrant.ensureInitialized();
try {
await EasyLocalization.ensureInitialized();
await loadTranslations();
final Localization L = Localization.instance;
await dotenv.load();
await initSentry();
await registar();
await dotenv.load();
await EasyLocalization.ensureInitialized();
final GetIt getIt = GetIt.instance;
final IForegroundService foregroundService =
getIt.get<IForegroundService>();
Expand All @@ -50,8 +54,6 @@ class VerificationTaskHandler implements TaskHandler {
Stream<List<int>> tempStream = tempFile
.openRead(); // Steams are consumed after beeing done so we need a new one
sendPort?.send({"status": "Hashing", "progess": 0});
await foregroundService.updateNotification(
body: "verificationNotification.validatingMetaData".tr());
String hash = await hashLogic.hashBytesInChunksFromStream(tempStream,
(progress) async {
int currentProgress = (progress / fileSize * 100).ceil();
Expand All @@ -60,7 +62,7 @@ class VerificationTaskHandler implements TaskHandler {
// Should prevent to many updates
await foregroundService.updateNotification(
body:
"${"verificationNotification.hashing".tr()} $currentProgress%");
"${L.tr("verificationNotification.hashing")} $currentProgress%");
}
});
VerificationStatusModel model = await verificationService.verify(hash);
Expand All @@ -69,7 +71,7 @@ class VerificationTaskHandler implements TaskHandler {
MetaDataModel metaDataModel =
await extractMetaData(fileType, tempFile, getIt);
await foregroundService.updateNotification(
body: "verificationNotification.validatingMetaData".tr());
body: L.tr("verificationNotification.validatingMetaData"));
final finalModel = model.copyWith(metaDataModel: metaDataModel);
sendPort?.send({"status": "Done", "model": finalModel.toJson()});
} catch (e, stack) {
Expand Down
11 changes: 2 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:decentproof/constants.dart';
import 'package:decentproof/features/hashing/bloc/SubmissionBloc.dart';
import 'package:decentproof/features/hashing/bloc/PreparationBloc/PreparationBloc.dart';
import 'package:decentproof/features/metadata/bloc/LocationWarningBloc.dart';
Expand Down Expand Up @@ -44,15 +45,7 @@ void main() async {
useOnlyLangCode: true,
fallbackLocale: const Locale("en"),
path: "assets/translations",
supportedLocales: const [
Locale("en"),
Locale("de"),
Locale("sn"),
Locale("fr"),
Locale("jp"),
Locale("zn"),
Locale("ar")
],
supportedLocales: SUPPORTED_LOCALS,
child: const MyApp()));
Bloc.observer = MetricsBlocObserver();
}, (error, stack) {
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/foregroundService/ForegroundServiceWrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ForegroundServiceWrapper implements IForegroundService {
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'decentproof_hashing_service',
channelName: 'Hashing & Preperation Channel',
channelDescription: "notification.description".tr(),
channelDescription: "notificationChannel.description".tr(),
channelImportance: NotificationChannelImportance.LOW,
priority: NotificationPriority.MAX,
visibility: NotificationVisibility.VISIBILITY_PRIVATE,
Expand Down
34 changes: 34 additions & 0 deletions lib/shared/util/loadTranslations.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:ui';

import 'package:decentproof/constants.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:easy_localization/src/easy_localization_controller.dart';
import 'package:easy_localization/src/localization.dart';

/// Load translations from assets and keep them in memory
/// Can be used to load translations in foreground services etc
/// Please also use `final Localization L = Localization.instance;` in the foreground service with `L.tr("my.key")`
/// See: https://github.com/aissat/easy_localization/issues/210#issuecomment-806089855
Future<void> loadTranslations() async {
//this will only set EasyLocalizationController.savedLocale
await EasyLocalizationController.initEasyLocation();

final controller = EasyLocalizationController(
saveLocale: true, //mandatory to use EasyLocalizationController.savedLocale
fallbackLocale: const Locale('en'),
supportedLocales: SUPPORTED_LOCALS,
assetLoader: const RootBundleAssetLoader(),
useOnlyLangCode: true,
useFallbackTranslations: true,
path: "assets/translations",
onLoadError: (e) {},
);

//Load translations from assets
await controller.loadTranslations();

//load translations into exploitable data, kept in memory
Localization.load(controller.locale,
translations: controller.translations,
fallbackTranslations: controller.fallbackTranslations);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 2.3.1+15
version: 2.3.2+16

environment:
sdk: ">=3.0.5 <4.0.0"
Expand Down
33 changes: 33 additions & 0 deletions test/consts_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import "package:decentproof/constants.dart";
import "package:flutter_dotenv/flutter_dotenv.dart";
import "package:test/test.dart";

// While it seems senseless at first, this is to figure out if the env vars can be accessed in the CI/CD pipeline.
void main() {
setUp(() async {
await dotenv.load(fileName: ".env");
});
group(
"Constants",
() {
test("SENTRY_DSN is not empty", () {
expect(SENTRY_DSN, isNotEmpty);
});
test("SIGN_URL is not empty", () {
expect(SIGN_URL, isNotEmpty);
});
test("VERIFY_URL is not empty", () {
expect(VERIFY_URL, isNotEmpty);
});
test("GET_KEY_URL is not empty", () {
expect(GET_KEY_URL, isNotEmpty);
});
test("CHECK_KEY_URL is not empty", () {
expect(CHECK_KEY_URL, isNotEmpty);
});
test("WIKI_URL is not empty", () {
expect(WIKI_URL, isNotEmpty);
});
},
);
}