wl_base_help_method_channel.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/services.dart';
  3. import 'wl_base_help_platform_interface.dart';
  4. /// An implementation of [WlBaseHelpPlatform] that uses method channels.
  5. class MethodChannelWlBaseHelp extends WlBaseHelpPlatform {
  6. /// The method channel used to interact with the native platform.
  7. @visibleForTesting
  8. final methodChannel = const MethodChannel('wl_base_help');
  9. @override
  10. Future<String?> getPlatformVersion() async {
  11. final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
  12. return version;
  13. }
  14. @override
  15. Future<String?> runAsAdministrator() async {
  16. try {
  17. await methodChannel.invokeMethod('runAsAdministrator');
  18. return null;
  19. } on PlatformException catch (e) {
  20. return e.code;
  21. }
  22. }
  23. @override
  24. Future<bool?> isRunningAsAdmin() async {
  25. final isAdmin = await methodChannel.invokeMethod<bool>('isRunningAsAdmin');
  26. return isAdmin;
  27. }
  28. @override
  29. Future<void> showConsole() async {
  30. await methodChannel.invokeMethod('showConsole');
  31. }
  32. @override
  33. Future<void> hideConsole() async {
  34. await methodChannel.invokeMethod('hideConsole');
  35. }
  36. @override
  37. Future<bool?> isProcessRunning(String processName) async {
  38. final isRunning = await methodChannel.invokeMethod('isProcessRunning', {'processName': processName});
  39. return isRunning;
  40. }
  41. @override
  42. Future<void> killProcess(String processName) async {
  43. await methodChannel.invokeMethod('killProcess', {'processName': processName});
  44. }
  45. @override
  46. Future<bool?> macIsAdmin() async {
  47. final isRunning = await methodChannel.invokeMethod('isAdmin');
  48. return isRunning;
  49. }
  50. @override
  51. Future<bool?> macIsProcessRunning() async {
  52. final isRunning = await methodChannel.invokeMethod('isProcessRunning');
  53. return isRunning;
  54. }
  55. // 新增:启用代理
  56. @override
  57. Future<void> startProxy(int port) async {
  58. return await methodChannel.invokeMethod('startProxy', {'port': port});
  59. }
  60. // 新增:禁用代理
  61. @override
  62. Future<void> stopProxy() async {
  63. return await methodChannel.invokeMethod('stopProxy');
  64. }
  65. // 新增:检测代理是否启用
  66. @override
  67. Future<bool> isProxyEnabled() async {
  68. return await methodChannel.invokeMethod('isProxyEnabled');
  69. }
  70. @override
  71. Future<bool> isDialUpEnabled() async {
  72. return await methodChannel.invokeMethod('isDialUpEnabled');
  73. }
  74. }