Skip to content

Commit 4633f15

Browse files
committed
fix(titlebar): sync window width to panel-hidden state on startup
The titlebar's panel-toggle path physically shrinks the OS window by 320px per hidden panel (var(--w-left/right)) — but Tauri does NOT persist window size across restarts (no tauri-plugin-window-state), so a user who closed with panels hidden reopened at the full 1600px default with a stretched-empty center column. Toggling a panel back on then grew the window past 1600px because adjustWindowForPanel works in deltas from the current size — every restart-then-show cycle ballooned the window by another 320px on the affected axis. Sync the window width to the persisted leftPanelHidden / rightPanelHidden flags BEFORE invoke('show_main_window') reveals it. The window starts with visible: false from tauri.conf.json, so the resize completes during the same paint cycle that flips visibility — no flash. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e514d28 commit 4633f15

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

src-ui/src/main.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,42 @@ if (typeof document !== 'undefined' && document.fonts) {
4343
// Window starts with `visible: false` (see tauri.conf.json) to hide the
4444
// Windows-default chrome flash. Reveal it only after the first paint so
4545
// the first frame the user sees is the final themed UI.
46+
//
47+
// Before reveal, sync window width to the persisted panel-hidden state
48+
// (cc-left-hidden / cc-right-hidden). The titlebar's panel-toggle path
49+
// physically shrinks the window by 320px per panel, but Tauri does NOT
50+
// persist window size across restarts (no tauri-plugin-window-state).
51+
// Without this sync, a user who closed with panels hidden would reopen
52+
// at the full 1600px default with a stretched-empty center column, and
53+
// toggling a panel back on would grow the window past 1600px because
54+
// adjustWindowForPanel works in deltas from the current size. Keep
55+
// PANEL_WIDTH in sync with TitleBar.tsx and the --w-left/right CSS vars.
56+
async function syncWindowToPanelStateAndShow() {
57+
try {
58+
const leftHidden = localStorage.getItem('cc-left-hidden') === '1';
59+
const rightHidden = localStorage.getItem('cc-right-hidden') === '1';
60+
const hiddenCount = (leftHidden ? 1 : 0) + (rightHidden ? 1 : 0);
61+
if (hiddenCount > 0) {
62+
const { getCurrentWindow, PhysicalSize } = await import('@tauri-apps/api/window');
63+
const w = getCurrentWindow();
64+
if (!(await w.isMaximized())) {
65+
const scale = await w.scaleFactor();
66+
const shrinkPx = Math.round(320 * hiddenCount * scale);
67+
const minWidthPx = Math.round(900 * scale); // matches tauri.conf.json minWidth
68+
const size = await w.innerSize();
69+
const targetW = Math.max(minWidthPx, size.width - shrinkPx);
70+
if (targetW !== size.width) {
71+
await w.setSize(new PhysicalSize(targetW, size.height));
72+
}
73+
}
74+
}
75+
} catch {}
76+
invoke('show_main_window').catch(() => {});
77+
}
78+
4679
requestAnimationFrame(() => {
4780
requestAnimationFrame(() => {
48-
invoke('show_main_window').catch(() => {});
81+
void syncWindowToPanelStateAndShow();
4982
});
5083
});
5184

0 commit comments

Comments
 (0)