From 946b0e554c7303371bc0934b2212fd948ff4d74d Mon Sep 17 00:00:00 2001 From: Bryan Lee <38807139+liby@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:22:06 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 避免使用 `clone` 2. 在获取配置失败时给予默认值 --- src-tauri/src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 55f0455..af3ce31 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,4 +1,3 @@ -use std::fs::File; use tauri_utils::config::{Config, WindowConfig}; fn main() -> wry::Result<()> { @@ -45,7 +44,7 @@ fn main() -> wry::Result<()> { transparent, fullscreen, .. - } = get_windows_config(); + } = get_windows_config().unwrap_or(WindowConfig::default()); let event_loop = EventLoop::new(); let window = WindowBuilder::new() .with_resizable(resizable) @@ -107,9 +106,9 @@ fn main() -> wry::Result<()> { }); } -fn get_windows_config() -> WindowConfig { +fn get_windows_config() -> Option { let config_file = include_str!("../tauri.conf.json"); let config: Config = serde_json::from_str(config_file).expect("failed to parse windows config"); - config.tauri.windows[0].clone() + config.tauri.windows.iter().next().cloned() }