From 57b67690b5cd6649dfaa848ae125574e421fe9c0 Mon Sep 17 00:00:00 2001 From: JonShort Date: Wed, 20 Nov 2024 21:49:02 +0000 Subject: [PATCH] [feat] - create too --- src-tauri/src/sql.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/sql.rs b/src-tauri/src/sql.rs index 0f07b68..7307adc 100644 --- a/src-tauri/src/sql.rs +++ b/src-tauri/src/sql.rs @@ -15,13 +15,16 @@ pub struct DB { impl DB { pub async fn new(app: &App) -> Result { - let app_data_dir = match app.path().app_data_dir() { - Ok(d) => d, - _ => return Err(DbError), - }; + let data_dir = app.path().data_dir()?; + let app_data_dir = app.path().app_data_dir()?; - // Tauri doesn't create the $APPDATA directory automatically, - // so here we create it if it doesn't already exist + // In some cases (e.g. iOS) the $APPDATA directory doesn't exist + if !data_dir.exists() && fs::create_dir(&data_dir).is_err() { + return Err(DbError); + } + + // Tauri doesn't create the $APPDATA/[app] directory for applications + // automatically, so here we create it if it doesn't already exist if !app_data_dir.exists() && fs::create_dir(&app_data_dir).is_err() { return Err(DbError); } @@ -253,6 +256,12 @@ impl fmt::Display for DbError { impl error::Error for DbError {} +impl From for DbError { + fn from(_: tauri::Error) -> Self { + DbError + } +} + impl From for DbError { fn from(_: sqlx::Error) -> Self { DbError