123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import 'package:flutter/foundation.dart';
- import 'package:flutter/services.dart';
- import 'wl_base_help_platform_interface.dart';
- /// An implementation of [WlBaseHelpPlatform] that uses method channels.
- class MethodChannelWlBaseHelp extends WlBaseHelpPlatform {
- /// The method channel used to interact with the native platform.
- @visibleForTesting
- final methodChannel = const MethodChannel('wl_base_help');
- @override
- Future<String?> getPlatformVersion() async {
- final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
- return version;
- }
- @override
- Future<String?> runAsAdministrator() async {
- try {
- await methodChannel.invokeMethod('runAsAdministrator');
- return null;
- } on PlatformException catch (e) {
- return e.code;
- }
- }
- @override
- Future<bool?> isRunningAsAdmin() async {
- final isAdmin = await methodChannel.invokeMethod<bool>('isRunningAsAdmin');
- return isAdmin;
- }
- @override
- Future<void> showConsole() async {
- await methodChannel.invokeMethod('showConsole');
- }
- @override
- Future<void> hideConsole() async {
- await methodChannel.invokeMethod('hideConsole');
- }
- @override
- Future<bool?> isProcessRunning(String processName) async {
- final isRunning = await methodChannel.invokeMethod('isProcessRunning', {'processName': processName});
- return isRunning;
- }
- @override
- Future<void> killProcess(String processName) async {
- await methodChannel.invokeMethod('killProcess', {'processName': processName});
- }
- @override
- Future<bool?> macIsAdmin() async {
- final isRunning = await methodChannel.invokeMethod('isAdmin');
- return isRunning;
- }
- @override
- Future<bool?> macIsProcessRunning() async {
- final isRunning = await methodChannel.invokeMethod('isProcessRunning');
- return isRunning;
- }
- // 新增:启用代理
- @override
- Future<void> startProxy(int port) async {
- return await methodChannel.invokeMethod('startProxy', {'port': port});
- }
- // 新增:禁用代理
- @override
- Future<void> stopProxy() async {
- return await methodChannel.invokeMethod('stopProxy');
- }
- // 新增:检测代理是否启用
- @override
- Future<bool> isProxyEnabled() async {
- return await methodChannel.invokeMethod('isProxyEnabled');
- }
- @override
- Future<bool> isDialUpEnabled() async {
- return await methodChannel.invokeMethod('isDialUpEnabled');
- }
- }
|