дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
fix(macos): wait for windows to finish leaving full screen before Merge All moves tabs (#7480)
Merge All Project Windows invoked from a group in native full screen aborted the app: tabs were moved with `addTabbedWindow` while the full-screen exit animation was still running, and AppKit threw. `merge` now waits (up to 3 s) for the windows that were in full screen, or already leaving it, to finish, then re-checks the candidates before moving tabs. Co-authored-by: audichuang <[email protected]>
Цей коміт міститься в:
1 джерело
6820d27af5
коміт
875b17938e
3 files changed
+58
-2
No files matched your search
@@ -14,7 +14,7 @@ pub fn window_group_current(window: WebviewWindow) -> IdeResult<Vec<groups::Wind
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn window_group_merge(window: WebviewWindow) -> IdeResult<()> {
|
||||
groups::merge(window.app_handle(), window.label())?;
|
||||
groups::merge(window.app_handle(), window.label()).await?;
|
||||
groups::persist(window.app_handle()).await
|
||||
}
|
||||
|
||||
|
||||
@@ -491,6 +491,27 @@ pub fn set_height(window: &tauri::WebviewWindow, height: f64) -> tauri::Result<(
|
||||
})
|
||||
}
|
||||
|
||||
/// For each of `windows`: whether it is in native full screen or on its way in or out, and whether
|
||||
/// it is leaving (from `willExit` to `didExit`).
|
||||
pub fn fullscreen_states(windows: &[tauri::WebviewWindow]) -> tauri::Result<Vec<(bool, bool)>> {
|
||||
let Some(first) = windows.first() else { return Ok(Vec::new()) };
|
||||
let labels: Vec<String> = windows.iter().map(|w| w.label().to_owned()).collect();
|
||||
let check = move || {
|
||||
WINDOWS.with_borrow(|tracked| {
|
||||
let state = |l: &String| tracked.get(l).map(|t| (t.state.entered.get(), t.state.leaving.get()));
|
||||
labels.iter().map(|l| state(l).unwrap_or_default()).collect()
|
||||
})
|
||||
};
|
||||
if MainThreadMarker::new().is_some() {
|
||||
return Ok(check());
|
||||
}
|
||||
let (tx, rx) = std::sync::mpsc::sync_channel(1);
|
||||
first.run_on_main_thread(move || {
|
||||
let _ = tx.send(check());
|
||||
})?;
|
||||
rx.recv().map_err(|_| tauri::Error::FailedToReceiveMessage)
|
||||
}
|
||||
|
||||
/// Stops tracking a destroyed window, which removes its notification observers.
|
||||
pub fn forget(window: &tauri::Window) {
|
||||
let label = window.label().to_owned();
|
||||
|
||||
@@ -169,19 +169,54 @@ pub fn join(app: &AppHandle, anchor: &str, new_window: &str) -> IdeResult<()> {
|
||||
select(app, anchor, new_window)
|
||||
}
|
||||
|
||||
pub fn merge(app: &AppHandle, caller: &str) -> IdeResult<()> {
|
||||
pub async fn merge(app: &AppHandle, caller: &str) -> IdeResult<()> {
|
||||
let all_windows = windows::project_window_labels(app);
|
||||
let members =
|
||||
ide_workspace::window_groups::merge_candidates(&all_windows, caller, |label| is_project_window(app, label));
|
||||
if members.len() < 2 || !members.iter().any(|label| label == caller) {
|
||||
return Err(IdeError::invalid("Open at least two project windows to create a window group"));
|
||||
}
|
||||
// Windows in full screen, or already leaving it (another Merge All, the user): an `entered`
|
||||
// left over from a failed entry is neither, so it cannot hold Merge All up.
|
||||
#[cfg(target_os = "macos")]
|
||||
let leaving: Vec<_> = {
|
||||
let windows: Vec<_> = members.iter().filter_map(|label| app.get_webview_window(label)).collect();
|
||||
let states = crate::titlebar::fullscreen_states(&windows).map_err(|e| IdeError::internal(e.to_string()))?;
|
||||
windows
|
||||
.into_iter()
|
||||
.zip(states)
|
||||
.filter(|(w, (_, leaving))| *leaving || w.is_fullscreen().unwrap_or(false))
|
||||
.map(|(w, _)| w)
|
||||
.collect()
|
||||
};
|
||||
// Native fullscreen puts each window in a separate Space; leave it before grouping.
|
||||
for label in &members {
|
||||
if let Some(window) = app.get_webview_window(label) {
|
||||
window.set_fullscreen(false).map_err(|e| IdeError::internal(e.to_string()))?;
|
||||
}
|
||||
}
|
||||
// Leaving full screen animates after `set_fullscreen` returns, and moving tabs into a window
|
||||
// still leaving it raises an Objective-C exception that aborts the app.
|
||||
#[cfg(target_os = "macos")]
|
||||
if !leaving.is_empty() {
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(3);
|
||||
while crate::titlebar::fullscreen_states(&leaving)
|
||||
.map_err(|e| IdeError::internal(e.to_string()))?
|
||||
.iter()
|
||||
.any(|(entered, _)| *entered)
|
||||
{
|
||||
if std::time::Instant::now() >= deadline {
|
||||
return Err(IdeError::invalid("Project windows are still leaving full screen"));
|
||||
}
|
||||
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
||||
}
|
||||
// Project windows may have opened or closed while waiting.
|
||||
let now = windows::project_window_labels(app);
|
||||
let now = ide_workspace::window_groups::merge_candidates(&now, caller, |label| is_project_window(app, label));
|
||||
if now.iter().collect::<HashSet<_>>() != members.iter().collect::<HashSet<_>>() {
|
||||
return Err(IdeError::invalid("Project windows changed while leaving full screen"));
|
||||
}
|
||||
}
|
||||
// If a member is currently grouped with a window outside `members` (e.g. a non-project
|
||||
// window), separate it from that native/frame group before merging.
|
||||
let state = app.state::<WindowsState>();
|
||||
|
||||
Reference in new issue
Заблокувати користувача