fix(quick-pane): serialize native visibility
This commit is contained in:
+37
-9
@@ -9,6 +9,7 @@ use tauri::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct LegacySubscription(Mutex<Option<JoinHandle<()>>>);
|
struct LegacySubscription(Mutex<Option<JoinHandle<()>>>);
|
||||||
|
struct QuickPaneVisibility(Mutex<bool>);
|
||||||
struct WorkspaceSubscription {
|
struct WorkspaceSubscription {
|
||||||
generation: Arc<bridge::SubscriptionGeneration>,
|
generation: Arc<bridge::SubscriptionGeneration>,
|
||||||
task: Mutex<Option<JoinHandle<()>>>,
|
task: Mutex<Option<JoinHandle<()>>>,
|
||||||
@@ -64,9 +65,9 @@ fn should_hide_close_request(label: &str) -> bool {
|
|||||||
label == "quick-pane"
|
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") {
|
if let Some(window) = app.get_webview_window("quick-pane") {
|
||||||
return Ok(window);
|
return Ok((window, false));
|
||||||
}
|
}
|
||||||
let config = app
|
let config = app
|
||||||
.config()
|
.config()
|
||||||
@@ -75,33 +76,49 @@ fn get_or_create_quick_pane(app: &AppHandle) -> Result<WebviewWindow, String> {
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|window| window.label == "quick-pane")
|
.find(|window| window.label == "quick-pane")
|
||||||
.ok_or_else(|| "Quick Pane window configuration is missing".to_owned())?;
|
.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())?
|
.map_err(|error| error.to_string())?
|
||||||
.build()
|
.build()
|
||||||
.map_err(|error| error.to_string())
|
.map_err(|error| error.to_string())?;
|
||||||
|
Ok((window, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_quick_pane(app: &AppHandle) {
|
fn toggle_quick_pane(app: &AppHandle) {
|
||||||
let window = match get_or_create_quick_pane(app) {
|
let (window, created) = match get_or_create_quick_pane(app) {
|
||||||
Ok(window) => window,
|
Ok(result) => result,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
eprintln!("Could not create Quick Pane window: {error}");
|
eprintln!("Could not create Quick Pane window: {error}");
|
||||||
return;
|
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 => {
|
WindowAction::Hide => {
|
||||||
let _ = window.hide();
|
if window.hide().is_ok() {
|
||||||
|
*current = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
WindowAction::ShowAndFocus => {
|
WindowAction::ShowAndFocus => {
|
||||||
if let Some(main) = app.get_webview_window("main") {
|
if let Some(main) = app.get_webview_window("main") {
|
||||||
let _ = main.hide();
|
let _ = main.hide();
|
||||||
}
|
}
|
||||||
let _ = window.show();
|
if window.show().is_ok() {
|
||||||
|
*current = true;
|
||||||
let _ = window.unminimize();
|
let _ = window.unminimize();
|
||||||
let _ = window.set_focus();
|
let _ = window.set_focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn requested_new_worktree_argument(args: &[String]) -> Option<String> {
|
fn requested_new_worktree_argument(args: &[String]) -> Option<String> {
|
||||||
@@ -426,6 +443,7 @@ pub fn run() {
|
|||||||
let builder = tauri::Builder::default()
|
let builder = tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.manage(LegacySubscription(Mutex::new(None)))
|
.manage(LegacySubscription(Mutex::new(None)))
|
||||||
|
.manage(QuickPaneVisibility(Mutex::new(false)))
|
||||||
.manage(WorkspaceSubscription {
|
.manage(WorkspaceSubscription {
|
||||||
generation: Arc::new(bridge::SubscriptionGeneration::default()),
|
generation: Arc::new(bridge::SubscriptionGeneration::default()),
|
||||||
task: Mutex::new(None),
|
task: Mutex::new(None),
|
||||||
@@ -452,9 +470,19 @@ pub fn run() {
|
|||||||
if should_hide_close_request(window.label()) {
|
if should_hide_close_request(window.label()) {
|
||||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||||
api.prevent_close();
|
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();
|
let _ = window.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.setup(move |app| {
|
.setup(move |app| {
|
||||||
if requested_quick_pane(&launch_args) {
|
if requested_quick_pane(&launch_args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user