mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-03-15 04:23:17 +08:00
31 lines
1.1 KiB
Dart
31 lines
1.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:proxypin/network/channel/host_port.dart';
|
|
import 'package:proxypin/network/util/process_info.dart';
|
|
|
|
class ProcessInfoPlugin {
|
|
static const MethodChannel _methodChannel = MethodChannel('com.proxy/processInfo');
|
|
|
|
static Future<ProcessInfo?> getProcessByPort(String host, int port) {
|
|
return _methodChannel.invokeMethod<Map>('getProcessByPort', {"host": host, "port": port}).then((process) {
|
|
if (process == null) return null;
|
|
|
|
return ProcessInfo(process['packageName'], process['name'], process['packageName'],
|
|
os: Platform.operatingSystem,
|
|
icon: process['icon'],
|
|
remoteHost: process['remoteHost'],
|
|
remotePost: process['remotePort']);
|
|
});
|
|
}
|
|
|
|
static Future<HostAndPort?> getRemoteAddressByPort(int port) async {
|
|
if (!Platform.isAndroid) return null;
|
|
|
|
return _methodChannel.invokeMethod<Map>('getRemoteAddressByPort', {"port": port}).then((process) {
|
|
if (process == null) return null;
|
|
return HostAndPort.host(process['remoteHost'], process['remotePort']);
|
|
});
|
|
}
|
|
}
|