From 223e0162af78dc2442010615993a6d6848c1d70c Mon Sep 17 00:00:00 2001 From: JSR Date: Fri, 20 Mar 2026 20:19:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=AA=E7=AB=96=E5=B1=8F?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=AF=BC=E8=87=B4=E7=AA=97=E5=8F=A3=E5=B0=BA?= =?UTF-8?q?=E5=AF=B8=E6=8C=81=E7=BB=AD=E5=A2=9E=E5=A4=A7=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c5f4742..4a5b406 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -279,6 +279,44 @@ function MainContent(): React.JSX.Element { if (key === "settings") navigate("/settings") } + const resolveOrientationTargetSize = (nextPortraitMode: boolean) => { + const currentWidth = Math.max(1, Math.round(window.innerWidth || 0)) + const currentHeight = Math.max(1, Math.round(window.innerHeight || 0)) + + // 切换横竖屏时优先以当前窗口尺寸“互换宽高”为目标,避免每次切换都朝固定大尺寸放大。 + let targetWidth = nextPortraitMode ? currentHeight : currentWidth + let targetHeight = nextPortraitMode ? currentWidth : currentHeight + + const rotatedWidth = nextPortraitMode ? currentHeight : currentWidth + const rotatedHeight = nextPortraitMode ? currentWidth : currentHeight + const ratio = rotatedWidth / Math.max(1, rotatedHeight) + + const availableWidth = window.screen?.availWidth || window.innerWidth || 1200 + const availableHeight = window.screen?.availHeight || window.innerHeight || 800 + const maxWidth = Math.max(420, Math.round(availableWidth - 64)) + const maxHeight = Math.max(520, Math.round(availableHeight - 64)) + + if (targetWidth > maxWidth) { + targetWidth = maxWidth + targetHeight = Math.max(1, Math.round(targetWidth / ratio)) + } + if (targetHeight > maxHeight) { + targetHeight = maxHeight + targetWidth = Math.max(1, Math.round(targetHeight * ratio)) + } + + if (nextPortraitMode && targetHeight <= targetWidth) { + targetHeight = Math.min(maxHeight, targetWidth + 200) + } else if (!nextPortraitMode && targetWidth <= targetHeight) { + targetWidth = Math.min(maxWidth, targetHeight + 200) + } + + return { + width: Math.max(420, Math.round(targetWidth)), + height: Math.max(520, Math.round(targetHeight)), + } + } + const toggleOrientationMode = async () => { const api = (window as any).api if (!api) return @@ -289,14 +327,15 @@ function MainContent(): React.JSX.Element { if (maximized) { await api.windowMaximize() } + const targetSize = resolveOrientationTargetSize(nextPortraitMode) if (nextPortraitMode) { await api.windowSetResizable(false) - await api.windowResize(940, 1600) + await api.windowResize(targetSize.width, targetSize.height) setSidebarCollapsed(true) setFloatingSidebarExpanded(false) } else { await api.windowSetResizable(true) - await api.windowResize(2560, 1440) + await api.windowResize(targetSize.width, targetSize.height) setSidebarCollapsed(false) setFloatingSidebarExpanded(false) }