Add Linux support
This commit is contained in:
41
packages/moxdns_linux/lib/moxdns_linux.dart
Normal file
41
packages/moxdns_linux/lib/moxdns_linux.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import "package:moxdns/moxdns.dart";
|
||||
import "package:moxdns_platform_interface/moxdns_platform_interface.dart";
|
||||
import "package:flutter/services.dart";
|
||||
|
||||
class MoxdnsLinuxPlugin extends MoxdnsPlatform {
|
||||
final MethodChannel _channel;
|
||||
|
||||
MoxdnsLinuxPlugin() : _channel = MethodChannel("me.polynom.moxdns_linux"), super();
|
||||
|
||||
static void registerWith() {
|
||||
print("MoxdnsLinuxPlugin: Registering implementation");
|
||||
MoxdnsPlugin.platform = MoxdnsLinuxPlugin();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<SrvRecord>> srvQuery(String domain, bool dnssec) async {
|
||||
try {
|
||||
final List<dynamic> results = await _channel.invokeMethod("srvQuery", {
|
||||
"domain": domain,
|
||||
"dnssec": dnssec
|
||||
});
|
||||
final records = List<SrvRecord>.empty(growable: true);
|
||||
for (var record in results) {
|
||||
if (record == null) {
|
||||
continue;
|
||||
}
|
||||
final rr = Map<String, dynamic>.from(record);
|
||||
records.add(SrvRecord(
|
||||
rr["target"]!,
|
||||
rr["port"]! as int,
|
||||
rr["priority"]! as int,
|
||||
rr["weight"]! as int
|
||||
));
|
||||
}
|
||||
return records;
|
||||
} on PlatformException catch(e) {
|
||||
print("moxdns_linux: $e");
|
||||
return const [];
|
||||
}
|
||||
}
|
||||
}
|
||||
17
packages/moxdns_linux/lib/moxdns_linux_method_channel.dart
Normal file
17
packages/moxdns_linux/lib/moxdns_linux_method_channel.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'moxdns_linux_platform_interface.dart';
|
||||
|
||||
/// An implementation of [MoxdnsLinuxPlatform] that uses method channels.
|
||||
class MethodChannelMoxdnsLinux extends MoxdnsLinuxPlatform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
final methodChannel = const MethodChannel('moxdns_linux');
|
||||
|
||||
@override
|
||||
Future<String?> getPlatformVersion() async {
|
||||
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'moxdns_linux_method_channel.dart';
|
||||
|
||||
abstract class MoxdnsLinuxPlatform extends PlatformInterface {
|
||||
/// Constructs a MoxdnsLinuxPlatform.
|
||||
MoxdnsLinuxPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static MoxdnsLinuxPlatform _instance = MethodChannelMoxdnsLinux();
|
||||
|
||||
/// The default instance of [MoxdnsLinuxPlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelMoxdnsLinux].
|
||||
static MoxdnsLinuxPlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific implementations should set this with their own
|
||||
/// platform-specific class that extends [MoxdnsLinuxPlatform] when
|
||||
/// they register themselves.
|
||||
static set instance(MoxdnsLinuxPlatform instance) {
|
||||
PlatformInterface.verifyToken(instance, _token);
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
Future<String?> getPlatformVersion() {
|
||||
throw UnimplementedError('platformVersion() has not been implemented.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user