From 0095344b50f2a80c9a90137e79cba6a04c5fae2a Mon Sep 17 00:00:00 2001 From: wanghongenpin Date: Sat, 7 Mar 2026 11:51:56 +0800 Subject: [PATCH] Validate proxy port input and show error for out-of-range values --- lib/ui/component/proxy_port_setting.dart | 9 ++++++++- macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ui/component/proxy_port_setting.dart b/lib/ui/component/proxy_port_setting.dart index ebf2012..cacb3e0 100644 --- a/lib/ui/component/proxy_port_setting.dart +++ b/lib/ui/component/proxy_port_setting.dart @@ -30,7 +30,14 @@ class _PortState extends State { portFocus.addListener(() async { //失去焦点 if (!portFocus.hasFocus && textController.text != widget.proxyServer.port.toString()) { - widget.proxyServer.configuration.port = int.parse(textController.text); + final port = int.tryParse(textController.text) ?? -1; + if (port < 0 || port > 65535) { + textController.text = widget.proxyServer.port.toString(); + FlutterToastr.show("Port out of range 0-65535", context, duration: 3); + return; + } + + widget.proxyServer.configuration.port = port; if (widget.proxyServer.isRunning) { String message = localizations.proxyPortRepeat(widget.proxyServer.port); diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index dbdc78c..76534dc 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import device_info_plus import file_picker import flutter_desktop_context_menu import flutter_js +import path_provider_foundation import proxy_manager import screen_retriever_macos import share_plus @@ -24,6 +25,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin")) FlutterDesktopContextMenuPlugin.register(with: registry.registrar(forPlugin: "FlutterDesktopContextMenuPlugin")) FlutterJsPlugin.register(with: registry.registrar(forPlugin: "FlutterJsPlugin")) + PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) ProxyManagerPlugin.register(with: registry.registrar(forPlugin: "ProxyManagerPlugin")) ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))