Skip to content

Commit bc81ba7

Browse files
committed
fix: close DB before logout deletion
A potential fix for Windows Logouts.
1 parent 908b4ef commit bc81ba7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,11 +3114,17 @@ async fn logout<R: Runtime>(handle: AppHandle<R>) {
31143114
// Lock the state to ensure nothing is added to the DB before restart
31153115
let _guard = STATE.lock().await;
31163116

3117-
// Delete the current account's profile directory (SQL database)
3117+
// Close the database connection pool BEFORE attempting to delete files
3118+
// This is critical on Windows where open file handles prevent deletion
3119+
account_manager::close_db_connection();
3120+
3121+
// Delete the current account's profile directory (SQL database and MLS data)
31183122
if let Ok(npub) = account_manager::get_current_account() {
31193123
if let Ok(profile_dir) = account_manager::get_profile_directory(&handle, &npub) {
31203124
if profile_dir.exists() {
3121-
let _ = std::fs::remove_dir_all(&profile_dir);
3125+
if let Err(e) = std::fs::remove_dir_all(&profile_dir) {
3126+
eprintln!("[Logout] Failed to remove profile directory: {}", e);
3127+
}
31223128
}
31233129
}
31243130
}
@@ -3136,7 +3142,7 @@ async fn logout<R: Runtime>(handle: AppHandle<R>) {
31363142
}
31373143
}
31383144

3139-
// Delete the MLS folder in AppData
3145+
// Delete the legacy MLS folder in AppData (for backwards compatibility)
31403146
if let Ok(mls_dir) = handle.path().resolve("mls", tauri::path::BaseDirectory::AppData) {
31413147
if mls_dir.exists() {
31423148
let _ = std::fs::remove_dir_all(&mls_dir);

0 commit comments

Comments
 (0)