diff --git a/fpx-app/src/commands/workspace.rs b/fpx-app/src/commands/workspace.rs index 94b2f8e3d..e3d3a0ecc 100644 --- a/fpx-app/src/commands/workspace.rs +++ b/fpx-app/src/commands/workspace.rs @@ -1,4 +1,4 @@ -use crate::models::workspace::{OpenWorkspaceByPathError, Workspace}; +use crate::models::workspace::{OpenWorkspaceError, Workspace}; use crate::state::AppState; use crate::STORE_PATH; use fpx::config::{FpxConfig, FpxConfigError}; @@ -40,19 +40,17 @@ pub fn open_workspace_by_path( state: State<'_, AppState>, app: AppHandle, stores: State<'_, StoreCollection>, -) -> Result { +) -> Result { let path_buf = PathBuf::from(path.clone()); let config = match FpxConfig::load(Some(path_buf)) { Ok((config, _config_path)) => config, Err(err) => { return Err(match err { - FpxConfigError::FileNotFound(path_buf) => { - OpenWorkspaceByPathError::ConfigFileMissing { - path: path_buf.to_string_lossy().to_string(), - } - } + FpxConfigError::FileNotFound(path_buf) => OpenWorkspaceError::ConfigFileMissing { + path: path_buf.to_string_lossy().to_string(), + }, FpxConfigError::InvalidFpxConfig { message, .. } => { - OpenWorkspaceByPathError::InvalidConfiguration { message } + OpenWorkspaceError::InvalidConfiguration { message } } FpxConfigError::RootDirectoryNotFound => { unreachable!("FpxConfig::load takes a path, so this cannot occur") diff --git a/fpx-app/src/models/workspace.rs b/fpx-app/src/models/workspace.rs index 2a8432e17..f46b30ab6 100644 --- a/fpx-app/src/models/workspace.rs +++ b/fpx-app/src/models/workspace.rs @@ -16,7 +16,7 @@ impl Workspace { #[derive(JsonSchema, Deserialize, Serialize)] #[serde(tag = "type")] -pub enum OpenWorkspaceByPathError { +pub enum OpenWorkspaceError { ConfigFileMissing { path: String }, InvalidConfiguration { message: String }, } diff --git a/fpx-app/src/state.rs b/fpx-app/src/state.rs index e78bd4da7..5227aa8c7 100644 --- a/fpx-app/src/state.rs +++ b/fpx-app/src/state.rs @@ -10,16 +10,16 @@ pub struct AppState { impl AppState { pub fn set_workspace(&self, workspace: Workspace) { let mut workspace_lock = self.workspace.lock().unwrap(); - *workspace_lock = Some(workspace); + workspace_lock.replace(workspace); } pub fn close_workspace(&self) { let mut workspace_lock = self.workspace.lock().unwrap(); - *workspace_lock = None; + workspace_lock.take(); } pub fn get_workspace(&self) -> Option { let workspace_lock = self.workspace.lock().unwrap(); - workspace_lock.as_ref().map(|workspace| workspace.clone()) + workspace_lock.as_ref().cloned() } } diff --git a/xtask/src/commands/schemas.rs b/xtask/src/commands/schemas.rs index d4a566c3f..347dd6988 100644 --- a/xtask/src/commands/schemas.rs +++ b/xtask/src/commands/schemas.rs @@ -21,7 +21,7 @@ pub async fn handle_command(args: Args) -> Result<()> { schema_for!(ClientMessage), schema_for!(ServerMessage), schema_for!(fpx_app::state::AppState), - schema_for!(fpx_app::models::workspace::OpenWorkspaceByPathError), + schema_for!(fpx_app::models::workspace::OpenWorkspaceError), schema_for!(fpx_app::models::workspace::Workspace), schema_for!(fpx::config::FpxConfig), schema_for!(fpx::config::FpxConfigError),