Skip to content

Commit

Permalink
Merge pull request #132 from Flajt/dev
Browse files Browse the repository at this point in the history
Fix: Metadata & watermark notification, language support for SN dropped, detect mock locations
  • Loading branch information
Flajt authored Mar 20, 2024
2 parents ae49d3c + be0b3dd commit 468f845
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 76 deletions.
4 changes: 3 additions & 1 deletion assets/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "إعداد",
"initalDescription": "التهيئة"
"initalDescription": "التهيئة",
"addingMetaData": "إضافة بيانات التعريف",
"addingWaterMark": "إضافة علامة مائية"
},
"verificationNotification": {
"title": "جارٍ التحقق",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "Media Datei wird vorbereitet",
"initalDescription": "Initialisiere"
"initalDescription": "Initialisiere",
"addingMetaData": "Metadaten werden hinzugefügt",
"addingWaterMark": "Wasserzeichen hinzufügen"
},
"verificationNotification": {
"title": "Verifiziere",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "Preperation in progress",
"initalDescription": "Initalizing"
"initalDescription": "Initalizing",
"addingMetaData": "Adding Metadata",
"addingWaterMark": "Adding Watermark"
},
"verificationNotification": {
"title": "Verification in progress",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "Preparación en progreso",
"initalDescription": "Inicializando"
"initalDescription": "Inicializando",
"addingMetaData": "Agregar metadatos",
"addingWaterMark": "Agregar marca de agua"
},
"verificationNotification": {
"title": "Verificación en progreso",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "Préparation en cours",
"initalDescription": "Initialisation"
"initalDescription": "Initialisation",
"addingMetaData": "Ajout de métadonnées",
"addingWaterMark": "Ajout d'un filigrane"
},
"verificationNotification": {
"title": "Vérification en cours",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "準備中",
"initalDescription": "初期化"
"initalDescription": "初期化",
"addingMetaData": "メタデータの追加",
"addingWaterMark": "透かしの追加"
},
"verificationNotification": {
"title": "検証中",
Expand Down
4 changes: 3 additions & 1 deletion assets/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "Подготовка продолжается",
"initalDescription": "Инициализация"
"initalDescription": "Инициализация",
"addingMetaData": "Добавление метаданных",
"addingWaterMark": "Добавление водяного знака"
},
"verificationNotification": {
"title": "Выполняется проверка",
Expand Down
66 changes: 0 additions & 66 deletions assets/translations/sn.json

This file was deleted.

4 changes: 3 additions & 1 deletion assets/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
},
"perperationNotification": {
"title": "准备工作正在进行中",
"initalDescription": "正在初始化"
"initalDescription": "正在初始化",
"addingMetaData": "添加元数据",
"addingWaterMark": "添加水印"
},
"verificationNotification": {
"title": "验证正在进行中",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import 'package:decentproof/features/metadata/interfaces/IMetaDataPermissionServ
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/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 PreperationTaskHandler extends TaskHandler {
// Called when the task is started.
Expand All @@ -22,6 +25,8 @@ class PreperationTaskHandler extends TaskHandler {
DartPluginRegistrant.ensureInitialized();
try {
await dotenv.load();
await loadTranslations();
final Localization L = Localization.instance;
await initSentry();
await registar();
final getIt = GetIt.I;
Expand Down Expand Up @@ -54,10 +59,14 @@ class PreperationTaskHandler extends TaskHandler {
final task = parts[0];
if (task == "image") {
sendPort?.send({"status": "AddingWaterMark"});
await foregroundService.updateNotification(
body: L.tr("perperationNotification.addingWaterMark"));
String finalPath = await imageWaterMarkService.addWaterMark(path);
bool shouldEmbedLocation =
metaDataPermissionService.shouldEmbedLocation();
if (shouldEmbedLocation) {
await foregroundService.updateNotification(
body: L.tr("perperationNotification.addingMetaData"));
sendPort?.send({"status": "AddingMetaData"});
bool isEnabled = await locationService.serviceEnabled();
if (!isEnabled) {
Expand All @@ -80,12 +89,16 @@ class PreperationTaskHandler extends TaskHandler {
?.send({"status": "Done", "content": hash, "filePath": finalPath});
} else if (task == "video") {
String? afterMetaDataPath;
await foregroundService.updateNotification(
body: L.tr("perperationNotification.addingWaterMark"));
sendPort?.send({"status": "AddingWaterMark"});
String finalPath = await videoWaterMarkSerivce.addWaterMark(path);
bool shouldEmbedLocation =
metaDataPermissionService.shouldEmbedLocation();
if (shouldEmbedLocation) {
bool isEnabled = await locationService.serviceEnabled();
await foregroundService.updateNotification(
body: L.tr("perperationNotification.addingMetaData"));
sendPort?.send({"status": "AddingMetaData"});
if (!isEnabled) {
sendPort?.send({
Expand Down Expand Up @@ -115,6 +128,8 @@ class PreperationTaskHandler extends TaskHandler {
bool shouldEmbedLocation =
metaDataPermissionService.shouldEmbedLocation();
if (shouldEmbedLocation) {
await foregroundService.updateNotification(
body: L.tr("perperationNotification.addingWaterMark"));
sendPort?.send({"status": "AddingMetaData"});
bool isEnabled = await locationService.serviceEnabled();
if (!isEnabled) {
Expand All @@ -140,6 +155,10 @@ class PreperationTaskHandler extends TaskHandler {
"content": hash,
"filePath": afterMetaDataPath ?? path
});
} else {
sendPort
?.send({"status": "Error", "description": "Task not supported"});
await foregroundService.stop();
}
} catch (e, stack) {
sendPort?.send({
Expand Down
4 changes: 4 additions & 0 deletions lib/features/metadata/logic/LocationServiceWrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class LocationServiceWrapper implements ILocationService {
Future<LocationModel> requestLocation() async {
Position locationData = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best);
if (locationData.isMocked) {
throw Exception(
'Invalid Location: It seems like you are using a mock location service. Please disable it and try again.');
}
return LocationModel(
latitude: locationData.latitude, longitude: locationData.longitude);
}
Expand Down
1 change: 0 additions & 1 deletion project.inlang/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"fr",
"jp",
"ru",
"sn",
"zh"
],
"modules": [
Expand Down
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.4+18
version: 2.3.6+19

environment:
sdk: ">=3.0.5 <4.0.0"
Expand Down
53 changes: 53 additions & 0 deletions test/hashing/bloc/PreparationBloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'package:test/test.dart';

import '../../mocks.mocks.dart';

/// The whole suit is kinda a mess. Since it's hard to get a good stream of events, the worst thing is that I've got to simulate the stream of events.
/// Idealy this wouldn't be the case and we could just hook into a real stream, and do the testing that way. Any ideas are appreciated.
void main() {
setUp(() async {
await GetIt.I.reset();
Expand Down Expand Up @@ -588,6 +590,57 @@ void main() {
PrepareationIsAddingMetaData(),
PreparationHasError("Location Service is not enabled!")
]);
blocTest("w. error due to mock location",
setUp: () {
register(
videoSavingService,
imageSavingService,
imageHashingService,
videoHashingService,
videoWaterMarkSerivce,
imageWaterMarkService,
audioMetaDataService,
videoMetaDataService,
imageMetaDataService,
audioHashingService,
locationService,
metaDataPermissionService,
foregroundServiceWrapper);
final testPort = ReceivePort.fromRawReceivePort(RawReceivePort());
final sendPort = testPort.sendPort;
when(foregroundServiceWrapper.getReceivePort())
.thenAnswer((_) => Future.value(testPort));
sendPort.send({
"status": "AddingWaterMark"
}); // Since stuff is returned from a stream it is in the currect order
sendPort.send({"status": "AddingMetaData"});
sendPort.send({"status": "Hashing", "progress": 0});
sendPort.send({
"status": "Fail",
"description":
"Invalid Location: It seems like you are using a mock location service. Please disable it and try again.",
});
when(imageSavingService.saveFile())
.thenAnswer((_) => Future.value("some/path/to/image.png"));
when(imageWaterMarkService.addWaterMark(any))
.thenAnswer((_) => Future.value("sample/path/to/image.png"));
when(metaDataPermissionService.shouldEmbedLocation())
.thenReturn(true);
when(locationService.requestLocation()).thenThrow((_) =>
"Invalid Location: It seems like you are using a mock location service. Please disable it and try again.");
when(locationService.serviceEnabled())
.thenAnswer((realInvocation) => Future.value(true));
},
act: (bloc) => bloc.add(PrepareImage()),
build: () => PreparationBloc(),
wait: const Duration(milliseconds: 100),
expect: () => [
PrepareationIsAplyingWaterMark(),
PrepareationIsAddingMetaData(),
PrepareationIsHashing(),
PreparationHasError(
"Invalid Location: It seems like you are using a mock location service. Please disable it and try again.")
]);
});
});
}
Expand Down

0 comments on commit 468f845

Please sign in to comment.