diff --git a/README.md b/README.md index e032cad..a6d5a48 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ Platform-specific code for Moxxy. Not intended for use outside of Moxxy. This repo is based on [very_good_flutter_plugin](https://github.com/VeryGoodOpenSource/very_good_flutter_plugin). +## Development + +The development of this package is based on [melos](https://pub.dev/packages/melos). + +To make all packages link to each other locally, begin by running `melos bootstrap`. After editing +the code and making your changes, please run `melos run analyze` to make sure that no linter warnings +are left inside the code. + ## Acknowledgements - [ekasetiawans](https://github.com/ekasetiawans) for [flutter_background_service](https://github.com/ekasetiawans/flutter_background_service). moxplatform_android is basically just a copy and paste of [flutter_background_service](https://github.com/ekasetiawans/flutter_background_service). diff --git a/analysis_options.yaml b/analysis_options.yaml index 09c982f..b3a83ec 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,8 @@ -analyzer: - exclude: - - brick/** +include: package:very_good_analysis/analysis_options.yaml +linter: + rules: + public_member_api_docs: false + lines_longer_than_80_chars: false + use_setters_to_change_properties: false + avoid_positional_boolean_parameters: false + avoid_bool_literals_in_conditional_expressions: false diff --git a/packages/moxplatform/analysis_options.yaml b/packages/moxplatform/analysis_options.yaml new file mode 100644 index 0000000..f04c6cf --- /dev/null +++ b/packages/moxplatform/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options.yaml diff --git a/packages/moxplatform/lib/moxplatform.dart b/packages/moxplatform/lib/moxplatform.dart index 158e082..01308d4 100644 --- a/packages/moxplatform/lib/moxplatform.dart +++ b/packages/moxplatform/lib/moxplatform.dart @@ -1,12 +1,4 @@ -import "package:moxplatform_platform_interface/moxplatform_platform_interface.dart"; -import "package:moxplatform_platform_interface/src/isolate.dart"; -import "package:moxplatform_platform_interface/src/media.dart"; +library moxplatform; -export "package:moxplatform_platform_interface/src/isolate.dart" show IsolateHandler; -export "package:moxplatform_platform_interface/src/media.dart" show MediaScannerImplementation; -export "package:moxplatform_platform_interface/src/service.dart" show BackgroundService; - -class MoxplatformPlugin { - static IsolateHandler get handler => MoxplatformInterface.handler; - static MediaScannerImplementation get media => MoxplatformInterface.media; -} +export 'src/plugin.dart'; +export 'src/types.dart'; diff --git a/packages/moxplatform/lib/src/plugin.dart b/packages/moxplatform/lib/src/plugin.dart new file mode 100644 index 0000000..d99320e --- /dev/null +++ b/packages/moxplatform/lib/src/plugin.dart @@ -0,0 +1,6 @@ +import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart'; + +class MoxplatformPlugin { + static IsolateHandler get handler => MoxplatformInterface.handler; + static MediaScannerImplementation get media => MoxplatformInterface.media; +} diff --git a/packages/moxplatform/lib/types.dart b/packages/moxplatform/lib/src/types.dart similarity index 72% rename from packages/moxplatform/lib/types.dart rename to packages/moxplatform/lib/src/types.dart index 5eeab82..e4731ce 100644 --- a/packages/moxplatform/lib/types.dart +++ b/packages/moxplatform/lib/src/types.dart @@ -1,4 +1,4 @@ -import "package:moxlib/awaitabledatasender.dart"; +import 'package:moxlib/awaitabledatasender.dart'; abstract class BackgroundCommand implements JsonImplementation {} abstract class BackgroundEvent implements JsonImplementation {} diff --git a/packages/moxplatform/pubspec.yaml b/packages/moxplatform/pubspec.yaml index 5a2038e..0b9d182 100644 --- a/packages/moxplatform/pubspec.yaml +++ b/packages/moxplatform/pubspec.yaml @@ -19,6 +19,10 @@ dependencies: flutter: sdk: flutter + moxlib: + hosted: https://git.polynom.me/api/packages/Moxxy/pub + version: 0.1.4 + moxplatform_android: hosted: https://git.polynom.me/api/packages/Moxxy/pub version: 0.1.11 @@ -26,11 +30,8 @@ dependencies: hosted: https://git.polynom.me/api/packages/Moxxy/pub version: 0.1.11 - moxlib: - hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: 0.1.4 - dev_dependencies: flutter_test: sdk: flutter plugin_platform_interface: 2.1.2 + very_good_analysis: 2.4.0 diff --git a/packages/moxplatform_android/analysis_options.yaml b/packages/moxplatform_android/analysis_options.yaml new file mode 100644 index 0000000..f04c6cf --- /dev/null +++ b/packages/moxplatform_android/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options.yaml diff --git a/packages/moxplatform_android/lib/moxplatform_android.dart b/packages/moxplatform_android/lib/moxplatform_android.dart index 3887c73..8a55cf4 100644 --- a/packages/moxplatform_android/lib/moxplatform_android.dart +++ b/packages/moxplatform_android/lib/moxplatform_android.dart @@ -1,15 +1,6 @@ -import "package:moxplatform_android/isolate_android.dart"; -import "package:moxplatform_android/media_android.dart"; +library moxplatform_android; -import "package:moxplatform_platform_interface/moxplatform_platform_interface.dart"; - -class MoxplatformAndroidPlugin extends MoxplatformInterface { - static void registerWith() { - print("MoxplatformAndroidPlugin: Registering implementation"); - MoxplatformInterface.handler = AndroidIsolateHandler(); - MoxplatformInterface.media = AndroidMediaScannerImplementation(); - } - - @override - Future getPlatformName() async => "Android"; -} +export 'src/isolate_android.dart'; +export 'src/media_android.dart'; +export 'src/plugin_android.dart'; +export 'src/service_android.dart'; diff --git a/packages/moxplatform_android/lib/moxplatform_android_method_channel.dart b/packages/moxplatform_android/lib/moxplatform_android_method_channel.dart deleted file mode 100644 index 106dc40..0000000 --- a/packages/moxplatform_android/lib/moxplatform_android_method_channel.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; - -import 'moxplatform_android_platform_interface.dart'; - -/// An implementation of [MoxplatformAndroidPlatform] that uses method channels. -class MethodChannelMoxplatformAndroid extends MoxplatformAndroidPlatform { - /// The method channel used to interact with the native platform. - @visibleForTesting - final methodChannel = const MethodChannel('moxplatform_android'); - - @override - Future getPlatformVersion() async { - final version = await methodChannel.invokeMethod('getPlatformVersion'); - return version; - } -} diff --git a/packages/moxplatform_android/lib/moxplatform_android_platform_interface.dart b/packages/moxplatform_android/lib/moxplatform_android_platform_interface.dart deleted file mode 100644 index 1123e31..0000000 --- a/packages/moxplatform_android/lib/moxplatform_android_platform_interface.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import 'moxplatform_android_method_channel.dart'; - -abstract class MoxplatformAndroidPlatform extends PlatformInterface { - /// Constructs a MoxplatformAndroidPlatform. - MoxplatformAndroidPlatform() : super(token: _token); - - static final Object _token = Object(); - - static MoxplatformAndroidPlatform _instance = MethodChannelMoxplatformAndroid(); - - /// The default instance of [MoxplatformAndroidPlatform] to use. - /// - /// Defaults to [MethodChannelMoxplatformAndroid]. - static MoxplatformAndroidPlatform get instance => _instance; - - /// Platform-specific implementations should set this with their own - /// platform-specific class that extends [MoxplatformAndroidPlatform] when - /// they register themselves. - static set instance(MoxplatformAndroidPlatform instance) { - PlatformInterface.verifyToken(instance, _token); - _instance = instance; - } - - Future getPlatformVersion() { - throw UnimplementedError('platformVersion() has not been implemented.'); - } -} diff --git a/packages/moxplatform_android/lib/service_android.dart b/packages/moxplatform_android/lib/service_android.dart deleted file mode 100644 index 5faf58a..0000000 --- a/packages/moxplatform_android/lib/service_android.dart +++ /dev/null @@ -1,63 +0,0 @@ -import "dart:convert"; -import "dart:ui"; - -import "package:moxplatform_platform_interface/src/service.dart"; -import "package:moxplatform/types.dart"; -import "package:moxlib/awaitabledatasender.dart"; -import "package:flutter/material.dart"; -import "package:flutter/services.dart"; -import "package:logging/logging.dart"; -import "package:uuid/uuid.dart"; -import "package:meta/meta.dart"; - -class AndroidBackgroundService extends BackgroundService { - @internal - static const MethodChannel channel = MethodChannel("me.polynom.moxplatform_android_bg"); - final Logger _log; - - AndroidBackgroundService() - : _log = Logger("AndroidBackgroundService"), - super(); - - @override - void setNotification(String title, String body) { - channel.invokeMethod( - "setNotificationBody", - [ body ] - ); - } - - @override - void sendEvent(BackgroundEvent event, { String? id }) { - final data = DataWrapper( - id ?? const Uuid().v4(), - event - ); - // NOTE: *S*erver to *F*oreground - _log.fine("S2F: ${data.toJson().toString()}"); - channel.invokeMethod("sendData", jsonEncode(data.toJson())); - } - - @override - void init( - Future Function() entrypoint, - Future Function(Map? data) handleEvent - ) { - WidgetsFlutterBinding.ensureInitialized(); - - // Ensure that all native plugins are registered against this FlutterEngine, so that - // we can use path_provider, notifications, ... - DartPluginRegistrant.ensureInitialized(); - - // Register the event handler - channel.setMethodCallHandler((MethodCall call) async { - await handleEvent(jsonDecode(call.arguments)); - }); - - setNotification("Moxxy", "Preparing..."); - - _log.finest("Running..."); - - entrypoint(); - } -} diff --git a/packages/moxplatform_android/lib/isolate_android.dart b/packages/moxplatform_android/lib/src/isolate_android.dart similarity index 54% rename from packages/moxplatform_android/lib/isolate_android.dart rename to packages/moxplatform_android/lib/src/isolate_android.dart index fafe632..3d6e523 100644 --- a/packages/moxplatform_android/lib/isolate_android.dart +++ b/packages/moxplatform_android/lib/src/isolate_android.dart @@ -1,43 +1,47 @@ -import "dart:convert"; -import "dart:ui"; - -import "package:moxplatform_android/service_android.dart"; - -import "package:flutter/widgets.dart"; -import "package:flutter/services.dart"; -import "package:logging/logging.dart"; -import "package:moxplatform_platform_interface/src/isolate.dart"; -import "package:moxplatform_platform_interface/src/service.dart"; -import "package:moxplatform/types.dart"; -import "package:moxlib/awaitabledatasender.dart"; -import "package:get_it/get_it.dart"; +import 'dart:convert'; +import 'dart:ui'; +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: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 { + + BackgroundServiceDataSender() + : _channel = const MethodChannel('me.polynom.moxplatform_android'), super(); final MethodChannel _channel; - BackgroundServiceDataSender() : _channel = MethodChannel("me.polynom.moxplatform_android"), super(); @override Future sendDataImpl(DataWrapper data) async { - await _channel.invokeMethod("sendData", jsonEncode(data.toJson())); + await _channel.invokeMethod('sendData', jsonEncode(data.toJson())); } } @pragma('vm:entry-point') Future androidEntrypoint() async { - print("androidEntrypoint: Called on new FlutterEngine"); + // ignore: avoid_print + print('androidEntrypoint: Called on new FlutterEngine'); WidgetsFlutterBinding.ensureInitialized(); /* AndroidBackgroundService.channel.setMethodCallHandler((MethodCall call) async { print(call.method); });*/ - - final data = jsonDecode(await AndroidBackgroundService.channel.invokeMethod("getExtraData", [])); - final int entrypointHandle = data["genericEntrypoint"]!; + + final result = await AndroidBackgroundService.channel.invokeMethod( + 'getExtraData', + [], + ); + final data = jsonDecode(result!) as Map; + final entrypointHandle = data['genericEntrypoint']! as int; final entrypointCallbackHandle = CallbackHandle.fromRawHandle(entrypointHandle); final entrypoint = PluginUtilities.getCallbackFromHandle(entrypointCallbackHandle); - final int handleUIEventHandle = data["eventHandle"]!; + final handleUIEventHandle = data['eventHandle']! as int; final handleUIEventCallbackHandle = CallbackHandle.fromRawHandle(handleUIEventHandle); final handleUIEvent = PluginUtilities.getCallbackFromHandle(handleUIEventCallbackHandle); @@ -45,26 +49,27 @@ Future androidEntrypoint() async { GetIt.I.registerSingleton(srv); srv.init( entrypoint! as Future Function(), - handleUIEvent! as Future Function(Map? data) + handleUIEvent! as Future Function(Map? data), ); } /// 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(); final BackgroundServiceDataSender _dataSender; final MethodChannel _channel; final Logger _log; - AndroidIsolateHandler() - : _channel = MethodChannel("me.polynom.moxplatform_android"), - _dataSender = BackgroundServiceDataSender(), - _log = Logger("AndroidIsolateHandler"), - super(); - @override Future attach(Future Function(Map? data) handleIsolateEvent) async { _channel.setMethodCallHandler((MethodCall call) async { - await handleIsolateEvent(jsonDecode(call.arguments)); + final args = call.arguments as String; + await handleIsolateEvent(jsonDecode(args) as Map); }); } @@ -72,35 +77,35 @@ class AndroidIsolateHandler extends IsolateHandler { Future start( Future Function() entrypoint, Future Function(Map? data) handleUIEvent, - Future Function(Map? data) handleIsolateEvent + Future Function(Map? data) handleIsolateEvent, ) async { - _log.finest("Called start"); + _log.finest('Called start'); WidgetsFlutterBinding.ensureInitialized(); 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() - }), + await _channel.invokeMethod('configure', [ + androidEntrypointHandle, + jsonEncode({ + 'genericEntrypoint': PluginUtilities.getCallbackHandle(entrypoint)!.toRawHandle(), + 'eventHandle': PluginUtilities.getCallbackHandle(handleUIEvent)!.toRawHandle() + }), ]); await attach(handleIsolateEvent); - final result = await _channel.invokeMethod("start", []); - if (result) { - _log.finest("Service successfully started"); + final result = await _channel.invokeMethod('start', []); + if (result == true) { + _log.finest('Service successfully started'); } else { - _log.severe("Service failed to start"); + _log.severe('Service failed to start'); } } @override Future isRunning() async { WidgetsFlutterBinding.ensureInitialized(); - return await _channel.invokeMethod("isRunning", []); + return (await _channel.invokeMethod('isRunning', [])) == true; } @override diff --git a/packages/moxplatform_android/lib/media_android.dart b/packages/moxplatform_android/lib/src/media_android.dart similarity index 55% rename from packages/moxplatform_android/lib/media_android.dart rename to packages/moxplatform_android/lib/src/media_android.dart index c82e220..88da65f 100644 --- a/packages/moxplatform_android/lib/media_android.dart +++ b/packages/moxplatform_android/lib/src/media_android.dart @@ -1,5 +1,5 @@ -import "package:moxplatform_platform_interface/src/media.dart"; -import "package:media_scanner/media_scanner.dart"; +import 'package:media_scanner/media_scanner.dart'; +import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart'; class AndroidMediaScannerImplementation extends MediaScannerImplementation { @override diff --git a/packages/moxplatform_android/lib/src/plugin_android.dart b/packages/moxplatform_android/lib/src/plugin_android.dart new file mode 100644 index 0000000..e5dd0ef --- /dev/null +++ b/packages/moxplatform_android/lib/src/plugin_android.dart @@ -0,0 +1,15 @@ +import 'package:moxplatform_android/src/isolate_android.dart'; +import 'package:moxplatform_android/src/media_android.dart'; +import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart'; + +class MoxplatformAndroidPlugin extends MoxplatformInterface { + static void registerWith() { + // ignore: avoid_print + print('MoxplatformAndroidPlugin: Registering implementation'); + MoxplatformInterface.handler = AndroidIsolateHandler(); + MoxplatformInterface.media = AndroidMediaScannerImplementation(); + } + + @override + Future getPlatformName() async => 'Android'; +} diff --git a/packages/moxplatform_android/lib/src/service_android.dart b/packages/moxplatform_android/lib/src/service_android.dart new file mode 100644 index 0000000..baaade6 --- /dev/null +++ b/packages/moxplatform_android/lib/src/service_android.dart @@ -0,0 +1,64 @@ +import 'dart:convert'; +import 'dart:ui'; +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: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(); + + @internal + static const MethodChannel channel = MethodChannel('me.polynom.moxplatform_android_bg'); + final Logger _log; + + @override + void setNotification(String title, String body) { + channel.invokeMethod( + 'setNotificationBody', + [body], + ); + } + + @override + void sendEvent(BackgroundEvent event, { String? id }) { + final data = DataWrapper( + id ?? const Uuid().v4(), + event, + ); + // NOTE: *S*erver to *F*oreground + _log.fine('S2F: ${data.toJson().toString()}'); + channel.invokeMethod('sendData', jsonEncode(data.toJson())); + } + + @override + void init( + Future Function() entrypoint, + Future Function(Map? data) handleEvent, + ) { + WidgetsFlutterBinding.ensureInitialized(); + + // Ensure that all native plugins are registered against this FlutterEngine, so that + // we can use path_provider, notifications, ... + DartPluginRegistrant.ensureInitialized(); + + // Register the event handler + channel.setMethodCallHandler((MethodCall call) async { + final args = call.arguments! as String; + await handleEvent(jsonDecode(args) as Map); + }); + + setNotification('Moxxy', 'Preparing...'); + + _log.finest('Running...'); + + entrypoint(); + } +} diff --git a/packages/moxplatform_android/pubspec.yaml b/packages/moxplatform_android/pubspec.yaml index 78524e0..bc0989c 100644 --- a/packages/moxplatform_android/pubspec.yaml +++ b/packages/moxplatform_android/pubspec.yaml @@ -20,23 +20,25 @@ flutter: dependencies: flutter: sdk: flutter - moxplatform_platform_interface: - hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: 0.1.11 - moxplatform: - hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: 0.1.11 - + get_it: 7.2.0 + logging: 1.0.2 + media_scanner: 2.0.0 + meta: ^1.7.0 moxlib: hosted: https://git.polynom.me/api/packages/Moxxy/pub version: 0.1.4 - logging: 1.0.2 - get_it: 7.2.0 - uuid: 3.0.5 - media_scanner: 2.0.0 + + moxplatform: + hosted: https://git.polynom.me/api/packages/Moxxy/pub + version: 0.1.11 + moxplatform_platform_interface: + hosted: https://git.polynom.me/api/packages/Moxxy/pub + version: 0.1.11 + plugin_platform_interface: 2.1.2 - meta: ^1.7.0 + uuid: 3.0.5 dev_dependencies: flutter_test: sdk: flutter + very_good_analysis: 2.4.0 diff --git a/packages/moxplatform_generic/analysis_options.yaml b/packages/moxplatform_generic/analysis_options.yaml index a5744c1..f04c6cf 100644 --- a/packages/moxplatform_generic/analysis_options.yaml +++ b/packages/moxplatform_generic/analysis_options.yaml @@ -1,4 +1 @@ -include: package:flutter_lints/flutter.yaml - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +include: ../../analysis_options.yaml diff --git a/packages/moxplatform_generic/pubspec.yaml b/packages/moxplatform_generic/pubspec.yaml index e471e8f..135e2eb 100644 --- a/packages/moxplatform_generic/pubspec.yaml +++ b/packages/moxplatform_generic/pubspec.yaml @@ -30,3 +30,4 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.0 + very_good_analysis: 2.4.0 diff --git a/packages/moxplatform_linux/analysis_options.yaml b/packages/moxplatform_linux/analysis_options.yaml index a5744c1..f04c6cf 100644 --- a/packages/moxplatform_linux/analysis_options.yaml +++ b/packages/moxplatform_linux/analysis_options.yaml @@ -1,4 +1 @@ -include: package:flutter_lints/flutter.yaml - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +include: ../../analysis_options.yaml diff --git a/packages/moxplatform_linux/pubspec.yaml b/packages/moxplatform_linux/pubspec.yaml index e480b3b..2067376 100644 --- a/packages/moxplatform_linux/pubspec.yaml +++ b/packages/moxplatform_linux/pubspec.yaml @@ -12,9 +12,8 @@ dependencies: sdk: flutter moxplatform: - path: ../moxplatform - #hosted: https://git.polynom.me/api/packages/Moxxy/pub - #version: 0.1.11 + hosted: https://git.polynom.me/api/packages/Moxxy/pub + version: 0.1.11 moxplatform_generic: path: ../moxplatform_generic @@ -22,6 +21,7 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.0 + very_good_analysis: 2.4.0 flutter: plugin: diff --git a/packages/moxplatform_platform_interface/analysis_options.yaml b/packages/moxplatform_platform_interface/analysis_options.yaml new file mode 100644 index 0000000..f04c6cf --- /dev/null +++ b/packages/moxplatform_platform_interface/analysis_options.yaml @@ -0,0 +1 @@ +include: ../../analysis_options.yaml diff --git a/packages/moxplatform_platform_interface/lib/moxplatform_platform_interface.dart b/packages/moxplatform_platform_interface/lib/moxplatform_platform_interface.dart index 146a3dd..6422a37 100644 --- a/packages/moxplatform_platform_interface/lib/moxplatform_platform_interface.dart +++ b/packages/moxplatform_platform_interface/lib/moxplatform_platform_interface.dart @@ -1,29 +1,8 @@ -import "package:moxplatform_platform_interface/src/isolate.dart"; -import "package:moxplatform_platform_interface/src/isolate_stub.dart"; -import "package:moxplatform_platform_interface/src/media.dart"; -import "package:moxplatform_platform_interface/src/media_stub.dart"; -import "package:plugin_platform_interface/plugin_platform_interface.dart"; +library moxplatform_platform_interface; -abstract class MoxplatformInterface extends PlatformInterface { - /// Constructs a MyPluginPlatform. - MoxplatformInterface() : super(token: _token); - - static final Object _token = Object(); - - static IsolateHandler _handler = StubIsolateHandler(); - static MediaScannerImplementation _media = StubMediaScannerImplementation(); - - static IsolateHandler get handler => _handler; - static set handler(IsolateHandler instance) { - _handler = instance; - } - - static MediaScannerImplementation get media => _media; - static set media(MediaScannerImplementation instance) { - _media = instance; - } - - - /// Return the current platform name. - Future getPlatformName(); -} +export 'src/interface.dart'; +export 'src/isolate.dart'; +export 'src/isolate_stub.dart'; +export 'src/media.dart'; +export 'src/media_stub.dart'; +export 'src/service.dart'; diff --git a/packages/moxplatform_platform_interface/lib/src/interface.dart b/packages/moxplatform_platform_interface/lib/src/interface.dart new file mode 100644 index 0000000..7d348aa --- /dev/null +++ b/packages/moxplatform_platform_interface/lib/src/interface.dart @@ -0,0 +1,17 @@ +import 'package:moxplatform_platform_interface/src/isolate.dart'; +import 'package:moxplatform_platform_interface/src/isolate_stub.dart'; +import 'package:moxplatform_platform_interface/src/media.dart'; +import 'package:moxplatform_platform_interface/src/media_stub.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +abstract class MoxplatformInterface extends PlatformInterface { + MoxplatformInterface() : super(token: _token); + + static final Object _token = Object(); + + static IsolateHandler handler = StubIsolateHandler(); + static MediaScannerImplementation media = StubMediaScannerImplementation(); + + /// Return the current platform name. + Future getPlatformName(); +} diff --git a/packages/moxplatform_platform_interface/lib/src/isolate.dart b/packages/moxplatform_platform_interface/lib/src/isolate.dart index 7818615..dce1ca9 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/awaitabledatasender.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. @@ -6,17 +6,17 @@ import "package:moxlib/awaitabledatasender.dart"; abstract class IsolateHandler { /// Start the background service. /// [entrypoint] is the entrypoint that is run inside the new isolate. - /// [handeUiEvent] is a handler function that is called when the isolate receives data from the UI. + /// [handleUIEvent] is a handler function that is called when the isolate receives data from the UI. /// [handleIsolateEvent] is a handler function that is called when the UI receives data from the service. Future start( Future Function() entrypoint, Future Function(Map? data) handleUIEvent, - Future Function(Map? data) handleIsolateEvent + Future Function(Map? data) handleIsolateEvent, ); /// Make sure that the UI event handler is registered without starting the isolate. Future attach( - Future Function(Map? data) handleIsolateEvent + Future Function(Map? data) handleIsolateEvent, ); /// Return true if the background service is running. False if it's not. diff --git a/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart b/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart index da4cfcc..34d9e1a 100644 --- a/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart +++ b/packages/moxplatform_platform_interface/lib/src/isolate_stub.dart @@ -1,5 +1,5 @@ -import "package:moxlib/awaitabledatasender.dart"; -import "package:moxplatform_platform_interface/src/isolate.dart"; +import 'package:moxlib/awaitabledatasender.dart'; +import 'package:moxplatform_platform_interface/src/isolate.dart'; class StubDataSender extends AwaitableDataSender { StubDataSender() : super(); @@ -9,24 +9,25 @@ class StubDataSender extends AwaitableDataSender { } class StubIsolateHandler extends IsolateHandler { - final StubDataSender _sender; - StubIsolateHandler() : _sender = StubDataSender(); + final StubDataSender _sender; @override Future attach( - Future Function(Map? data) handleIsolateEvent + Future Function(Map? data) handleIsolateEvent, ) async { - print("STUB ATTACHED!!!!!!"); + // ignore: avoid_print + print('STUB ATTACHED!!!!!!'); } @override Future start( Future Function() entrypoint, Future Function(Map? data) handleUIEvent, - Future Function(Map? data) handleIsolateEvent + Future Function(Map? data) handleIsolateEvent, ) async { - print("STUB STARTED!!!!!!"); + // ignore: avoid_print + print('STUB STARTED!!!!!!'); } @override diff --git a/packages/moxplatform_platform_interface/lib/src/media.dart b/packages/moxplatform_platform_interface/lib/src/media.dart index cbc1f1d..23f7244 100644 --- a/packages/moxplatform_platform_interface/lib/src/media.dart +++ b/packages/moxplatform_platform_interface/lib/src/media.dart @@ -1,4 +1,5 @@ /// Wrapper around platform-specific media scanning +// ignore: one_member_abstracts abstract class MediaScannerImplementation { /// Let the platform-specific media scanner scan the file at [path]. void scanFile(String path); diff --git a/packages/moxplatform_platform_interface/lib/src/media_stub.dart b/packages/moxplatform_platform_interface/lib/src/media_stub.dart index 9f2ad80..5ce84ba 100644 --- a/packages/moxplatform_platform_interface/lib/src/media_stub.dart +++ b/packages/moxplatform_platform_interface/lib/src/media_stub.dart @@ -1,4 +1,4 @@ -import "package:moxplatform_platform_interface/src/media.dart"; +import 'package:moxplatform_platform_interface/src/media.dart'; class StubMediaScannerImplementation extends MediaScannerImplementation { @override diff --git a/packages/moxplatform_platform_interface/lib/src/service.dart b/packages/moxplatform_platform_interface/lib/src/service.dart index 90f6717..5f390bf 100644 --- a/packages/moxplatform_platform_interface/lib/src/service.dart +++ b/packages/moxplatform_platform_interface/lib/src/service.dart @@ -1,4 +1,4 @@ -import "package:moxplatform/types.dart"; +import 'package:moxplatform/moxplatform.dart'; abstract class BackgroundService { /// Set the notification of the background service, if available @@ -12,6 +12,6 @@ abstract class BackgroundService { /// data. void init( Future Function() entrypoint, - Future Function(Map? data) handleEvent + Future Function(Map? data) handleEvent, ); } diff --git a/packages/moxplatform_platform_interface/pubspec.yaml b/packages/moxplatform_platform_interface/pubspec.yaml index 84f8905..1e4e364 100644 --- a/packages/moxplatform_platform_interface/pubspec.yaml +++ b/packages/moxplatform_platform_interface/pubspec.yaml @@ -12,15 +12,16 @@ dependencies: flutter: sdk: flutter + moxlib: + hosted: https://git.polynom.me/api/packages/Moxxy/pub + version: 0.1.4 moxplatform: hosted: https://git.polynom.me/api/packages/Moxxy/pub version: 0.1.11 - moxlib: - hosted: https://git.polynom.me/api/packages/Moxxy/pub - version: 0.1.4 plugin_platform_interface: 2.1.2 dev_dependencies: flutter_test: sdk: flutter + very_good_analysis: 2.4.0