-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tauri): app setup and unrecoverable error logic (#1262)
* move state init pieces into tauri setup function * refactor unrecoverable startup errors logic
- Loading branch information
Showing
14 changed files
with
210 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
use anyhow::{Context, Result}; | ||
use std::path::PathBuf; | ||
use tokio::fs::{self, File}; | ||
use std::fs; | ||
use std::fs::File; | ||
use std::path::{Path, PathBuf}; | ||
use tracing::{debug, error}; | ||
|
||
/// Check if a directory exists, if not create it including all | ||
/// parent components | ||
pub fn check_dir(path: &PathBuf) -> Result<()> { | ||
if !path.is_dir() { | ||
debug!("directory `{}` does not exist, creating it", path.display()); | ||
return std::fs::create_dir_all(path) | ||
return fs::create_dir_all(path) | ||
.inspect_err(|e| error!("Failed to create directory `{}`: {e}", path.display())) | ||
.context(format!("Failed to create directory `{}`", path.display())); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Check if a file exists, if not create it | ||
pub async fn check_file(path: &PathBuf) -> Result<()> { | ||
if !fs::try_exists(&path) | ||
.await | ||
pub fn check_file(path: &PathBuf) -> Result<()> { | ||
if !Path::try_exists(path) | ||
.inspect_err(|e| error!("Failed to check if path exists `{}`: {e}", path.display())) | ||
.context(format!( | ||
"Failed to check if path exists `{}`", | ||
path.display() | ||
))? | ||
{ | ||
debug!("file `{}` does not exist, creating it", path.display()); | ||
File::create(&path) | ||
.await | ||
File::create(path) | ||
.inspect_err(|e| error!("Failed to create file `{}`: {e}", path.display())) | ||
.context(format!("Failed to create file `{}`", path.display()))?; | ||
return Ok(()); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.