refactor: Rename src to packages
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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 {
|
||||
/// 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<String?> getPlatformName();
|
||||
}
|
||||
27
packages/moxplatform_platform_interface/lib/src/isolate.dart
Normal file
27
packages/moxplatform_platform_interface/lib/src/isolate.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
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.
|
||||
/// This class only deals with the direction of UI -> Service.
|
||||
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.
|
||||
/// [handleIsolateEvent] is a handler function that is called when the UI receives data from the service.
|
||||
Future<void> start(
|
||||
Future<void> Function() entrypoint,
|
||||
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent
|
||||
);
|
||||
|
||||
/// Make sure that the UI event handler is registered without starting the isolate.
|
||||
Future<void> attach(
|
||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent
|
||||
);
|
||||
|
||||
/// Return true if the background service is running. False if it's not.
|
||||
Future<bool> isRunning();
|
||||
|
||||
/// Return the [AwaitableDataSender] for communicating with the service.
|
||||
AwaitableDataSender getDataSender();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import "package:moxlib/awaitabledatasender.dart";
|
||||
import "package:moxplatform_platform_interface/src/isolate.dart";
|
||||
|
||||
class StubDataSender extends AwaitableDataSender {
|
||||
StubDataSender() : super();
|
||||
|
||||
@override
|
||||
Future<void> sendDataImpl(DataWrapper data) async {}
|
||||
}
|
||||
|
||||
class StubIsolateHandler extends IsolateHandler {
|
||||
final StubDataSender _sender;
|
||||
|
||||
StubIsolateHandler() : _sender = StubDataSender();
|
||||
|
||||
@override
|
||||
Future<void> attach(
|
||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent
|
||||
) async {
|
||||
print("STUB ATTACHED!!!!!!");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> start(
|
||||
Future<void> Function() entrypoint,
|
||||
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent
|
||||
) async {
|
||||
print("STUB STARTED!!!!!!");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> isRunning() async => false;
|
||||
|
||||
@override
|
||||
AwaitableDataSender getDataSender() => _sender;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/// Wrapper around platform-specific media scanning
|
||||
abstract class MediaScannerImplementation {
|
||||
/// Let the platform-specific media scanner scan the file at [path].
|
||||
void scanFile(String path);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import "package:moxplatform_platform_interface/src/media.dart";
|
||||
|
||||
class StubMediaScannerImplementation extends MediaScannerImplementation {
|
||||
@override
|
||||
void scanFile(String path) {}
|
||||
}
|
||||
17
packages/moxplatform_platform_interface/lib/src/service.dart
Normal file
17
packages/moxplatform_platform_interface/lib/src/service.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import "package:moxplatform/types.dart";
|
||||
|
||||
abstract class BackgroundService {
|
||||
/// Set the notification of the background service, if available
|
||||
void setNotification(String title, String body);
|
||||
|
||||
/// Send data from the background service to the UI.
|
||||
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
|
||||
/// data.
|
||||
void init(
|
||||
Future<void> Function() entrypoint,
|
||||
Future<void> Function(Map<String, dynamic>? data) handleEvent
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user