Feature: Show TLS and MCP state in the server status bar

The main window's status bar now carries two short panes between the host
count and the FRP address. The first reports whether the server identity is
loaded, using the same ServerTlsIdentity::IsReady() check the rest of the UI
uses, so a menu that claims TLS is on cannot leave the bar saying otherwise
when the certificate failed to load. The second reports whether MCP is
enabled and, while it is, which protocol the endpoint speaks: (HTTP) or
(HTTPS) according to McpHttps. Both panes follow the existing 60 second
statistics tick, and toggling either switch in its dialog refreshes them at
once instead of leaving the bar stale until the next tick.

Pane widths are measured from the widest text each pane can show in the
current language instead of hardcoded pixels, and the measurement selects
the status bar's own font: DEFAULT_GUI_FONT is about 8% narrower than the
Segoe UI the bar paints with, which would have clipped "MCP: ... (HTTPS)"
at higher display scaling. Switching HTTP/HTTPS keeps the column width
steady, and turning MCP off lets it shrink again.

The MCP settings dialog was also missing translations for several of its
labels, the file write switch among them, which is why they stayed Chinese
in the English UI. Those keys, together with the status bar ones, are added
to all three language files.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-01 10:53:04 +01:00
1 parent e99092ca70
commit 559681ea01
7 files changed
+124 -23

No files matched your search

+86 -17
View File
@@ -346,11 +346,42 @@ static bool ShouldLogAuth(const std::string& sn, int success) {
static UINT Indicators[] = {
IDR_STATUSBAR_STRING,
IDR_STATUSBAR_TLS, // 服务端 TLS 证书:有/无
IDR_STATUSBAR_MCP, // MCP 启用状态:开/关
IDR_STATUSBAR_FRP, // FRP 地址(由上级提供)
IDR_STATUSBAR_RUNTIME,
IDR_STATUSBAR_EXPIRE
};
// 状态栏短标签分区(TLS/MCP)的宽度:按当前语言下两种取值的实际文本宽度取大者,
// 再留出左右边距。硬编码像素在不同语言/DPI 下容易被截断或浪费空间。
static int CalcStatusFlagPaneWidth(const CStatusBar& bar, const CString& a, const CString& b)
{
CClientDC dc((CWnd*)&bar);
CFont* pOld = nullptr;
CFont* pFont = bar.GetFont();
// 状态栏没有显式设过字体时,绘制用的是系统的「状态栏字体」(Segoe UI 9pt),
// 比 DEFAULT_GUI_FONT 宽约 8%:100% 缩放下靠边距还能兜住,缩放比更高就会截断,
// 所以这里直接按状态栏字体测量。
CFont statusFont;
if (pFont == nullptr) {
NONCLIENTMETRICS ncm = {};
ncm.cbSize = sizeof(ncm);
if (::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0)
&& statusFont.CreateFontIndirect(&ncm.lfStatusFont))
pFont = &statusFont;
}
if (pFont == nullptr)
pFont = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
if (pFont != nullptr)
pOld = dc.SelectObject(pFont);
CSize szA = dc.GetTextExtent(a);
CSize szB = dc.GetTextExtent(b);
if (pOld != nullptr)
dc.SelectObject(pOld);
return max(szA.cx, szB.cx) + 16;
}
std::string EventName()
{
char eventName[64];
@@ -3404,8 +3435,8 @@ void CMy2015RemoteDlg::StartFrpcAuto(const FrpAutoConfig& cfg)
m_strFrpAddr.Format(_T("%hs:%d"), cfg.serverAddr.c_str(), cfg.remotePort);
// 直接更新状态栏 FRP 分区(不触发 OnSize 避免循环)
if (m_StatusBar.GetSafeHwnd()) {
m_StatusBar.SetPaneInfo(1, m_StatusBar.GetItemID(1), SBPS_NORMAL, 250);
m_StatusBar.SetPaneText(1, m_strFrpAddr);
m_StatusBar.SetPaneInfo(3, m_StatusBar.GetItemID(3), SBPS_NORMAL, 250);
m_StatusBar.SetPaneText(3, m_strFrpAddr);
}
Mprintf("[FRP-Auto] 启动自动代理: %s:%d -> frps:%d\n",
@@ -3434,8 +3465,8 @@ void CMy2015RemoteDlg::StopFrpcAuto()
m_strFrpAddr.Empty();
// 直接更新状态栏 FRP 分区(不触发 OnSize 避免循环)
if (m_StatusBar.GetSafeHwnd()) {
m_StatusBar.SetPaneInfo(1, m_StatusBar.GetItemID(1), SBPS_NORMAL, 0);
m_StatusBar.SetPaneText(1, _T(""));
m_StatusBar.SetPaneInfo(3, m_StatusBar.GetItemID(3), SBPS_NORMAL, 0);
m_StatusBar.SetPaneText(3, _T(""));
}
Mprintf("[FRP-Auto] 已停止\n");
@@ -3774,16 +3805,20 @@ void CMy2015RemoteDlg::OnSize(UINT nType, int cx, int cy)
Rect.right=cx;
Rect.bottom=cy;
m_StatusBar.MoveWindow(Rect);
// 4个分区:消息(自动拉伸)、FRP地址(250px)、运行统计(180px)、到期时间(180px)
// 6个分区:消息(自动拉伸)、TLS、MCP、FRP地址(250px)、运行统计(180px)、到期时间(180px)
int paneExpire = m_strExpireDate.IsEmpty() ? 0 : 180; // 无到期信息时隐藏
// 优先显示上级 FRPC,其次显示本机 FRPS
int paneFrp = 250;
int paneRuntime = 180;
int paneMsg = max(0, cx - paneFrp - paneRuntime - paneExpire - 20);
int paneTls = max(0, m_nPaneTlsWidth);
int paneMcp = max(0, m_nPaneMcpWidth);
int paneMsg = max(0, cx - paneTls - paneMcp - paneFrp - paneRuntime - paneExpire - 20);
m_StatusBar.SetPaneInfo(0, m_StatusBar.GetItemID(0), SBPS_STRETCH, paneMsg);
m_StatusBar.SetPaneInfo(1, m_StatusBar.GetItemID(1), SBPS_NORMAL, paneFrp);
m_StatusBar.SetPaneInfo(2, m_StatusBar.GetItemID(2), SBPS_NORMAL, paneRuntime);
m_StatusBar.SetPaneInfo(3, m_StatusBar.GetItemID(3), SBPS_NORMAL, paneExpire);
m_StatusBar.SetPaneInfo(1, m_StatusBar.GetItemID(1), SBPS_NORMAL, paneTls);
m_StatusBar.SetPaneInfo(2, m_StatusBar.GetItemID(2), SBPS_NORMAL, paneMcp);
m_StatusBar.SetPaneInfo(3, m_StatusBar.GetItemID(3), SBPS_NORMAL, paneFrp);
m_StatusBar.SetPaneInfo(4, m_StatusBar.GetItemID(4), SBPS_NORMAL, paneRuntime);
m_StatusBar.SetPaneInfo(5, m_StatusBar.GetItemID(5), SBPS_NORMAL, paneExpire);
}
if(m_ToolBar.m_hWnd!=NULL) { //工具条
@@ -3978,6 +4013,8 @@ void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent)
CRect rc;
GetClientRect(&rc);
OnSize(SIZE_RESTORED, rc.Width(), rc.Height());
// 此时服务端已 Activate、TLS 身份已加载,补一次刷新让 TLS/MCP 状态立刻正确
UpdateStatusBarStats();
}
__super::OnTimer(nIDEvent);
@@ -4030,7 +4067,7 @@ void CMy2015RemoteDlg::CheckHeartbeat()
}
}
// 更新状态栏统计信息(MTBF/运行时长、到期时间)
// 更新状态栏统计信息(TLS/MCP 状态、FRP 地址、MTBF/运行时长、到期时间)
void CMy2015RemoteDlg::UpdateStatusBarStats()
{
if (!m_StatusBar.GetSafeHwnd())
@@ -4038,7 +4075,32 @@ void CMy2015RemoteDlg::UpdateStatusBarStats()
CString strRuntime, strExpire;
// === 分区1:运行统计 ===
// === 分区1/2:TLS / MCP 状态 ===
// TLS:服务端身份已加载([tls] Enabled 且证书/私钥可用)。与协议切换等处用同一判定,
// 避免「菜单显示已启用但证书加载失败」时状态栏给出错误结论。
CString strTls = ServerTlsIdentity::IsReady() ? _TR("TLS: 有") : _TR("TLS: 无");
// MCP:读配置开关。启用后需重启才真正监听,此处反映的是「已启用」这一配置意图;
// 启用时一并标出访问协议(McpHttps=1 走 TLS 前端,证书坏了启动时整体 fail-closed)。
CString strMcp;
CString strMcpWidest;
if (THIS_CFG.GetInt("settings", "McpEnabled", 0)) {
strMcp = _TR("MCP: 开");
strMcp += THIS_CFG.GetInt("settings", "McpHttps", 0) ? _T(" (HTTPS)") : _T(" (HTTP)");
// 协议在 HTTP/HTTPS 之间切换时列宽保持稳定
strMcpWidest = _TR("MCP: 开") + _T(" (HTTPS)");
} else {
strMcp = _TR("MCP: 关");
strMcpWidest = strMcp;
}
// 宽度取当前状态下的最大取值(关闭时收窄,开启时按最长协议串留足)
m_nPaneTlsWidth = CalcStatusFlagPaneWidth(m_StatusBar, _TR("TLS: 有"), _TR("TLS: 无"));
m_nPaneMcpWidth = CalcStatusFlagPaneWidth(m_StatusBar, strMcp, strMcpWidest);
m_StatusBar.SetPaneInfo(1, m_StatusBar.GetItemID(1), SBPS_NORMAL, m_nPaneTlsWidth);
m_StatusBar.SetPaneText(1, strTls);
m_StatusBar.SetPaneInfo(2, m_StatusBar.GetItemID(2), SBPS_NORMAL, m_nPaneMcpWidth);
m_StatusBar.SetPaneText(2, strMcp);
// === 分区4:运行统计 ===
if (m_runNormal == 1) {
// 普通模式:显示程序运行时长
ULONGLONG uptime = GetTickCount64() - m_ullStartTime;
@@ -4094,7 +4156,7 @@ void CMy2015RemoteDlg::UpdateStatusBarStats()
strRuntime = _TR("运行:") + CString(_T(" ")) + strTime + _T(" ") + _TR("(无崩溃)");
}
}
// === 分区1:FRP 地址 ===
// === 分区3:FRP 地址 ===
// 优先显示上级配置的 FRPC,其次显示本机 FRPS
CString strFrpDisplay = m_strFrpAddr;
if (strFrpDisplay.IsEmpty()) {
@@ -4121,12 +4183,13 @@ void CMy2015RemoteDlg::UpdateStatusBarStats()
}
// 根据是否有内容设置分区宽度
int paneFrpWidth = 250;
m_StatusBar.SetPaneInfo(1, m_StatusBar.GetItemID(1), SBPS_NORMAL, paneFrpWidth);
m_StatusBar.SetPaneText(1, strFrpDisplay);
m_StatusBar.SetPaneInfo(3, m_StatusBar.GetItemID(3), SBPS_NORMAL, paneFrpWidth);
m_StatusBar.SetPaneText(3, strFrpDisplay);
m_StatusBar.SetPaneText(2, strRuntime);
// === 分区4:运行统计 ===
m_StatusBar.SetPaneText(4, strRuntime);
// === 分区3:到期时间 ===
// === 分区5:到期时间 ===
// 定期刷新到期时间(每 5 分钟从配置重新读取,以便反映上级延展)
static ULONGLONG lastExpireRefresh = 0;
ULONGLONG now = GetTickCount64();
@@ -4175,7 +4238,7 @@ void CMy2015RemoteDlg::UpdateStatusBarStats()
strDays.Format(_T("(%lld"), diffDays);
strExpire = _TR("到期:") + CString(_T(" ")) + strDate + _T(" ") + strDays + _TR("天") + _T(")");
}
m_StatusBar.SetPaneText(3, strExpire);
m_StatusBar.SetPaneText(5, strExpire);
}
}
@@ -12453,6 +12516,9 @@ void CMy2015RemoteDlg::OnMcpSettings()
pExtMenu->CheckMenuItem(ID_MCP_SETTINGS, MF_BYCOMMAND |
(THIS_CFG.GetInt("settings", "McpEnabled", 0) ? MF_CHECKED : MF_UNCHECKED));
}
// 状态栏 MCP 分区立即跟随切换结果(不等 60s 定时器)
UpdateStatusBarStats();
}
void CMy2015RemoteDlg::OnTlsCertificate()
@@ -12468,6 +12534,9 @@ void CMy2015RemoteDlg::OnTlsCertificate()
pExtMenu->CheckMenuItem(ID_TLS_CERTIFICATE, MF_BYCOMMAND |
(THIS_CFG.GetInt("tls", "Enabled", 0) ? MF_CHECKED : MF_UNCHECKED));
}
// 状态栏 TLS 分区立即跟随切换结果(对话框内已热重载身份,不等 60s 定时器)
UpdateStatusBarStats();
}
void CMy2015RemoteDlg::OnConnectionManage()