From db874790a3108bae71b77db22b94738cb32f2b03 Mon Sep 17 00:00:00 2001 From: wanghongen Date: Mon, 23 Oct 2023 02:00:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=89=E5=8D=93=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=8A=93=E5=8C=85=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../network/proxy/plugin/VpnServicePlugin.kt | 2 +- lib/main.dart | 1 + lib/ui/component/multi_window.dart | 8 +++++-- lib/ui/desktop/toolbar/phone_connect.dart | 2 +- lib/ui/desktop/toolbar/setting/setting.dart | 2 +- lib/ui/mobile/mobile.dart | 24 ++++++++++++------- lib/utils/ip.dart | 2 +- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/android/app/src/main/kotlin/com/network/proxy/plugin/VpnServicePlugin.kt b/android/app/src/main/kotlin/com/network/proxy/plugin/VpnServicePlugin.kt index 95cd4a2..67ddaee 100644 --- a/android/app/src/main/kotlin/com/network/proxy/plugin/VpnServicePlugin.kt +++ b/android/app/src/main/kotlin/com/network/proxy/plugin/VpnServicePlugin.kt @@ -47,7 +47,7 @@ class VpnServicePlugin : AndroidFlutterPlugin() { * 启动vpn服务 */ private fun startVpn(host: String, port: Int, allowApps: ArrayList?) { - Log.i("com.network.proxy", "startVpn $allowApps") + Log.i("com.network.proxy", "startVpn $host:$port $allowApps") val intent = Intent(activity, ProxyVpnService::class.java) intent.putExtra(ProxyVpnService.ProxyHost, host) intent.putExtra(ProxyVpnService.ProxyPort, port) diff --git a/lib/main.dart b/lib/main.dart index 34b0251..bef39a8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -45,6 +45,7 @@ void main(List args) async { }); var uiConfiguration = await instance; + registerMethodHandler(); runApp(FluentApp(DesktopHomePage(configuration: await configuration), uiConfiguration: uiConfiguration)); } diff --git a/lib/ui/component/multi_window.dart b/lib/ui/component/multi_window.dart index 6175196..35f50fe 100644 --- a/lib/ui/component/multi_window.dart +++ b/lib/ui/component/multi_window.dart @@ -15,8 +15,12 @@ import 'package:path_provider/path_provider.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:window_manager/window_manager.dart'; +bool isMultiWindow = false; + ///多窗口 Widget multiWindow(int windowId, Map argument) { + isMultiWindow = true; + //请求编辑器 if (argument['name'] == 'RequestEditor') { return RequestEditor( windowController: WindowController.fromWindowId(windowId), @@ -68,7 +72,7 @@ encodeWindow(EncoderType type, BuildContext context, [String? text]) async { bool _registerHandler = false; -void methodHandler() { +void registerMethodHandler() { if (_registerHandler) { return; } @@ -113,7 +117,7 @@ openScriptWindow() async { if (Platform.isWindows) { ratio = WindowManager.instance.getDevicePixelRatio(); } - methodHandler(); + registerMethodHandler(); final window = await DesktopMultiWindow.createWindow(jsonEncode( {'name': 'ScriptWidget'}, )); diff --git a/lib/ui/desktop/toolbar/phone_connect.dart b/lib/ui/desktop/toolbar/phone_connect.dart index f93729c..a61a802 100644 --- a/lib/ui/desktop/toolbar/phone_connect.dart +++ b/lib/ui/desktop/toolbar/phone_connect.dart @@ -6,7 +6,7 @@ class PhoneConnect extends StatefulWidget { final ProxyServer proxyServer; final List hosts; - const PhoneConnect({Key? key, required this.proxyServer, required this.hosts}) : super(key: key); + const PhoneConnect({super.key, required this.proxyServer, required this.hosts}); @override State createState() { diff --git a/lib/ui/desktop/toolbar/setting/setting.dart b/lib/ui/desktop/toolbar/setting/setting.dart index e525fc6..bb19f87 100644 --- a/lib/ui/desktop/toolbar/setting/setting.dart +++ b/lib/ui/desktop/toolbar/setting/setting.dart @@ -100,7 +100,7 @@ class _SettingState extends State { builder: (context) { return AlertDialog( titlePadding: const EdgeInsets.only(left: 24, top: 10, right: 15), - contentPadding: const EdgeInsets.only(left: 24, right: 20), + contentPadding: const EdgeInsets.only(left: 24, right: 20, bottom: 15), scrollable: true, title: const Row(children: [ Text("请求重写", style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500)), diff --git a/lib/ui/mobile/mobile.dart b/lib/ui/mobile/mobile.dart index f36c9a5..060f908 100644 --- a/lib/ui/mobile/mobile.dart +++ b/lib/ui/mobile/mobile.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:network_proxy/native/vpn.dart'; @@ -8,11 +9,13 @@ import 'package:network_proxy/network/channel.dart'; import 'package:network_proxy/network/handler.dart'; import 'package:network_proxy/network/http/http.dart'; import 'package:network_proxy/network/http_client.dart'; +import 'package:network_proxy/ui/component/utils.dart'; import 'package:network_proxy/ui/launch/launch.dart'; import 'package:network_proxy/ui/mobile/connect_remote.dart'; import 'package:network_proxy/ui/mobile/menu.dart'; import 'package:network_proxy/ui/mobile/request/list.dart'; import 'package:network_proxy/ui/mobile/request/search.dart'; +import 'package:network_proxy/utils/ip.dart'; class MobileHomePage extends StatefulWidget { final Configuration configuration; @@ -89,15 +92,18 @@ class MobileHomeState extends State implements EventListener { ]), drawer: DrawerWidget(proxyServer: proxyServer, requestStateKey: requestStateKey), floatingActionButton: FloatingActionButton( - onPressed: null, - child: Center( - child: SocketLaunch( - proxyServer: proxyServer, - size: 36, - startup: false, - serverLaunch: false, - onStart: () => Vpn.startVpn("127.0.0.1", proxyServer.port, proxyServer.configuration.appWhitelist), - onStop: () => Vpn.stopVpn())), + onPressed: null, + child: Center( + child: futureWidget( + localIp(), + (data) => SocketLaunch( + proxyServer: proxyServer, + size: 36, + startup: false, + serverLaunch: false, + onStart: () => Vpn.startVpn(Platform.isAndroid ? data : "127.0.0.1", proxyServer.port, + proxyServer.configuration.appWhitelist), + onStop: () => Vpn.stopVpn()))), ), body: ValueListenableBuilder( valueListenable: desktop, diff --git a/lib/utils/ip.dart b/lib/utils/ip.dart index 56d1af1..3d66dac 100644 --- a/lib/utils/ip.dart +++ b/lib/utils/ip.dart @@ -59,5 +59,5 @@ Future networkName() { // en0(macos系统) or WLAN(widows设备名)优先 bool primary(NetworkInterface it) { - return it.name == 'en0' || it.name.startsWith('WLAN') || it.name.startsWith("wlan"); + return it.name == 'en0' || it.name.startsWith('WLAN') || it.name.startsWith("wlan") || it.name.startsWith('ccmn'); }