fix windows threadding ccm window bug

This commit is contained in:
2026-01-04 17:56:36 +08:00
parent afdff29637
commit 96ba44613d
4 changed files with 54 additions and 9 deletions

View File

@@ -364,7 +364,7 @@ fn save_client_config(config: AppConfig) -> Result<(), String> {
}
#[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())
}

View File

@@ -3,7 +3,7 @@ use std::{fs, path::PathBuf};
use serde::{Deserialize, Serialize};
use tauri::Manager;
use thiserror::Error;
use tracing::{error, info, warn};
use tracing::{error, warn};
use url::Url;
use crate::get_app_handle;
@@ -28,6 +28,8 @@ pub enum ClientConfigError {
Io(#[from] std::io::Error),
#[error("failed to parse client config: {0}")]
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}")]
Window(tauri::Error),
#[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));
let auth_url_trimmed = config.auth.auth_url.trim();
config.auth.auth_url = parse_http_url(auth_url_trimmed)
.unwrap_or_else(|| DEFAULT_AUTH_URL.to_string());
config.auth.auth_url =
parse_http_url(auth_url_trimmed).unwrap_or_else(|| DEFAULT_AUTH_URL.to_string());
if config.auth.audience.trim().is_empty() {
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> {
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);
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}");
return Err(ClientConfigError::ShowWindow(e));
}
if let Err(e) = window.set_focus() {
error!("Failed to focus client config manager window: {e}");
}
return Ok(());
}
info!("Starting client config manager...");
match tauri::WebviewWindowBuilder::new(
app_handle,
CLIENT_CONFIG_MANAGER_WINDOW_LABEL,
@@ -167,11 +189,17 @@ pub fn open_config_manager_window() -> Result<(), ClientConfigError> {
)
.title("Friendolls Client Config Manager")
.inner_size(600.0, 500.0)
.visible(false)
.build()
{
Ok(_) => {
info!("Client config manager window builder succeeded");
info!("Client config manager window initialized successfully.");
Ok(window) => {
if let Err(e) = window.show() {
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(())
}
Err(e) => {

View File

@@ -10,9 +10,14 @@ pub static HEALTH_MANAGER_EVENT: &str = "health-error";
fn close_window_if_exists(label: &str) {
let app_handle = get_app_handle();
if let Some(window) = app_handle.get_window(label) {
info!("Closing window with label: {}", label);
if let Err(e) = window.close() {
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;
}
info!("Building health manager window");
let webview_window = match tauri::WebviewWindowBuilder::new(
app_handle,
HEALTH_MANAGER_WINDOW_LABEL,
@@ -95,6 +101,8 @@ pub fn show_health_manager_with_error(error_message: Option<String>) {
)
.kind(MessageDialogKind::Error)
.show(|_| {});
} else {
info!("Health manager window shown successfully");
}
}

View File

@@ -56,7 +56,16 @@
Try again
{/if}
</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
</button>
</div>