дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
fix(windows): open one Settings window when it is requested in a burst (#6870)
The auxiliary-window commands are async, so several requests for the same window (Ctrl+Alt+S pressed quickly or held) could all pass the already-open check before the first window registered; five parallel requests opened five Settings windows for one project window. The window's creation is now claimed before the check, and a request arriving during the build leaves its launch for that window and returns. Fixes #6630
Цей коміт міститься в:
1 джерело
97598641be
коміт
016240ac1b
1 file changed
+38
@@ -345,6 +345,9 @@ pub struct WindowsState {
|
||||
restart: AtomicBool,
|
||||
/// Numbers windows of kinds that can open several times per project window.
|
||||
aux_serial: AtomicU64,
|
||||
/// Auxiliary windows being built: commands run in parallel, so a burst of the same request
|
||||
/// (Settings pressed repeatedly) would otherwise pass the already-open check together.
|
||||
creating: Mutex<HashSet<String>>,
|
||||
/// Logical sizes remembered per [`AuxKind`] on macOS (`auxiliary-windows.json`), avoiding
|
||||
/// `tauri-plugin-window-state`'s physical-pixel scale-factor drift across mixed-DPI displays.
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -599,6 +602,11 @@ impl WindowsState {
|
||||
*self.last_focused.lock() = Some(label.to_owned());
|
||||
}
|
||||
|
||||
/// Claims the creation of window `label`; `None` while another request is already building it.
|
||||
fn begin_creating(&self, label: &str) -> Option<CreatingWindow<'_>> {
|
||||
self.creating.lock().insert(label.to_owned()).then(|| CreatingWindow { state: self, label: label.to_owned() })
|
||||
}
|
||||
|
||||
pub fn forget(&self, label: &str) {
|
||||
self.close_settled(label);
|
||||
{
|
||||
@@ -1882,6 +1890,18 @@ pub struct AuxWindow {
|
||||
|
||||
/// Opens an auxiliary window of `caller`'s project window, centred over it. A matching window
|
||||
/// receives the new launch ([`LAUNCH_EVENT`]) and is focused.
|
||||
/// Releases a [`WindowsState::begin_creating`] claim once the window exists (or failed to).
|
||||
struct CreatingWindow<'a> {
|
||||
state: &'a WindowsState,
|
||||
label: String,
|
||||
}
|
||||
|
||||
impl Drop for CreatingWindow<'_> {
|
||||
fn drop(&mut self) {
|
||||
self.state.creating.lock().remove(&self.label);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_auxiliary_window(app: &AppHandle, caller: &WebviewWindow, aux: AuxWindow) -> IdeResult<()> {
|
||||
// Asked from an auxiliary window itself: open it for that window's parent.
|
||||
let parent_label = auxiliary_parent(caller.label()).unwrap_or(caller.label()).to_owned();
|
||||
@@ -1899,6 +1919,14 @@ pub fn open_auxiliary_window(app: &AppHandle, caller: &WebviewWindow, aux: AuxWi
|
||||
} else {
|
||||
format!("{}-{parent_label}", aux.kind.name())
|
||||
};
|
||||
// Already being built for an earlier request: that window shows and focuses itself. Claimed
|
||||
// before the check below, so a request arriving as the build finishes finds the window.
|
||||
let Some(_creating) = windows.begin_creating(&label) else {
|
||||
if aux.launch != Launch::default() {
|
||||
windows.set_launch(&label, aux.launch);
|
||||
}
|
||||
return Ok(());
|
||||
};
|
||||
if let Some(existing) = app.get_webview_window(&label) {
|
||||
if aux.launch != Launch::default() {
|
||||
windows.set_launch(&label, aux.launch);
|
||||
@@ -2749,6 +2777,16 @@ fn macos_webview_configuration<'a>(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn a_window_being_built_is_claimed_once_until_it_exists() {
|
||||
let state = WindowsState::default();
|
||||
let first = state.begin_creating("settings-main").expect("first request builds");
|
||||
assert!(state.begin_creating("settings-main").is_none(), "a second request waits for the first");
|
||||
assert!(state.begin_creating("settings-other").is_some(), "other windows are independent");
|
||||
drop(first);
|
||||
assert!(state.begin_creating("settings-main").is_some());
|
||||
}
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Заблокувати користувача