From 8ef7ff1ce98d9ac946fecad70af71e41e50b4aff Mon Sep 17 00:00:00 2001 From: xuwenwei Date: Tue, 9 Jun 2026 12:04:18 +0800 Subject: [PATCH] Hide 'Transfer file' and 'TCP tunneling' menu items in relay mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plan B for the punch UI: don't just grey out file transfer — hide it entirely when the connection is relay. The user can't try to use it, and we save the toast explanation. When punch succeeds (P2P, direct), the menu items reappear. Applied to: - Transfer file - TCP tunneling (Leaving View camera and Terminal in the menu regardless of mode — they don't use server bandwidth significantly.) --- flutter/lib/common/widgets/toolbar.dart | 41 ++++++++++++------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/flutter/lib/common/widgets/toolbar.dart b/flutter/lib/common/widgets/toolbar.dart index 56451a8..7ae486e 100644 --- a/flutter/lib/common/widgets/toolbar.dart +++ b/flutter/lib/common/widgets/toolbar.dart @@ -451,17 +451,25 @@ List toolbarControls(BuildContext context, String id, FFI ffi) { } if (isDefaultConn && isDesktop) { - v.add( - TTextMenu( - child: Text(translate('Transfer file')), - onPressed: () { - if (!isDirectConnection(id)) { - showToast('中继模式:当前连接走服务器 21117 中转,文件传输已被禁用以避免占用过多服务器带宽。'); - return; - } - connectWithToken(isFileTransfer: true); - }), - ); + // Custom fork: only show the "Transfer file" and "TCP tunneling" menu + // items when the connection is P2P (direct). In relay mode, hide them + // entirely so the user can't even try. Reason: server bandwidth is + // scarce (5 Mbps for 4 users) and a single file transfer can saturate + // it; better to surface the limitation up-front than show a disabled + // grey item with a toast. + final showP2POnlyMenus = isDirectConnection(id); + if (showP2POnlyMenus) { + v.add( + TTextMenu( + child: Text(translate('Transfer file')), + onPressed: () => connectWithToken(isFileTransfer: true)), + ); + v.add( + TTextMenu( + child: Text(translate('TCP tunneling')), + onPressed: () => connectWithToken(isTcpTunneling: true)), + ); + } v.add( TTextMenu( child: Text(translate('View camera')), @@ -472,17 +480,6 @@ List toolbarControls(BuildContext context, String id, FFI ffi) { child: Text('${translate('Terminal')} (beta)'), onPressed: () => connectWithToken(isTerminal: true)), ); - v.add( - TTextMenu( - child: Text(translate('TCP tunneling')), - onPressed: () { - if (!isDirectConnection(id)) { - showToast('中继模式:TCP 隧道已被禁用以避免占用过多服务器带宽。'); - return; - } - connectWithToken(isTcpTunneling: true); - }), - ); } // note if (isDefaultConn && !bind.isDisableAccount()) {