From 8078c45d401694c37d62d2bd3ffc7bc1437395e7 Mon Sep 17 00:00:00 2001 From: wanghongenpin Date: Mon, 19 Aug 2024 22:13:24 +0800 Subject: [PATCH] iOS fix: Stop switching to the background for a long time and then start packet capture without network problem (#146) --- ios/Runner/AppDelegate.swift | 2 +- lib/network/bin/server.dart | 13 ++++++++++++- lib/ui/desktop/desktop.dart | 25 ++++++++++--------------- lib/ui/mobile/mobile.dart | 29 ++++++++++++++++------------- lib/ui/mobile/request/list.dart | 2 +- lib/ui/mobile/widgets/about.dart | 2 +- linux/build.sh | 3 +-- macos/Runner/AppDelegate.swift | 2 +- pubspec.yaml | 10 +++++----- 9 files changed, 48 insertions(+), 40 deletions(-) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index bf5fd86..c0b7563 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -2,7 +2,7 @@ import UIKit import Flutter import NetworkExtension -@UIApplicationMain +@main @objc class AppDelegate: FlutterAppDelegate { var backgroundAudioEnable: Bool = true diff --git a/lib/network/bin/server.dart b/lib/network/bin/server.dart index dd93934..51f5b02 100644 --- a/lib/network/bin/server.dart +++ b/lib/network/bin/server.dart @@ -15,6 +15,7 @@ */ import 'dart:async'; +import 'dart:io'; import 'package:network_proxy/network/bin/configuration.dart'; import 'package:network_proxy/network/channel.dart'; @@ -84,6 +85,16 @@ class ProxyServer { }); } + ///检查是否监听端口 没有监听则启动 + Future startForCheck() async { + try { + var socket = await Socket.connect('127.0.0.1', port, timeout: const Duration(milliseconds: 100)); + socket.close(); + } catch (e) { + await start(); + } + } + /// 停止代理服务 Future stop() async { if (!isRunning) { @@ -115,7 +126,7 @@ class ProxyServer { /// 重启代理服务 Future restart() async { - await stop().then((value) => start()); + await stop().whenComplete(() => start()); } ///添加监听器 diff --git a/lib/ui/desktop/desktop.dart b/lib/ui/desktop/desktop.dart index cb6e9b6..d2ce030 100644 --- a/lib/ui/desktop/desktop.dart +++ b/lib/ui/desktop/desktop.dart @@ -119,27 +119,22 @@ class _DesktopHomePagePageState extends State implements EventL }, child: Text(localizations.cancel)) ], - title: Text(isCN ? '更新内容V1.1.1' : "Update content V1.1.1", style: const TextStyle(fontSize: 18)), + title: Text(isCN ? '更新内容V1.1.2' : "Update content V1.1.2", style: const TextStyle(fontSize: 18)), content: Text( isCN ? '提示:默认不会开启HTTPS抓包,请安装证书后再开启HTTPS抓包。\n' '点击HTTPS抓包(加锁图标),选择安装根证书,按照提示操作即可。\n\n' - '1. 支持导入自定义跟证书,以及生成自定义根证书;\n' - '2. 支持重新生成根证书,以及重置默认跟证书;\n' - '3. 支持导出根证书(p12)和私钥;\n' - '4. 历史记录支持重放所有请求;\n' - '5. 重放域名下请求;\n' - '6. 修复请求重写列表换行问题;\n' - '7. 脚本headers支持同名多个值情况;\n' + '1. iOS 通知栏显示VPN状态;\n' + '2. iOS修复停止长时间切换后台再开启抓包无网络问题;\n' + '3. 修复请求重发和脚本导致URL错误;\n' + '4. 修复脚本二进制body转换问题;\n' + '5. 修复请求编辑中文路径编码问题;\n' : 'Tips:By default, HTTPS packet capture will not be enabled. Please install the certificate before enabling HTTPS packet capture。\n' 'Click HTTPS Capture packets(Lock icon),Choose to install the root certificate and follow the prompts to proceed。\n\n' - '1. Support importing custom certificates and generating custom root certificates;\n' - '2. Support generate new root certificates and resetting default root certificates;\n' - '3. Support exporting root certificates and private keys;\n' - '4. History supports replaying all requests;\n' - '5. Replay domain name request;\n' - '6. Fix request rewrite list word wrapping;\n' - '7. Script headers support multiple values with the same name;\n' + '1. iOS notification bar displays VPN status;\n' + '2. iOS fix: Stop switching to the background for a long time and then start packet capture without network problem;\n' + '3. fix request repeat & script change url wrong;\n' + '4. fix script binary body convert;\n' '', style: const TextStyle(fontSize: 14))); }); diff --git a/lib/ui/mobile/mobile.dart b/lib/ui/mobile/mobile.dart index 5852e4e..53bd166 100644 --- a/lib/ui/mobile/mobile.dart +++ b/lib/ui/mobile/mobile.dart @@ -207,6 +207,11 @@ class MobileHomeState extends State implements EventListener, Li startup: proxyServer.configuration.startup, serverLaunch: false, onStart: () async { + //ios端口可能会被系统杀掉 + if (Platform.isIOS) { + await proxyServer.restart(); + } + Vpn.startVpn( Platform.isAndroid ? await localIp() : "127.0.0.1", proxyServer.port, proxyServer.configuration); }, @@ -219,21 +224,19 @@ class MobileHomeState extends State implements EventListener, Li String content = isCN ? '提示:默认不会开启HTTPS抓包,请安装证书后再开启HTTPS抓包。\n\n' - '1. 支持导入自定义跟证书,以及生成自定义根证书;\n' - '2. 支持重新生成根证书,以及重置默认跟证书;\n' - '3. 支持导出根证书(P12)和私钥;\n' - '4. 重放域名下请求;\n' - '5. 修复请求重写列表换行问题;\n' - '6. 脚本headers支持同名多个值情况;\n' + '1. iOS 通知栏显示VPN状态;\n' + '2. iOS修复停止长时间切换后台再开启抓包无网络问题;\n' + '3. 修复请求重发和脚本导致URL错误;\n' + '4. 修复脚本二进制body转换问题;\n' + '5. 修复请求编辑中文路径编码问题;\n' : 'Tips:By default, HTTPS packet capture will not be enabled. Please install the certificate before enabling HTTPS packet capture。\n\n' 'Click HTTPS Capture packets(Lock icon),Choose to install the root certificate and follow the prompts to proceed。\n\n' - '1. Support importing custom certificates and generating custom root certificates;\n' - '2. Support generate new root certificates and resetting default root certificates;\n' - '3. Support exporting root certificates(P12) and private keys;\n' - '4. Replay domain name request;\n' - '5. Fix request rewrite list word wrapping;\n' - '6. Script headers support multiple values with the same name;\n'; - showAlertDialog(isCN ? '更新内容V1.1.1' : "Update content V1.1.1", content, () { + '1. iOS notification bar displays VPN status;\n' + '2. iOS fix: Stop switching to the background for a long time and then start packet capture without network problem;\n' + '3. fix request repeat & script change url wrong;\n' + '4. fix script binary body convert;\n' + ''; + showAlertDialog(isCN ? '更新内容V1.1.2' : "Update content V1.1.2", content, () { widget.appConfiguration.upgradeNoticeV10 = false; widget.appConfiguration.flushConfig(); }); diff --git a/lib/ui/mobile/request/list.dart b/lib/ui/mobile/request/list.dart index 304a42e..5e00990 100644 --- a/lib/ui/mobile/request/list.dart +++ b/lib/ui/mobile/request/list.dart @@ -238,7 +238,7 @@ class RequestSequenceState extends State with AutomaticKeepAliv //防止频繁刷新 if (!changing) { changing = true; - Future.delayed(const Duration(milliseconds: 50), () { + Future.delayed(const Duration(milliseconds: 150), () { setState(() { changing = false; }); diff --git a/lib/ui/mobile/widgets/about.dart b/lib/ui/mobile/widgets/about.dart index 299eb0d..119d16a 100644 --- a/lib/ui/mobile/widgets/about.dart +++ b/lib/ui/mobile/widgets/about.dart @@ -22,7 +22,7 @@ class About extends StatelessWidget { padding: const EdgeInsets.only(left: 10, right: 10), child: Text(isCN ? "全平台开源免费抓包软件" : "Full platform open source free capture HTTP(S) traffic software")), const SizedBox(height: 10), - const Text("V1.1.1"), + const Text("V1.1.2"), ListTile( title: const Text("Github"), trailing: const Icon(Icons.arrow_right), diff --git a/linux/build.sh b/linux/build.sh index cf4f159..451310e 100644 --- a/linux/build.sh +++ b/linux/build.sh @@ -1,12 +1,11 @@ #!/bin/bash - pwd cd ../build/linux/x64/release rm -rf package mkdir -p package/DEBIAN echo "Package: ProxyPin" >> package/DEBIAN/control -echo "Version: 1.1.1" >> package/DEBIAN/control +echo "Version: 1.1.2" >> package/DEBIAN/control echo "Priority: optional" >> package/DEBIAN/control echo "Architecture: amd64" >> package/DEBIAN/control echo "Depends: ca-certificates" >> package/DEBIAN/control diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index af55012..5dc2fdd 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import Cocoa import FlutterMacOS -@NSApplicationMain +@main class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { diff --git a/pubspec.yaml b/pubspec.yaml index c2edd60..da663eb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: network_proxy description: ProxyPin publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 1.1.1+11 +version: 1.1.2+11 environment: sdk: '>=3.0.2 <4.0.0' @@ -18,12 +18,12 @@ dependencies: basic_utils: ^5.7.0 logger: ^2.0.1 date_format: ^2.0.7 - window_manager: ^0.3.8 + window_manager: ^0.4.0 desktop_multi_window: git: url: https://gitee.com/wanghongenpin/flutter-plugins.git path: packages/desktop_multi_window - path_provider: ^2.1.3 + path_provider: ^2.1.4 url_launcher: ^6.3.0 proxy_manager: ^0.0.3 qr_flutter: ^4.1.0 @@ -36,11 +36,11 @@ dependencies: file_selector: ^1.0.3 flutter_js: ^0.8.1 flutter_code_editor: ^0.3.2 - file_picker: ^8.0.5 + file_picker: ^8.0.7 flutter_desktop_context_menu: ^0.2.0 win32audio: ^1.3.1 device_info_plus: ^10.1.1 - shared_preferences: ^2.2.3 + shared_preferences: ^2.3.1 dev_dependencies: flutter_test: