From 3bc880079c6a5eba34901857da31e884f06b3c07 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 18 Jun 2023 12:19:24 +0200 Subject: [PATCH] feat: Migrate to moxlib 0.2.0 --- packages/moxplatform/lib/src/types.dart | 3 +- packages/moxplatform/pubspec.yaml | 12 ++--- .../lib/src/crypto_android.dart | 31 +++++++++--- .../lib/src/isolate_android.dart | 47 +++++++++++-------- .../lib/src/service_android.dart | 14 +++--- packages/moxplatform_android/pubspec.yaml | 12 ++--- .../lib/src/crypto.dart | 40 +++++++++------- .../lib/src/crypto_stub.dart | 18 ++++++- .../lib/src/interface.dart | 2 +- .../lib/src/isolate.dart | 4 +- .../lib/src/isolate_stub.dart | 4 +- .../lib/src/service.dart | 2 +- .../pubspec.yaml | 10 ++-- 13 files changed, 124 insertions(+), 75 deletions(-) diff --git a/packages/moxplatform/lib/src/types.dart b/packages/moxplatform/lib/src/types.dart index e4731ce..96fc347 100644 --- a/packages/moxplatform/lib/src/types.dart +++ b/packages/moxplatform/lib/src/types.dart @@ -1,4 +1,5 @@ -import 'package:moxlib/awaitabledatasender.dart'; +import 'package:moxlib/moxlib.dart'; abstract class BackgroundCommand implements JsonImplementation {} + abstract class BackgroundEvent implements JsonImplementation {} diff --git a/packages/moxplatform/pubspec.yaml b/packages/moxplatform/pubspec.yaml index 2ca3456..a35ac5c 100644 --- a/packages/moxplatform/pubspec.yaml +++ b/packages/moxplatform/pubspec.yaml @@ -1,11 +1,11 @@ name: moxplatform description: Moxxy platform-specific code -version: 0.1.15 +version: 0.1.16 publish_to: https://git.polynom.me/api/packages/Moxxy/pub homepage: https://codeberg.org/moxxy/moxplatform environment: - sdk: ">=2.16.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" flutter: ">=2.10.0" flutter: @@ -22,17 +22,17 @@ dependencies: moxlib: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.4 + version: ^0.2.0 moxplatform_android: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.15 + version: ^0.1.16 moxplatform_platform_interface: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.15 + version: ^0.1.16 dev_dependencies: flutter_test: sdk: flutter plugin_platform_interface: ^2.1.2 - very_good_analysis: ^2.4.0 + very_good_analysis: ^3.0.1 \ No newline at end of file diff --git a/packages/moxplatform_android/lib/src/crypto_android.dart b/packages/moxplatform_android/lib/src/crypto_android.dart index 0a8738e..4ea1e00 100644 --- a/packages/moxplatform_android/lib/src/crypto_android.dart +++ b/packages/moxplatform_android/lib/src/crypto_android.dart @@ -6,13 +6,21 @@ class AndroidCryptographyImplementation extends CryptographyImplementation { final _methodChannel = const MethodChannel('me.polynom.moxplatform_android'); @override - Future encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { - final dynamic resultRaw = await _methodChannel.invokeMethod('encryptFile', [ + Future encryptFile( + String sourcePath, + String destPath, + Uint8List key, + Uint8List iv, + CipherAlgorithm algorithm, + String hashSpec, + ) async { + final dynamic resultRaw = + await _methodChannel.invokeMethod('encryptFile', [ sourcePath, destPath, key, iv, - algorithm.toInt(), + algorithm.value, hashSpec, ]); if (resultRaw == null) return null; @@ -26,13 +34,21 @@ class AndroidCryptographyImplementation extends CryptographyImplementation { } @override - Future decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { - final dynamic resultRaw = await _methodChannel.invokeMethod('decryptFile', [ + Future decryptFile( + String sourcePath, + String destPath, + Uint8List key, + Uint8List iv, + CipherAlgorithm algorithm, + String hashSpec, + ) async { + final dynamic resultRaw = + await _methodChannel.invokeMethod('decryptFile', [ sourcePath, destPath, key, iv, - algorithm.toInt(), + algorithm.value, hashSpec, ]); if (resultRaw == null) return null; @@ -47,7 +63,8 @@ class AndroidCryptographyImplementation extends CryptographyImplementation { @override Future hashFile(String path, String hashSpec) async { - final dynamic resultsRaw = await _methodChannel.invokeMethod('hashFile', [ + final dynamic resultsRaw = + await _methodChannel.invokeMethod('hashFile', [ path, hashSpec, ]); diff --git a/packages/moxplatform_android/lib/src/isolate_android.dart b/packages/moxplatform_android/lib/src/isolate_android.dart index 3d6e523..fd14e54 100644 --- a/packages/moxplatform_android/lib/src/isolate_android.dart +++ b/packages/moxplatform_android/lib/src/isolate_android.dart @@ -4,18 +4,19 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:get_it/get_it.dart'; import 'package:logging/logging.dart'; -import 'package:moxlib/awaitabledatasender.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxplatform/moxplatform.dart'; import 'package:moxplatform_android/src/service_android.dart'; import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart'; /// An [AwaitableDataSender] that uses flutter_background_service. -class BackgroundServiceDataSender extends AwaitableDataSender { - +class BackgroundServiceDataSender + extends AwaitableDataSender { BackgroundServiceDataSender() - : _channel = const MethodChannel('me.polynom.moxplatform_android'), super(); + : _channel = const MethodChannel('me.polynom.moxplatform_android'), + super(); final MethodChannel _channel; - + @override Future sendDataImpl(DataWrapper data) async { await _channel.invokeMethod('sendData', jsonEncode(data.toJson())); @@ -39,11 +40,15 @@ Future androidEntrypoint() async { ); final data = jsonDecode(result!) as Map; final entrypointHandle = data['genericEntrypoint']! as int; - final entrypointCallbackHandle = CallbackHandle.fromRawHandle(entrypointHandle); - final entrypoint = PluginUtilities.getCallbackFromHandle(entrypointCallbackHandle); + final entrypointCallbackHandle = + CallbackHandle.fromRawHandle(entrypointHandle); + final entrypoint = + PluginUtilities.getCallbackFromHandle(entrypointCallbackHandle); final handleUIEventHandle = data['eventHandle']! as int; - final handleUIEventCallbackHandle = CallbackHandle.fromRawHandle(handleUIEventHandle); - final handleUIEvent = PluginUtilities.getCallbackFromHandle(handleUIEventCallbackHandle); + final handleUIEventCallbackHandle = + CallbackHandle.fromRawHandle(handleUIEventHandle); + final handleUIEvent = + PluginUtilities.getCallbackFromHandle(handleUIEventCallbackHandle); final srv = AndroidBackgroundService(); GetIt.I.registerSingleton(srv); @@ -55,24 +60,25 @@ Future androidEntrypoint() async { /// The Android specific implementation of the [IsolateHandler]. class AndroidIsolateHandler extends IsolateHandler { - AndroidIsolateHandler() - : _channel = const MethodChannel('me.polynom.moxplatform_android'), - _dataSender = BackgroundServiceDataSender(), - _log = Logger('AndroidIsolateHandler'), - super(); + : _channel = const MethodChannel('me.polynom.moxplatform_android'), + _dataSender = BackgroundServiceDataSender(), + _log = Logger('AndroidIsolateHandler'), + super(); final BackgroundServiceDataSender _dataSender; final MethodChannel _channel; final Logger _log; @override - Future attach(Future Function(Map? data) handleIsolateEvent) async { + Future attach( + Future Function(Map? data) handleIsolateEvent, + ) async { _channel.setMethodCallHandler((MethodCall call) async { final args = call.arguments as String; await handleIsolateEvent(jsonDecode(args) as Map); }); } - + @override Future start( Future Function() entrypoint, @@ -82,13 +88,16 @@ class AndroidIsolateHandler extends IsolateHandler { _log.finest('Called start'); WidgetsFlutterBinding.ensureInitialized(); - final androidEntrypointHandle = PluginUtilities.getCallbackHandle(androidEntrypoint)!.toRawHandle(); + final androidEntrypointHandle = + PluginUtilities.getCallbackHandle(androidEntrypoint)!.toRawHandle(); _log.finest('androidEntrypointHandle: $androidEntrypointHandle'); await _channel.invokeMethod('configure', [ androidEntrypointHandle, jsonEncode({ - 'genericEntrypoint': PluginUtilities.getCallbackHandle(entrypoint)!.toRawHandle(), - 'eventHandle': PluginUtilities.getCallbackHandle(handleUIEvent)!.toRawHandle() + 'genericEntrypoint': + PluginUtilities.getCallbackHandle(entrypoint)!.toRawHandle(), + 'eventHandle': + PluginUtilities.getCallbackHandle(handleUIEvent)!.toRawHandle() }), ]); diff --git a/packages/moxplatform_android/lib/src/service_android.dart b/packages/moxplatform_android/lib/src/service_android.dart index baaade6..42ae4c6 100644 --- a/packages/moxplatform_android/lib/src/service_android.dart +++ b/packages/moxplatform_android/lib/src/service_android.dart @@ -4,19 +4,19 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:logging/logging.dart'; import 'package:meta/meta.dart'; -import 'package:moxlib/awaitabledatasender.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxplatform/moxplatform.dart'; import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart'; import 'package:uuid/uuid.dart'; class AndroidBackgroundService extends BackgroundService { - AndroidBackgroundService() - : _log = Logger('AndroidBackgroundService'), - super(); + : _log = Logger('AndroidBackgroundService'), + super(); @internal - static const MethodChannel channel = MethodChannel('me.polynom.moxplatform_android_bg'); + static const MethodChannel channel = + MethodChannel('me.polynom.moxplatform_android_bg'); final Logger _log; @override @@ -28,7 +28,7 @@ class AndroidBackgroundService extends BackgroundService { } @override - void sendEvent(BackgroundEvent event, { String? id }) { + void sendEvent(BackgroundEvent event, {String? id}) { final data = DataWrapper( id ?? const Uuid().v4(), event, @@ -54,7 +54,7 @@ class AndroidBackgroundService extends BackgroundService { final args = call.arguments! as String; await handleEvent(jsonDecode(args) as Map); }); - + setNotification('Moxxy', 'Preparing...'); _log.finest('Running...'); diff --git a/packages/moxplatform_android/pubspec.yaml b/packages/moxplatform_android/pubspec.yaml index 1837151..1e2d01f 100644 --- a/packages/moxplatform_android/pubspec.yaml +++ b/packages/moxplatform_android/pubspec.yaml @@ -1,11 +1,11 @@ name: moxplatform_android description: Android implementation of moxplatform -version: 0.1.15 +version: 0.1.16 homepage: https://codeberg.org/moxxy/moxplatform publish_to: https://git.polynom.me/api/packages/Moxxy/pub environment: - sdk: ">=2.16.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" flutter: ">=2.10.0" flutter: @@ -26,14 +26,14 @@ dependencies: meta: ^1.7.0 moxlib: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.4 + version: ^0.2.0 moxplatform: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.15 + version: ^0.1.16 moxplatform_platform_interface: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.15 + version: ^0.1.16 plugin_platform_interface: ^2.1.2 uuid: ^3.0.5 @@ -41,4 +41,4 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - very_good_analysis: ^2.4.0 + very_good_analysis: ^3.0.1 \ No newline at end of file diff --git a/packages/moxplatform_platform_interface/lib/src/crypto.dart b/packages/moxplatform_platform_interface/lib/src/crypto.dart index c390e17..b61b086 100644 --- a/packages/moxplatform_platform_interface/lib/src/crypto.dart +++ b/packages/moxplatform_platform_interface/lib/src/crypto.dart @@ -1,23 +1,17 @@ import 'dart:typed_data'; enum CipherAlgorithm { - aes128GcmNoPadding, - aes256GcmNoPadding, - aes256CbcPkcs7, -} + aes128GcmNoPadding(0), + aes256GcmNoPadding(1), + aes256CbcPkcs7(2); -extension CipherAlgorithmToIntExtension on CipherAlgorithm { - int toInt() { - switch (this) { - case CipherAlgorithm.aes128GcmNoPadding: return 0; - case CipherAlgorithm.aes256GcmNoPadding: return 1; - case CipherAlgorithm.aes256CbcPkcs7: return 2; - } - } + const CipherAlgorithm(this.value); + + /// The "id" of the algorithm choice. + final int value; } class CryptographyResult { - const CryptographyResult(this.plaintextHash, this.ciphertextHash); final Uint8List plaintextHash; final Uint8List ciphertextHash; @@ -30,14 +24,28 @@ abstract class CryptographyImplementation { /// 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. - Future encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec); + Future 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 /// [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. - /// + /// /// Resolves to true if the encryption was successful. Resolves to fale on failure. - Future decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec); + Future 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]. /// Note that this function runs off-thread as to not block the UI thread. diff --git a/packages/moxplatform_platform_interface/lib/src/crypto_stub.dart b/packages/moxplatform_platform_interface/lib/src/crypto_stub.dart index 109ad6f..b71ff68 100644 --- a/packages/moxplatform_platform_interface/lib/src/crypto_stub.dart +++ b/packages/moxplatform_platform_interface/lib/src/crypto_stub.dart @@ -3,12 +3,26 @@ import 'package:moxplatform_platform_interface/src/crypto.dart'; class StubCryptographyImplementation extends CryptographyImplementation { @override - Future encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { + Future encryptFile( + String sourcePath, + String destPath, + Uint8List key, + Uint8List iv, + CipherAlgorithm algorithm, + String hashSpec, + ) async { return null; } @override - Future decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async { + Future decryptFile( + String sourcePath, + String destPath, + Uint8List key, + Uint8List iv, + CipherAlgorithm algorithm, + String hashSpec, + ) async { return null; } diff --git a/packages/moxplatform_platform_interface/lib/src/interface.dart b/packages/moxplatform_platform_interface/lib/src/interface.dart index 208d626..ca4ac6c 100644 --- a/packages/moxplatform_platform_interface/lib/src/interface.dart +++ b/packages/moxplatform_platform_interface/lib/src/interface.dart @@ -10,7 +10,7 @@ abstract class MoxplatformInterface extends PlatformInterface { MoxplatformInterface() : super(token: _token); static final Object _token = Object(); - + static IsolateHandler handler = StubIsolateHandler(); static MediaScannerImplementation media = StubMediaScannerImplementation(); static CryptographyImplementation crypto = StubCryptographyImplementation(); diff --git a/packages/moxplatform_platform_interface/lib/src/isolate.dart b/packages/moxplatform_platform_interface/lib/src/isolate.dart index dce1ca9..8e8f5ff 100644 --- a/packages/moxplatform_platform_interface/lib/src/isolate.dart +++ b/packages/moxplatform_platform_interface/lib/src/isolate.dart @@ -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 /// service, which is either a regular isolate or an Android foreground service. @@ -18,7 +18,7 @@ abstract class IsolateHandler { Future attach( Future Function(Map? data) handleIsolateEvent, ); - + /// Return true if the background service is running. False if it's not. Future isRunning(); diff --git a/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart b/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart index 34d9e1a..67c96a7 100644 --- a/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart +++ b/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart @@ -1,4 +1,4 @@ -import 'package:moxlib/awaitabledatasender.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxplatform_platform_interface/src/isolate.dart'; class StubDataSender extends AwaitableDataSender { @@ -19,7 +19,7 @@ class StubIsolateHandler extends IsolateHandler { // ignore: avoid_print print('STUB ATTACHED!!!!!!'); } - + @override Future start( Future Function() entrypoint, diff --git a/packages/moxplatform_platform_interface/lib/src/service.dart b/packages/moxplatform_platform_interface/lib/src/service.dart index 5f390bf..d676ebd 100644 --- a/packages/moxplatform_platform_interface/lib/src/service.dart +++ b/packages/moxplatform_platform_interface/lib/src/service.dart @@ -5,7 +5,7 @@ abstract class BackgroundService { void setNotification(String title, String body); /// Send data from the background service to the UI. - void sendEvent(BackgroundEvent event, { String? id }); + void sendEvent(BackgroundEvent event, {String? id}); /// Called before [entrypoint]. Sets up whatever it needs to set up. /// [handleEvent] is a function that is called whenever the service receives diff --git a/packages/moxplatform_platform_interface/pubspec.yaml b/packages/moxplatform_platform_interface/pubspec.yaml index f43fadb..4a83382 100644 --- a/packages/moxplatform_platform_interface/pubspec.yaml +++ b/packages/moxplatform_platform_interface/pubspec.yaml @@ -1,11 +1,11 @@ name: moxplatform_platform_interface description: A common platform interface for the my_plugin plugin. -version: 0.1.15 +version: 0.1.16 homepage: https://codeberg.org/moxxy/moxplatform publish_to: https://git.polynom.me/api/packages/Moxxy/pub environment: - sdk: ">=2.16.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" flutter: ">=2.10.0" dependencies: @@ -14,14 +14,14 @@ dependencies: moxlib: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.4 + version: ^0.2.0 moxplatform: hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: ^0.1.15 + version: ^0.1.16 plugin_platform_interface: ^2.1.2 dev_dependencies: flutter_test: sdk: flutter - very_good_analysis: ^2.4.0 + very_good_analysis: ^3.0.1