add db migrations and restore config on unlock

This commit is contained in:
jfmonty2 committed 2026-11-18 05:49:45 -05:00
1 parent a10510ed6e
commit 0798124811
12 files changed
+365 -41

No files matched your search

+12 -3
View File
@@ -1,5 +1,5 @@
use gpui_kit::{
AppContext, Context, Entity, FontWeight, IntoElement, ParentElement, Render, SharedString,
AppContext, BorrowAppContext, Context, Entity, FontWeight, IntoElement, ParentElement, Render, SharedString,
Styled, Subscription, Task, Window, div, rems,
};
use gpui_omarchy::{ButtonVariant, Status, alert, button, focus_scope};
@@ -58,13 +58,22 @@ impl UnlockScreen {
self.pending = Some(cx.spawn(async move |this, cx| {
// argon2 is deliberately slow, so keep it off the UI thread
let result = cx
.background_spawn(async move { Db::connect(&config, passphrase.as_str()) })
.background_spawn(async move {
let db = Db::connect(&config, passphrase.as_str())?;
// Some of AppConfig comes from the db, but we couldn't see it until now
let private_config = db.load_private_config()?;
Ok((db, private_config))
})
.await;
// db connection has been established or not, so now we handle the result
let _ = this.update(cx, |this, cx| {
this.pending = None;
match result {
Ok(db) => cx.set_global(AppSession::Unlocked(db)),
Ok((db, private_config)) => {
cx.update_global::<AppConfig, _>(|config, _cx| config.merge_private(private_config));
cx.set_global(AppSession::Unlocked(db));
},
Err(e) => this.error = Some(error_message(&e)),
}
cx.notify();