Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ pub async fn main() {
.plugin(tauri_plugin_js::init())
.plugin(
tauri_plugin_window_state::Builder::default()
.skip_initial_state("main")
.with_state_flags(tauri_plugin_windows::persisted_window_state_flags())
.with_denylist(&["composer"])
.build(),
)
.plugin(tauri_plugin_transcription::init())
Expand Down
58 changes: 58 additions & 0 deletions apps/desktop/src/shared/main/chat-panels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,64 @@ describe("MainChatPanels", () => {
expect(mocks.windowRestoreWidth).toHaveBeenCalledTimes(1);
});

it("does not restore window width when leaving a meeting for settings with chat still open", () => {
mocks.chatMode = "RightPanelOpen";
mocks.currentTab = { type: "sessions" };
mocks.leftSidebarExpanded = true;
mockPanelWidths({
bodyPanelWidth: 700,
leftSidebarWidth: 200,
rightPanelWidth: 120,
});

const renderPanels = () => (
<MainChatPanels>
<div data-left-sidebar-chrome />
<div data-chat-floating-anchor>
<div data-session-surface />
</div>
</MainChatPanels>
);
const { rerender } = render(renderPanels());

expect(mocks.windowExpandWidth).toHaveBeenCalled();
mocks.windowRestoreWidth.mockClear();

mocks.currentTab = { type: "settings" };
rerender(renderPanels());

expect(mocks.windowRestoreWidth).not.toHaveBeenCalled();
});

it("restores window width when docked chat closes while the sidebar stays open", () => {
mocks.chatMode = "RightPanelOpen";
mocks.currentTab = { type: "sessions" };
mocks.leftSidebarExpanded = true;
mockPanelWidths({
bodyPanelWidth: 700,
leftSidebarWidth: 200,
rightPanelWidth: 120,
});

const renderPanels = () => (
<MainChatPanels>
<div data-left-sidebar-chrome />
<div data-chat-floating-anchor>
<div data-session-surface />
</div>
</MainChatPanels>
);
const { rerender } = render(renderPanels());

expect(mocks.windowExpandWidth).toHaveBeenCalled();
mocks.windowRestoreWidth.mockClear();

mocks.chatMode = "FloatingClosed";
rerender(renderPanels());

expect(mocks.windowRestoreWidth).toHaveBeenCalledTimes(1);
});

it("collapses the left sidebar when a window resize would make the note surface narrower than 500px", () => {
mocks.currentTab = { type: "sessions" };
mocks.leftSidebarExpanded = true;
Expand Down
10 changes: 9 additions & 1 deletion apps/desktop/src/shared/main/chat-panels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,18 @@ function useNoteSurfaceWindowWidthGuard({
useLayoutEffect(() => {
const previousState = previousStateRef.current;
const hasOpenPanel = enabled && (leftPanelOpen || rightPanelOpen);
const rightPanelJustClosed =
previousState.rightPanelOpen && !rightPanelOpen;

if (
rightPanelJustClosed ||
(enabled && !leftPanelOpen && !rightPanelOpen)
) {
restoreWidthExpansions();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-entry re-expands unsaved width

Medium Severity

Skipping restore when leaving a meeting with docked chat open no longer matches the “panel just opened” detection. Returning to a note-surface tab still treats leftPanelOpen / rightPanelOpen as newly opened via !previousState.enabled, so the width guard can expand again on top of the already-expanded frame and stack another restorable expansion.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 70c62cb. Configure here.


if (!hasOpenPanel) {
previousStateRef.current = { enabled, leftPanelOpen, rightPanelOpen };
restoreWidthExpansions();
return;
}

Expand Down
8 changes: 1 addition & 7 deletions plugins/windows/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,6 @@ impl AppWindow {
}

if let Some(window) = self.get(app) {
if matches!(self, Self::Main) {
use tauri_plugin_window_state::{StateFlags, WindowExt};

let _ = window.restore_state(StateFlags::SIZE | StateFlags::POSITION);
}

self.ensure_visible(app, &window);
window.show()?;
window.set_focus()?;
Expand All @@ -385,7 +379,7 @@ impl AppWindow {
use tauri_plugin_window_state::{StateFlags, WindowExt};

let state_flags = if matches!(self, Self::Main) {
StateFlags::SIZE | StateFlags::POSITION
crate::persisted_window_state_flags()
} else {
StateFlags::SIZE
};
Expand Down
26 changes: 22 additions & 4 deletions plugins/windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ pub use ext::{Windows, WindowsPluginExt};
pub use tab::*;
pub use window::*;

const PLUGIN_NAME: &str = "windows";

use std::collections::HashMap;
use std::sync::{
Mutex,
atomic::{AtomicBool, AtomicU64, Ordering},
};
use std::time::{Duration, Instant};

const PLUGIN_NAME: &str = "windows";

pub fn persisted_window_state_flags() -> tauri_plugin_window_state::StateFlags {
use tauri_plugin_window_state::StateFlags;
StateFlags::SIZE | StateFlags::POSITION | StateFlags::MAXIMIZED
}

const WEBVIEW_RECOVERY_GRACE_PERIOD: Duration = Duration::from_secs(10);

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -307,8 +312,8 @@ pub fn init() -> tauri::plugin::TauriPlugin<tauri::Wry> {
})
.on_event(move |app, event| {
if let tauri::RunEvent::ExitRequested { .. } = event {
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
let _ = app.save_window_state(StateFlags::SIZE);
use tauri_plugin_window_state::AppHandleExt;
let _ = app.save_window_state(persisted_window_state_flags());
}
})
.build()
Expand Down Expand Up @@ -394,6 +399,19 @@ mod test {
assert!(expansions.0.lock().unwrap().is_empty());
}

#[test]
fn persisted_window_state_includes_size_and_position() {
use tauri_plugin_window_state::StateFlags;

let flags = persisted_window_state_flags();
assert!(flags.contains(StateFlags::SIZE));
assert!(flags.contains(StateFlags::POSITION));
assert!(flags.contains(StateFlags::MAXIMIZED));
assert!(!flags.contains(StateFlags::VISIBLE));
assert!(!flags.contains(StateFlags::DECORATIONS));
assert!(!flags.contains(StateFlags::FULLSCREEN));
}

#[test]
fn saved_frame_take_consumes_window_entry() {
let frames = SavedFrames::default();
Expand Down
16 changes: 8 additions & 8 deletions plugins/windows/src/window/v1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::WindowImpl;

const MAIN_WINDOW_WIDTH: f64 = 910.0;
const MAIN_WINDOW_HEIGHT: f64 = 600.0;
const NOTE_WINDOW_WIDTH: f64 = 720.0;
const NOTE_WINDOW_HEIGHT: f64 = 820.0;
const NOTE_WINDOW_POSITION_TOLERANCE: f64 = 1.0;
Expand Down Expand Up @@ -201,10 +203,9 @@ impl WindowImpl for AppWindow {
.window_builder(app, "/app")
.maximizable(true)
.minimizable(true)
.min_inner_size(500.0, 500.0);
let window = builder.build()?;
window.set_size(LogicalSize::new(910.0, 600.0))?;
window
.min_inner_size(500.0, 500.0)
.inner_size(MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT);
builder.build()?
}
Self::Composer => {
let builder = self
Expand All @@ -226,10 +227,9 @@ impl WindowImpl for AppWindow {
.window_builder(app, format!("/app/note/{encoded_id}"))
.maximizable(true)
.minimizable(true)
.min_inner_size(420.0, 500.0);
let window = builder.build()?;
window.set_size(LogicalSize::new(NOTE_WINDOW_WIDTH, NOTE_WINDOW_HEIGHT))?;
window
.min_inner_size(420.0, 500.0)
.inner_size(NOTE_WINDOW_WIDTH, NOTE_WINDOW_HEIGHT);
builder.build()?
}
};

Expand Down
Loading