Skip to content

Commit 9e330a7

Browse files
committed
fix: 修复跨平台编译错误(macOS 专用 API 条件编译)
1 parent 013cbdc commit 9e330a7

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,19 +4186,30 @@ pub fn run() {
41864186
}
41874187
} else {
41884188
// 重建主窗口
4189-
if let Ok(window) = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
4190-
.title("Lovcode")
4191-
.inner_size(800.0, 600.0)
4192-
.title_bar_style(tauri::TitleBarStyle::Overlay)
4193-
.hidden_title(true)
4194-
.traffic_light_position(tauri::Position::Logical(tauri::LogicalPosition::new(16.0, 28.0)))
4195-
.build()
4189+
#[cfg(target_os = "macos")]
41964190
{
4197-
let _ = window.show();
4198-
#[cfg(target_os = "macos")]
4199-
activate_and_focus_window(&window);
4200-
#[cfg(not(target_os = "macos"))]
4201-
let _ = window.set_focus();
4191+
if let Ok(window) = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
4192+
.title("Lovcode")
4193+
.inner_size(800.0, 600.0)
4194+
.title_bar_style(tauri::TitleBarStyle::Overlay)
4195+
.hidden_title(true)
4196+
.traffic_light_position(tauri::Position::Logical(tauri::LogicalPosition::new(16.0, 28.0)))
4197+
.build()
4198+
{
4199+
let _ = window.show();
4200+
activate_and_focus_window(&window);
4201+
}
4202+
}
4203+
#[cfg(not(target_os = "macos"))]
4204+
{
4205+
if let Ok(window) = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
4206+
.title("Lovcode")
4207+
.inner_size(800.0, 600.0)
4208+
.build()
4209+
{
4210+
let _ = window.show();
4211+
let _ = window.set_focus();
4212+
}
42024213
}
42034214
}
42044215
} else if id == "tray_toggle_float" {
@@ -4397,25 +4408,23 @@ pub fn run() {
43974408
])
43984409
.build(tauri::generate_context!())
43994410
.expect("error while building tauri application")
4400-
.run(|app, event| {
4401-
use tauri::{Manager, RunEvent, WebviewWindowBuilder, WebviewUrl};
4411+
.run(|_app, _event| {
4412+
#[cfg(target_os = "macos")]
4413+
{
4414+
use tauri::{Manager, RunEvent, WebviewWindowBuilder, WebviewUrl};
44024415

4403-
match event {
4404-
RunEvent::Reopen { has_visible_windows, .. } => {
4416+
if let RunEvent::Reopen { has_visible_windows, .. } = _event {
44054417
println!("[Lovcode] Dock clicked! has_visible_windows: {}", has_visible_windows);
44064418

44074419
// 无论是否有"可见窗口",都尝试打开主窗口
44084420
// 因为 float 窗口可能被计入 has_visible_windows
4409-
if let Some(window) = app.get_webview_window("main") {
4421+
if let Some(window) = _app.get_webview_window("main") {
44104422
println!("[Lovcode] Main window exists, showing...");
44114423
let _ = window.show();
4412-
#[cfg(target_os = "macos")]
44134424
activate_and_focus_window(&window);
4414-
#[cfg(not(target_os = "macos"))]
4415-
let _ = window.set_focus();
44164425
} else {
44174426
println!("[Lovcode] Main window gone, recreating...");
4418-
match WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
4427+
match WebviewWindowBuilder::new(_app, "main", WebviewUrl::default())
44194428
.title("Lovcode")
44204429
.inner_size(800.0, 600.0)
44214430
.title_bar_style(tauri::TitleBarStyle::Overlay)
@@ -4426,18 +4435,14 @@ pub fn run() {
44264435
Ok(window) => {
44274436
println!("[Lovcode] Window created successfully");
44284437
let _ = window.show();
4429-
#[cfg(target_os = "macos")]
44304438
activate_and_focus_window(&window);
4431-
#[cfg(not(target_os = "macos"))]
4432-
let _ = window.set_focus();
44334439
}
44344440
Err(e) => {
44354441
println!("[Lovcode] Failed to create window: {:?}", e);
44364442
}
44374443
}
44384444
}
44394445
}
4440-
_ => {}
44414446
}
44424447
});
44434448
}

0 commit comments

Comments
 (0)