修复iOS构建失败并调整初始窗口尺寸以避免底部黑边

This commit is contained in:
JSR
2026-03-19 19:08:33 +08:00
parent 24e7303040
commit c4c65861c9
3 changed files with 42 additions and 30 deletions
+34 -28
View File
@@ -1,6 +1,7 @@
use parking_lot::RwLock; use parking_lot::RwLock;
use std::sync::Arc; use std::sync::Arc;
use tauri::AppHandle; use tauri::AppHandle;
#[cfg(desktop)]
use tauri::Manager; use tauri::Manager;
use crate::state::AppState; use crate::state::AppState;
@@ -27,32 +28,28 @@ pub async fn window_maximize(
app: AppHandle, app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>, _state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<bool, String> { ) -> Result<bool, String> {
#[cfg(not(desktop))]
{
let _ = app;
return Ok(false);
}
#[cfg(desktop)] #[cfg(desktop)]
{ {
if let Some(window) = app.get_webview_window("main") { if let Some(window) = app.get_webview_window("main") {
let is_maximized = window.is_maximized().map_err(|e| e.to_string())?; let is_maximized = window.is_maximized().map_err(|e| e.to_string())?;
if is_maximized { if is_maximized {
window.unmaximize().map_err(|e| e.to_string())?; window.unmaximize().map_err(|e| e.to_string())?;
Ok(false) Ok(false)
} else { } else {
window.maximize().map_err(|e| e.to_string())?; window.maximize().map_err(|e| e.to_string())?;
Ok(true) Ok(true)
} }
} else { } else {
Err("Window not found".to_string()) Err("Window not found".to_string())
} }
} }
#[cfg(not(desktop))]
{
if let Some(window) = app.get_webview_window("main") {
window.set_fullscreen(true).map_err(|e| e.to_string())?;
Ok(true)
} else {
Ok(false)
}
}
} }
#[tauri::command] #[tauri::command]
@@ -77,19 +74,16 @@ pub async fn window_is_maximized(
app: AppHandle, app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>, _state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<bool, String> { ) -> Result<bool, String> {
#[cfg(not(desktop))]
{
let _ = app;
return Ok(false);
}
#[cfg(desktop)] #[cfg(desktop)]
{ {
if let Some(window) = app.get_webview_window("main") { if let Some(window) = app.get_webview_window("main") {
window.is_maximized().map_err(|e| e.to_string()) window.is_maximized().map_err(|e| e.to_string())
} else {
Ok(false)
}
}
#[cfg(not(desktop))]
{
if let Some(window) = app.get_webview_window("main") {
window.is_fullscreen().map_err(|e| e.to_string())
} else { } else {
Ok(false) Ok(false)
} }
@@ -124,6 +118,12 @@ pub async fn window_resize(
app: AppHandle, app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>, _state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<(), String> { ) -> Result<(), String> {
#[cfg(not(desktop))]
{
let _ = (width, height, app);
}
#[cfg(desktop)]
if let Some(window) = app.get_webview_window("main") { if let Some(window) = app.get_webview_window("main") {
window window
.set_size(tauri::Size::Physical(tauri::PhysicalSize { width, height })) .set_size(tauri::Size::Physical(tauri::PhysicalSize { width, height }))
@@ -138,6 +138,12 @@ pub async fn window_set_resizable(
app: AppHandle, app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>, _state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<(), String> { ) -> Result<(), String> {
#[cfg(not(desktop))]
{
let _ = (resizable, app);
}
#[cfg(desktop)]
if let Some(window) = app.get_webview_window("main") { if let Some(window) = app.get_webview_window("main") {
window.set_resizable(resizable).map_err(|e| e.to_string())?; window.set_resizable(resizable).map_err(|e| e.to_string())?;
} }
+6
View File
@@ -298,6 +298,12 @@ fn setup_tray(_app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
#[cfg(desktop)] #[cfg(desktop)]
fn setup_window_events(app: &mut App) -> Result<(), Box<dyn std::error::Error>> { fn setup_window_events(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
if let Some(window) = app.get_webview_window("main") { if let Some(window) = app.get_webview_window("main") {
let _ = window.set_size(tauri::Size::Physical(tauri::PhysicalSize {
width: 1180,
height: 680,
}));
let _ = window.center();
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
let _ = window.set_shadow(true); let _ = window.set_shadow(true);
+2 -2
View File
@@ -15,8 +15,8 @@
"windows": [ "windows": [
{ {
"title": "SecScore", "title": "SecScore",
"width": 1180, "width": 10000,
"height": 680, "height": 10000,
"resizable": true, "resizable": true,
"fullscreen": false, "fullscreen": false,
"decorations": false, "decorations": false,