style: Lint using very_good_analysis
This commit is contained in:
@@ -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<String> getPlatformName() async => "Android";
|
||||
}
|
||||
export 'src/isolate_android.dart';
|
||||
export 'src/media_android.dart';
|
||||
export 'src/plugin_android.dart';
|
||||
export 'src/service_android.dart';
|
||||
|
||||
@@ -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<String?> getPlatformVersion() async {
|
||||
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -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<String?> getPlatformVersion() {
|
||||
throw UnimplementedError('platformVersion() has not been implemented.');
|
||||
}
|
||||
}
|
||||
@@ -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<void> Function() entrypoint,
|
||||
Future<void> Function(Map<String, dynamic>? 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();
|
||||
}
|
||||
}
|
||||
@@ -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<BackgroundCommand, BackgroundEvent> {
|
||||
|
||||
BackgroundServiceDataSender()
|
||||
: _channel = const MethodChannel('me.polynom.moxplatform_android'), super();
|
||||
final MethodChannel _channel;
|
||||
BackgroundServiceDataSender() : _channel = MethodChannel("me.polynom.moxplatform_android"), super();
|
||||
|
||||
@override
|
||||
Future<void> sendDataImpl(DataWrapper data) async {
|
||||
await _channel.invokeMethod("sendData", jsonEncode(data.toJson()));
|
||||
await _channel.invokeMethod<void>('sendData', jsonEncode(data.toJson()));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> 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<String>(
|
||||
'getExtraData',
|
||||
<void>[],
|
||||
);
|
||||
final data = jsonDecode(result!) as Map<String, dynamic>;
|
||||
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<void> androidEntrypoint() async {
|
||||
GetIt.I.registerSingleton<BackgroundService>(srv);
|
||||
srv.init(
|
||||
entrypoint! as Future<void> Function(),
|
||||
handleUIEvent! as Future<void> Function(Map<String, dynamic>? data)
|
||||
handleUIEvent! as Future<void> Function(Map<String, dynamic>? 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<void> attach(Future<void> Function(Map<String, dynamic>? 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<String, dynamic>);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,35 +77,35 @@ class AndroidIsolateHandler extends IsolateHandler {
|
||||
Future<void> start(
|
||||
Future<void> Function() entrypoint,
|
||||
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent
|
||||
Future<void> Function(Map<String, dynamic>? 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<void>('configure', <dynamic>[
|
||||
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<bool>('start', <void>[]);
|
||||
if (result == true) {
|
||||
_log.finest('Service successfully started');
|
||||
} else {
|
||||
_log.severe("Service failed to start");
|
||||
_log.severe('Service failed to start');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> isRunning() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
return await _channel.invokeMethod("isRunning", []);
|
||||
return (await _channel.invokeMethod<bool>('isRunning', <void>[])) == true;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -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
|
||||
15
packages/moxplatform_android/lib/src/plugin_android.dart
Normal file
15
packages/moxplatform_android/lib/src/plugin_android.dart
Normal file
@@ -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<String> getPlatformName() async => 'Android';
|
||||
}
|
||||
64
packages/moxplatform_android/lib/src/service_android.dart
Normal file
64
packages/moxplatform_android/lib/src/service_android.dart
Normal file
@@ -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<void>(
|
||||
'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<void>('sendData', jsonEncode(data.toJson()));
|
||||
}
|
||||
|
||||
@override
|
||||
void init(
|
||||
Future<void> Function() entrypoint,
|
||||
Future<void> Function(Map<String, dynamic>? 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<String, dynamic>);
|
||||
});
|
||||
|
||||
setNotification('Moxxy', 'Preparing...');
|
||||
|
||||
_log.finest('Running...');
|
||||
|
||||
entrypoint();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user