feat: Migrate to moxlib 0.2.0

This commit is contained in:
PapaTutuWawa 2023-06-18 12:19:24 +02:00
parent 7a999cf860
commit 3bc880079c
13 changed files with 124 additions and 75 deletions

View File

@ -1,4 +1,5 @@
import 'package:moxlib/awaitabledatasender.dart'; import 'package:moxlib/moxlib.dart';
abstract class BackgroundCommand implements JsonImplementation {} abstract class BackgroundCommand implements JsonImplementation {}
abstract class BackgroundEvent implements JsonImplementation {} abstract class BackgroundEvent implements JsonImplementation {}

View File

@ -1,11 +1,11 @@
name: moxplatform name: moxplatform
description: Moxxy platform-specific code description: Moxxy platform-specific code
version: 0.1.15 version: 0.1.16
publish_to: https://git.polynom.me/api/packages/Moxxy/pub publish_to: https://git.polynom.me/api/packages/Moxxy/pub
homepage: https://codeberg.org/moxxy/moxplatform homepage: https://codeberg.org/moxxy/moxplatform
environment: environment:
sdk: ">=2.16.0 <3.0.0" sdk: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0" flutter: ">=2.10.0"
flutter: flutter:
@ -22,17 +22,17 @@ dependencies:
moxlib: moxlib:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.4 version: ^0.2.0
moxplatform_android: moxplatform_android:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.15 version: ^0.1.16
moxplatform_platform_interface: moxplatform_platform_interface:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.15 version: ^0.1.16
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
plugin_platform_interface: ^2.1.2 plugin_platform_interface: ^2.1.2
very_good_analysis: ^2.4.0 very_good_analysis: ^3.0.1

View File

@ -6,13 +6,21 @@ class AndroidCryptographyImplementation extends CryptographyImplementation {
final _methodChannel = const MethodChannel('me.polynom.moxplatform_android'); final _methodChannel = const MethodChannel('me.polynom.moxplatform_android');
@override @override
Future<CryptographyResult?> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { Future<CryptographyResult?> encryptFile(
final dynamic resultRaw = await _methodChannel.invokeMethod<dynamic>('encryptFile', [ String sourcePath,
String destPath,
Uint8List key,
Uint8List iv,
CipherAlgorithm algorithm,
String hashSpec,
) async {
final dynamic resultRaw =
await _methodChannel.invokeMethod<dynamic>('encryptFile', [
sourcePath, sourcePath,
destPath, destPath,
key, key,
iv, iv,
algorithm.toInt(), algorithm.value,
hashSpec, hashSpec,
]); ]);
if (resultRaw == null) return null; if (resultRaw == null) return null;
@ -26,13 +34,21 @@ class AndroidCryptographyImplementation extends CryptographyImplementation {
} }
@override @override
Future<CryptographyResult?> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { Future<CryptographyResult?> decryptFile(
final dynamic resultRaw = await _methodChannel.invokeMethod<dynamic>('decryptFile', [ String sourcePath,
String destPath,
Uint8List key,
Uint8List iv,
CipherAlgorithm algorithm,
String hashSpec,
) async {
final dynamic resultRaw =
await _methodChannel.invokeMethod<dynamic>('decryptFile', [
sourcePath, sourcePath,
destPath, destPath,
key, key,
iv, iv,
algorithm.toInt(), algorithm.value,
hashSpec, hashSpec,
]); ]);
if (resultRaw == null) return null; if (resultRaw == null) return null;
@ -47,7 +63,8 @@ class AndroidCryptographyImplementation extends CryptographyImplementation {
@override @override
Future<Uint8List?> hashFile(String path, String hashSpec) async { Future<Uint8List?> hashFile(String path, String hashSpec) async {
final dynamic resultsRaw = await _methodChannel.invokeMethod<dynamic>('hashFile', [ final dynamic resultsRaw =
await _methodChannel.invokeMethod<dynamic>('hashFile', [
path, path,
hashSpec, hashSpec,
]); ]);

View File

@ -4,16 +4,17 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:moxlib/awaitabledatasender.dart'; import 'package:moxlib/moxlib.dart';
import 'package:moxplatform/moxplatform.dart'; import 'package:moxplatform/moxplatform.dart';
import 'package:moxplatform_android/src/service_android.dart'; import 'package:moxplatform_android/src/service_android.dart';
import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart'; import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart';
/// An [AwaitableDataSender] that uses flutter_background_service. /// An [AwaitableDataSender] that uses flutter_background_service.
class BackgroundServiceDataSender extends AwaitableDataSender<BackgroundCommand, BackgroundEvent> { class BackgroundServiceDataSender
extends AwaitableDataSender<BackgroundCommand, BackgroundEvent> {
BackgroundServiceDataSender() BackgroundServiceDataSender()
: _channel = const MethodChannel('me.polynom.moxplatform_android'), super(); : _channel = const MethodChannel('me.polynom.moxplatform_android'),
super();
final MethodChannel _channel; final MethodChannel _channel;
@override @override
@ -39,11 +40,15 @@ Future<void> androidEntrypoint() async {
); );
final data = jsonDecode(result!) as Map<String, dynamic>; final data = jsonDecode(result!) as Map<String, dynamic>;
final entrypointHandle = data['genericEntrypoint']! as int; final entrypointHandle = data['genericEntrypoint']! as int;
final entrypointCallbackHandle = CallbackHandle.fromRawHandle(entrypointHandle); final entrypointCallbackHandle =
final entrypoint = PluginUtilities.getCallbackFromHandle(entrypointCallbackHandle); CallbackHandle.fromRawHandle(entrypointHandle);
final entrypoint =
PluginUtilities.getCallbackFromHandle(entrypointCallbackHandle);
final handleUIEventHandle = data['eventHandle']! as int; final handleUIEventHandle = data['eventHandle']! as int;
final handleUIEventCallbackHandle = CallbackHandle.fromRawHandle(handleUIEventHandle); final handleUIEventCallbackHandle =
final handleUIEvent = PluginUtilities.getCallbackFromHandle(handleUIEventCallbackHandle); CallbackHandle.fromRawHandle(handleUIEventHandle);
final handleUIEvent =
PluginUtilities.getCallbackFromHandle(handleUIEventCallbackHandle);
final srv = AndroidBackgroundService(); final srv = AndroidBackgroundService();
GetIt.I.registerSingleton<BackgroundService>(srv); GetIt.I.registerSingleton<BackgroundService>(srv);
@ -55,7 +60,6 @@ Future<void> androidEntrypoint() async {
/// The Android specific implementation of the [IsolateHandler]. /// The Android specific implementation of the [IsolateHandler].
class AndroidIsolateHandler extends IsolateHandler { class AndroidIsolateHandler extends IsolateHandler {
AndroidIsolateHandler() AndroidIsolateHandler()
: _channel = const MethodChannel('me.polynom.moxplatform_android'), : _channel = const MethodChannel('me.polynom.moxplatform_android'),
_dataSender = BackgroundServiceDataSender(), _dataSender = BackgroundServiceDataSender(),
@ -66,7 +70,9 @@ class AndroidIsolateHandler extends IsolateHandler {
final Logger _log; final Logger _log;
@override @override
Future<void> attach(Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent) async { Future<void> attach(
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent,
) async {
_channel.setMethodCallHandler((MethodCall call) async { _channel.setMethodCallHandler((MethodCall call) async {
final args = call.arguments as String; final args = call.arguments as String;
await handleIsolateEvent(jsonDecode(args) as Map<String, dynamic>); await handleIsolateEvent(jsonDecode(args) as Map<String, dynamic>);
@ -82,13 +88,16 @@ class AndroidIsolateHandler extends IsolateHandler {
_log.finest('Called start'); _log.finest('Called start');
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
final androidEntrypointHandle = PluginUtilities.getCallbackHandle(androidEntrypoint)!.toRawHandle(); final androidEntrypointHandle =
PluginUtilities.getCallbackHandle(androidEntrypoint)!.toRawHandle();
_log.finest('androidEntrypointHandle: $androidEntrypointHandle'); _log.finest('androidEntrypointHandle: $androidEntrypointHandle');
await _channel.invokeMethod<void>('configure', <dynamic>[ await _channel.invokeMethod<void>('configure', <dynamic>[
androidEntrypointHandle, androidEntrypointHandle,
jsonEncode({ jsonEncode({
'genericEntrypoint': PluginUtilities.getCallbackHandle(entrypoint)!.toRawHandle(), 'genericEntrypoint':
'eventHandle': PluginUtilities.getCallbackHandle(handleUIEvent)!.toRawHandle() PluginUtilities.getCallbackHandle(entrypoint)!.toRawHandle(),
'eventHandle':
PluginUtilities.getCallbackHandle(handleUIEvent)!.toRawHandle()
}), }),
]); ]);

View File

@ -4,19 +4,19 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:moxlib/awaitabledatasender.dart'; import 'package:moxlib/moxlib.dart';
import 'package:moxplatform/moxplatform.dart'; import 'package:moxplatform/moxplatform.dart';
import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart'; import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
class AndroidBackgroundService extends BackgroundService { class AndroidBackgroundService extends BackgroundService {
AndroidBackgroundService() AndroidBackgroundService()
: _log = Logger('AndroidBackgroundService'), : _log = Logger('AndroidBackgroundService'),
super(); super();
@internal @internal
static const MethodChannel channel = MethodChannel('me.polynom.moxplatform_android_bg'); static const MethodChannel channel =
MethodChannel('me.polynom.moxplatform_android_bg');
final Logger _log; final Logger _log;
@override @override

View File

@ -1,11 +1,11 @@
name: moxplatform_android name: moxplatform_android
description: Android implementation of moxplatform description: Android implementation of moxplatform
version: 0.1.15 version: 0.1.16
homepage: https://codeberg.org/moxxy/moxplatform homepage: https://codeberg.org/moxxy/moxplatform
publish_to: https://git.polynom.me/api/packages/Moxxy/pub publish_to: https://git.polynom.me/api/packages/Moxxy/pub
environment: environment:
sdk: ">=2.16.0 <3.0.0" sdk: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0" flutter: ">=2.10.0"
flutter: flutter:
@ -26,14 +26,14 @@ dependencies:
meta: ^1.7.0 meta: ^1.7.0
moxlib: moxlib:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.4 version: ^0.2.0
moxplatform: moxplatform:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.15 version: ^0.1.16
moxplatform_platform_interface: moxplatform_platform_interface:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.15 version: ^0.1.16
plugin_platform_interface: ^2.1.2 plugin_platform_interface: ^2.1.2
uuid: ^3.0.5 uuid: ^3.0.5
@ -41,4 +41,4 @@ dependencies:
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
very_good_analysis: ^2.4.0 very_good_analysis: ^3.0.1

View File

@ -1,23 +1,17 @@
import 'dart:typed_data'; import 'dart:typed_data';
enum CipherAlgorithm { enum CipherAlgorithm {
aes128GcmNoPadding, aes128GcmNoPadding(0),
aes256GcmNoPadding, aes256GcmNoPadding(1),
aes256CbcPkcs7, aes256CbcPkcs7(2);
}
extension CipherAlgorithmToIntExtension on CipherAlgorithm { const CipherAlgorithm(this.value);
int toInt() {
switch (this) { /// The "id" of the algorithm choice.
case CipherAlgorithm.aes128GcmNoPadding: return 0; final int value;
case CipherAlgorithm.aes256GcmNoPadding: return 1;
case CipherAlgorithm.aes256CbcPkcs7: return 2;
}
}
} }
class CryptographyResult { class CryptographyResult {
const CryptographyResult(this.plaintextHash, this.ciphertextHash); const CryptographyResult(this.plaintextHash, this.ciphertextHash);
final Uint8List plaintextHash; final Uint8List plaintextHash;
final Uint8List ciphertextHash; final Uint8List ciphertextHash;
@ -30,14 +24,28 @@ abstract class CryptographyImplementation {
/// Note that this function runs off-thread as to not block the UI thread. /// Note that this function runs off-thread as to not block the UI thread.
/// ///
/// Resolves to true if the encryption was successful. Resolves to fale on failure. /// Resolves to true if the encryption was successful. Resolves to fale on failure.
Future<CryptographyResult?> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec); Future<CryptographyResult?> encryptFile(
String sourcePath,
String destPath,
Uint8List key,
Uint8List iv,
CipherAlgorithm algorithm,
String hashSpec,
);
/// Decrypt the file at [sourcePath] using [algorithm] and write the result back to /// Decrypt the file at [sourcePath] using [algorithm] and write the result back to
/// [destPath]. [hashSpec] is the name of the Hash function to use, i.e. "SHA-256". /// [destPath]. [hashSpec] is the name of the Hash function to use, i.e. "SHA-256".
/// Note that this function runs off-thread as to not block the UI thread. /// Note that this function runs off-thread as to not block the UI thread.
/// ///
/// Resolves to true if the encryption was successful. Resolves to fale on failure. /// Resolves to true if the encryption was successful. Resolves to fale on failure.
Future<CryptographyResult?> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec); Future<CryptographyResult?> decryptFile(
String sourcePath,
String destPath,
Uint8List key,
Uint8List iv,
CipherAlgorithm algorithm,
String hashSpec,
);
/// Hashes the file at [path] using the Hash function with name [hashSpec]. /// Hashes the file at [path] using the Hash function with name [hashSpec].
/// Note that this function runs off-thread as to not block the UI thread. /// Note that this function runs off-thread as to not block the UI thread.

View File

@ -3,12 +3,26 @@ import 'package:moxplatform_platform_interface/src/crypto.dart';
class StubCryptographyImplementation extends CryptographyImplementation { class StubCryptographyImplementation extends CryptographyImplementation {
@override @override
Future<CryptographyResult?> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { Future<CryptographyResult?> encryptFile(
String sourcePath,
String destPath,
Uint8List key,
Uint8List iv,
CipherAlgorithm algorithm,
String hashSpec,
) async {
return null; return null;
} }
@override @override
Future<CryptographyResult?> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { Future<CryptographyResult?> decryptFile(
String sourcePath,
String destPath,
Uint8List key,
Uint8List iv,
CipherAlgorithm algorithm,
String hashSpec,
) async {
return null; return null;
} }

View File

@ -1,4 +1,4 @@
import 'package:moxlib/awaitabledatasender.dart'; import 'package:moxlib/moxlib.dart';
/// A class abstracting the interaction between the UI isolate and the background /// A class abstracting the interaction between the UI isolate and the background
/// service, which is either a regular isolate or an Android foreground service. /// service, which is either a regular isolate or an Android foreground service.

View File

@ -1,4 +1,4 @@
import 'package:moxlib/awaitabledatasender.dart'; import 'package:moxlib/moxlib.dart';
import 'package:moxplatform_platform_interface/src/isolate.dart'; import 'package:moxplatform_platform_interface/src/isolate.dart';
class StubDataSender extends AwaitableDataSender { class StubDataSender extends AwaitableDataSender {

View File

@ -1,11 +1,11 @@
name: moxplatform_platform_interface name: moxplatform_platform_interface
description: A common platform interface for the my_plugin plugin. description: A common platform interface for the my_plugin plugin.
version: 0.1.15 version: 0.1.16
homepage: https://codeberg.org/moxxy/moxplatform homepage: https://codeberg.org/moxxy/moxplatform
publish_to: https://git.polynom.me/api/packages/Moxxy/pub publish_to: https://git.polynom.me/api/packages/Moxxy/pub
environment: environment:
sdk: ">=2.16.0 <3.0.0" sdk: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0" flutter: ">=2.10.0"
dependencies: dependencies:
@ -14,14 +14,14 @@ dependencies:
moxlib: moxlib:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.4 version: ^0.2.0
moxplatform: moxplatform:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.1.15 version: ^0.1.16
plugin_platform_interface: ^2.1.2 plugin_platform_interface: ^2.1.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
very_good_analysis: ^2.4.0 very_good_analysis: ^3.0.1