fix(quick-pane): serialize native visibility

This commit is contained in:
2026-08-25 23:17:50 +02:00
parent 4fc9c60ade
commit 0ec7d224a2
+37 -9
View File
@@ -9,6 +9,7 @@ use tauri::{
};
struct LegacySubscription(Mutex<Option<JoinHandle<()>>>);
struct QuickPaneVisibility(Mutex<bool>);
struct WorkspaceSubscription {
generation: Arc<bridge::SubscriptionGeneration>,
task: Mutex<Option<JoinHandle<()>>>,
@@ -64,9 +65,9 @@ fn should_hide_close_request(label: &str) -> bool {
label == "quick-pane"
}
fn get_or_create_quick_pane(app: &AppHandle) -> Result<WebviewWindow, String> {
fn get_or_create_quick_pane(app: &AppHandle) -> Result<(WebviewWindow, bool), String> {
if let Some(window) = app.get_webview_window("quick-pane") {
return Ok(window);
return Ok((window, false));
}
let config = app
.config()
@@ -75,33 +76,49 @@ fn get_or_create_quick_pane(app: &AppHandle) -> Result<WebviewWindow, String> {
.iter()
.find(|window| window.label == "quick-pane")
.ok_or_else(|| "Quick Pane window configuration is missing".to_owned())?;
WebviewWindowBuilder::from_config(app, config)
let window = WebviewWindowBuilder::from_config(app, config)
.map_err(|error| error.to_string())?
.build()
.map_err(|error| error.to_string())
.map_err(|error| error.to_string())?;
Ok((window, true))
}
fn toggle_quick_pane(app: &AppHandle) {
let window = match get_or_create_quick_pane(app) {
Ok(window) => window,
let (window, created) = match get_or_create_quick_pane(app) {
Ok(result) => result,
Err(error) => {
eprintln!("Could not create Quick Pane window: {error}");
return;
}
};
match quick_pane_action(window.is_visible().unwrap_or(false)) {
let Some(state) = app.try_state::<QuickPaneVisibility>() else {
eprintln!("Quick Pane visibility state is unavailable");
return;
};
let mut current = state
.0
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
if created {
*current = false;
}
match quick_pane_action(*current) {
WindowAction::Hide => {
let _ = window.hide();
if window.hide().is_ok() {
*current = false;
}
}
WindowAction::ShowAndFocus => {
if let Some(main) = app.get_webview_window("main") {
let _ = main.hide();
}
let _ = window.show();
if window.show().is_ok() {
*current = true;
let _ = window.unminimize();
let _ = window.set_focus();
}
}
}
}
fn requested_new_worktree_argument(args: &[String]) -> Option<String> {
@@ -426,6 +443,7 @@ pub fn run() {
let builder = tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.manage(LegacySubscription(Mutex::new(None)))
.manage(QuickPaneVisibility(Mutex::new(false)))
.manage(WorkspaceSubscription {
generation: Arc::new(bridge::SubscriptionGeneration::default()),
task: Mutex::new(None),
@@ -452,9 +470,19 @@ pub fn run() {
if should_hide_close_request(window.label()) {
if let WindowEvent::CloseRequested { api, .. } = event {
api.prevent_close();
if let Some(state) = window.app_handle().try_state::<QuickPaneVisibility>() {
let mut current = state
.0
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
if window.hide().is_ok() {
*current = false;
}
} else {
let _ = window.hide();
}
}
}
})
.setup(move |app| {
if requested_quick_pane(&launch_args) {