run gtk calls on main thread
This commit is contained in:
@@ -121,7 +121,7 @@ pub fn show_toolbar_window(app_handle: &AppHandle) -> Result<(), tauri::Error> {
|
||||
window.unminimize()?;
|
||||
window.set_focus()?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&window);
|
||||
focus_window_linux(app_handle, &window);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -138,7 +138,7 @@ fn open_toolbar(app_handle: &AppHandle) -> Result<(), tauri::Error> {
|
||||
window.unminimize()?;
|
||||
window.set_focus()?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&window);
|
||||
focus_window_linux(app_handle, &window);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+47
-26
@@ -49,11 +49,14 @@ fn centered_logical_position(
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) fn focus_window_linux(window: &WebviewWindow) {
|
||||
use gtk::prelude::*;
|
||||
if let Ok(gtk_win) = window.gtk_window() {
|
||||
gtk_win.present_with_time(gtk::current_event_time());
|
||||
}
|
||||
pub(crate) fn focus_window_linux(app_handle: &AppHandle, window: &WebviewWindow) {
|
||||
let window_clone = window.clone();
|
||||
let _ = app_handle.run_on_main_thread(move || {
|
||||
use gtk::prelude::*;
|
||||
if let Ok(gtk_win) = window_clone.gtk_window() {
|
||||
gtk_win.present_with_time(gtk::current_event_time());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -67,10 +70,10 @@ pub async fn open_full_window(
|
||||
if let Some(existing) = app_handle.get_webview_window(&name) {
|
||||
existing.set_focus().map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&existing);
|
||||
focus_window_linux(&app_handle, &existing);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
let os = std::env::consts::OS;
|
||||
|
||||
let primary_monitor = app_handle
|
||||
@@ -119,16 +122,23 @@ pub async fn open_full_window(
|
||||
window.show().map_err(|e| e.to_string())?;
|
||||
window.set_focus().map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&window);
|
||||
focus_window_linux(&app_handle, &window);
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
if let Some((x, y)) = centered_logical_position(&app_handle, width, height) {
|
||||
let _ = window.set_position(tauri::Position::Logical(tauri::LogicalPosition::new(x, y)));
|
||||
}
|
||||
|
||||
if os != "windows" && os != "macos" {
|
||||
window.set_resizable(false).map_err(|e| e.to_string())?;
|
||||
window.set_resizable(true).map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let window_clone = window.clone();
|
||||
app_handle.run_on_main_thread(move || {
|
||||
use gtk::prelude::*;
|
||||
if let Ok(gtk_win) = window_clone.gtk_window() {
|
||||
gtk_win.set_resizable(false);
|
||||
gtk_win.set_resizable(true);
|
||||
}
|
||||
}).map_err(|e| e.to_string())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -146,7 +156,7 @@ pub async fn open_window(
|
||||
if let Some(existing) = app_handle.get_webview_window(&name) {
|
||||
existing.set_focus().map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&existing);
|
||||
focus_window_linux(&app_handle, &existing);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -220,7 +230,7 @@ pub async fn open_window(
|
||||
if let Some(existing) = app_handle.get_webview_window(&name) {
|
||||
existing.set_focus().map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&existing);
|
||||
focus_window_linux(&app_handle, &existing);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -244,17 +254,21 @@ pub async fn open_window(
|
||||
|
||||
let window = builder.build().map_err(|e| e.to_string())?;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(750));
|
||||
|
||||
window.set_zoom(1.0).map_err(|e| e.to_string())?;
|
||||
window.show().map_err(|e| e.to_string())?;
|
||||
window.set_focus().map_err(|e| e.to_string())?;
|
||||
focus_window_linux(&window);
|
||||
|
||||
if let Some((x, y)) = centered_logical_position(&app_handle, width, height) {
|
||||
let _ = window.set_position(tauri::Position::Logical(tauri::LogicalPosition::new(x, y)));
|
||||
}
|
||||
|
||||
window.set_resizable(false).map_err(|e| e.to_string())?;
|
||||
window.set_resizable(true).map_err(|e| e.to_string())?;
|
||||
let window_clone = window.clone();
|
||||
app_handle.run_on_main_thread(move || {
|
||||
use gtk::prelude::*;
|
||||
if let Ok(gtk_win) = window_clone.gtk_window() {
|
||||
gtk_win.present_with_time(gtk::current_event_time());
|
||||
gtk_win.set_resizable(false);
|
||||
gtk_win.set_resizable(true);
|
||||
}
|
||||
}).map_err(|e| e.to_string())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -268,10 +282,10 @@ pub async fn open_small_window(
|
||||
if let Some(existing) = app_handle.get_webview_window(&name) {
|
||||
existing.set_focus().map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&existing);
|
||||
focus_window_linux(&app_handle, &existing);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
let os = std::env::consts::OS;
|
||||
|
||||
let mut builder = WebviewWindowBuilder::new(&app_handle, &name, WebviewUrl::App(url.into()))
|
||||
@@ -312,7 +326,7 @@ pub async fn open_small_window(
|
||||
window.show().map_err(|e| e.to_string())?;
|
||||
window.set_focus().map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
focus_window_linux(&window);
|
||||
focus_window_linux(&app_handle, &window);
|
||||
window.set_always_on_top(true).map_err(|e| e.to_string())?;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -320,9 +334,16 @@ pub async fn open_small_window(
|
||||
let _ = window.set_position(tauri::Position::Logical(tauri::LogicalPosition::new(x, y)));
|
||||
}
|
||||
|
||||
if os != "windows" && os != "macos" {
|
||||
window.set_resizable(true).map_err(|e| e.to_string())?;
|
||||
window.set_resizable(false).map_err(|e| e.to_string())?;
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let window_clone = window.clone();
|
||||
app_handle.run_on_main_thread(move || {
|
||||
use gtk::prelude::*;
|
||||
if let Ok(gtk_win) = window_clone.gtk_window() {
|
||||
gtk_win.set_resizable(true);
|
||||
gtk_win.set_resizable(false);
|
||||
}
|
||||
}).map_err(|e| e.to_string())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user