fix windows threadding ccm window bug
This commit is contained in:
@@ -364,7 +364,7 @@ fn save_client_config(config: AppConfig) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn open_client_config_manager() -> Result<(), String> {
|
async fn open_client_config_manager() -> Result<(), String> {
|
||||||
open_config_manager_window().map_err(|e| e.to_string())
|
open_config_manager_window().map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::{fs, path::PathBuf};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, warn};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::get_app_handle;
|
use crate::get_app_handle;
|
||||||
@@ -28,6 +28,8 @@ pub enum ClientConfigError {
|
|||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
#[error("failed to parse client config: {0}")]
|
#[error("failed to parse client config: {0}")]
|
||||||
Parse(#[from] serde_json::Error),
|
Parse(#[from] serde_json::Error),
|
||||||
|
#[error("failed to run on main thread: {0}")]
|
||||||
|
Dispatch(#[from] tauri::Error),
|
||||||
#[error("failed to build client config manager window: {0}")]
|
#[error("failed to build client config manager window: {0}")]
|
||||||
Window(tauri::Error),
|
Window(tauri::Error),
|
||||||
#[error("failed to show client config manager window: {0}")]
|
#[error("failed to show client config manager window: {0}")]
|
||||||
@@ -78,8 +80,8 @@ fn sanitize(mut config: AppConfig) -> AppConfig {
|
|||||||
.map(|v| strip_trailing_slash(&v));
|
.map(|v| strip_trailing_slash(&v));
|
||||||
|
|
||||||
let auth_url_trimmed = config.auth.auth_url.trim();
|
let auth_url_trimmed = config.auth.auth_url.trim();
|
||||||
config.auth.auth_url = parse_http_url(auth_url_trimmed)
|
config.auth.auth_url =
|
||||||
.unwrap_or_else(|| DEFAULT_AUTH_URL.to_string());
|
parse_http_url(auth_url_trimmed).unwrap_or_else(|| DEFAULT_AUTH_URL.to_string());
|
||||||
|
|
||||||
if config.auth.audience.trim().is_empty() {
|
if config.auth.audience.trim().is_empty() {
|
||||||
config.auth.audience = DEFAULT_JWT_AUDIENCE.to_string();
|
config.auth.audience = DEFAULT_JWT_AUDIENCE.to_string();
|
||||||
@@ -149,6 +151,24 @@ pub fn save_app_config(config: AppConfig) -> Result<AppConfig, ClientConfigError
|
|||||||
|
|
||||||
pub fn open_config_manager_window() -> Result<(), ClientConfigError> {
|
pub fn open_config_manager_window() -> Result<(), ClientConfigError> {
|
||||||
let app_handle = get_app_handle();
|
let app_handle = get_app_handle();
|
||||||
|
|
||||||
|
// Directly run on main thread via dispatch but handle errors properly
|
||||||
|
// This is essentially what we did but let's simplify and make sure we don't block
|
||||||
|
let handle_for_closure = app_handle.clone();
|
||||||
|
|
||||||
|
// We want to return immediately, the window creation happens asynchronously on main thread
|
||||||
|
let _ = app_handle.run_on_main_thread(move || {
|
||||||
|
if let Err(e) = open_config_manager_window_inner(&handle_for_closure) {
|
||||||
|
error!("Failed to open client config manager window: {e}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_config_manager_window_inner(
|
||||||
|
app_handle: &tauri::AppHandle,
|
||||||
|
) -> Result<(), ClientConfigError> {
|
||||||
let existing_webview_window = app_handle.get_window(CLIENT_CONFIG_MANAGER_WINDOW_LABEL);
|
let existing_webview_window = app_handle.get_window(CLIENT_CONFIG_MANAGER_WINDOW_LABEL);
|
||||||
|
|
||||||
if let Some(window) = existing_webview_window {
|
if let Some(window) = existing_webview_window {
|
||||||
@@ -156,10 +176,12 @@ pub fn open_config_manager_window() -> Result<(), ClientConfigError> {
|
|||||||
error!("Failed to show client config manager window: {e}");
|
error!("Failed to show client config manager window: {e}");
|
||||||
return Err(ClientConfigError::ShowWindow(e));
|
return Err(ClientConfigError::ShowWindow(e));
|
||||||
}
|
}
|
||||||
|
if let Err(e) = window.set_focus() {
|
||||||
|
error!("Failed to focus client config manager window: {e}");
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Starting client config manager...");
|
|
||||||
match tauri::WebviewWindowBuilder::new(
|
match tauri::WebviewWindowBuilder::new(
|
||||||
app_handle,
|
app_handle,
|
||||||
CLIENT_CONFIG_MANAGER_WINDOW_LABEL,
|
CLIENT_CONFIG_MANAGER_WINDOW_LABEL,
|
||||||
@@ -167,11 +189,17 @@ pub fn open_config_manager_window() -> Result<(), ClientConfigError> {
|
|||||||
)
|
)
|
||||||
.title("Friendolls Client Config Manager")
|
.title("Friendolls Client Config Manager")
|
||||||
.inner_size(600.0, 500.0)
|
.inner_size(600.0, 500.0)
|
||||||
|
.visible(false)
|
||||||
.build()
|
.build()
|
||||||
{
|
{
|
||||||
Ok(_) => {
|
Ok(window) => {
|
||||||
info!("Client config manager window builder succeeded");
|
if let Err(e) = window.show() {
|
||||||
info!("Client config manager window initialized successfully.");
|
error!("Failed to show client config manager window: {}", e);
|
||||||
|
return Err(ClientConfigError::ShowWindow(e));
|
||||||
|
}
|
||||||
|
if let Err(e) = window.set_focus() {
|
||||||
|
error!("Failed to focus client config manager window: {e}");
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -10,9 +10,14 @@ pub static HEALTH_MANAGER_EVENT: &str = "health-error";
|
|||||||
fn close_window_if_exists(label: &str) {
|
fn close_window_if_exists(label: &str) {
|
||||||
let app_handle = get_app_handle();
|
let app_handle = get_app_handle();
|
||||||
if let Some(window) = app_handle.get_window(label) {
|
if let Some(window) = app_handle.get_window(label) {
|
||||||
|
info!("Closing window with label: {}", label);
|
||||||
if let Err(e) = window.close() {
|
if let Err(e) = window.close() {
|
||||||
error!("Failed to close {} window: {}", label, e);
|
error!("Failed to close {} window: {}", label, e);
|
||||||
|
} else {
|
||||||
|
info!("Closed window with label: {}", label);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
info!("No window found with label: {}", label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +51,7 @@ pub fn show_health_manager_with_error(error_message: Option<String>) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info!("Building health manager window");
|
||||||
let webview_window = match tauri::WebviewWindowBuilder::new(
|
let webview_window = match tauri::WebviewWindowBuilder::new(
|
||||||
app_handle,
|
app_handle,
|
||||||
HEALTH_MANAGER_WINDOW_LABEL,
|
HEALTH_MANAGER_WINDOW_LABEL,
|
||||||
@@ -95,6 +101,8 @@ pub fn show_health_manager_with_error(error_message: Option<String>) {
|
|||||||
)
|
)
|
||||||
.kind(MessageDialogKind::Error)
|
.kind(MessageDialogKind::Error)
|
||||||
.show(|_| {});
|
.show(|_| {});
|
||||||
|
} else {
|
||||||
|
info!("Health manager window shown successfully");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,16 @@
|
|||||||
Try again
|
Try again
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-outline" onclick={async () => invoke("open_client_config_manager")}>
|
<button
|
||||||
|
class="btn btn-outline"
|
||||||
|
onclick={async () => {
|
||||||
|
try {
|
||||||
|
await invoke("open_client_config_manager");
|
||||||
|
} catch (err) {
|
||||||
|
errorMessage = `Failed to open config manager: ${err}`;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
Advanced options
|
Advanced options
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user