feat: impl setup restoration

This commit is contained in:
2026-04-26 00:01:57 +01:00
parent a54cc84660
commit 8b28f3d67f
11 changed files with 397 additions and 130 deletions

View File

@@ -14,6 +14,13 @@ mod screen;
mod storage;
mod theme;
mod titlebar;
mod util;
enum Start {
FromScratch,
FromSetup(setup_wizard::StoredSetupState),
FromSaved,
}
fn main() {
// GPUI polls our async query futures, but reqwest relies on Tokio's
@@ -33,8 +40,6 @@ fn main() {
}
fn setup_application(cx: &mut gpui::App) {
let window_bounds = gpui::Bounds::centered(None, size(px(800.), px(600.0)), cx);
let query_store = query::Store::new(api::QueryContext {
http: reqwest::Client::new(),
auth: None,
@@ -50,23 +55,55 @@ fn setup_application(cx: &mut gpui::App) {
rng: rand::rng(),
};
let top_left = global.safe_area.origin;
cx.set_global(global);
cx.set_global(query_store);
cx.open_window(
gpui::WindowOptions {
window_bounds: Some(gpui::WindowBounds::Windowed(window_bounds)),
titlebar: Some(gpui::TitlebarOptions {
appears_transparent: true,
traffic_light_position: Some(top_left + point(px(12.), px(12.))),
..Default::default()
}),
is_resizable: false,
..Default::default()
},
|window, cx| cx.new(|cx| setup_wizard::new(window, cx)),
)
.unwrap();
// TODO: handle failure
_ = storage::ensure_data_dir();
let start = resume_application_state(cx);
match start {
Start::FromScratch => {
let screen = setup_wizard::new();
_ = setup_wizard::open_window(screen, cx);
}
Start::FromSetup(state) => {
let screen = setup_wizard::from_saved(state);
_ = setup_wizard::open_window(screen, cx);
}
_ => {}
};
}
fn resume_application_state(cx: &mut gpui::App) -> Start {
let state = storage::load_persisted_state();
let Some(state) = state else {
return Start::FromScratch;
};
let auth_tokens = cx
.background_executor()
.block(storage::load_auth_tokens(cx, state.selected_account));
let Some(auth_tokens) = auth_tokens else {
return Start::FromScratch;
};
_ = cx.update_global::<query::Store<api::QueryContext>, _>(|store, _| {
store.update_query_context(|cx| {
cx.auth = Some(auth_tokens);
});
});
let setup_status = setup_wizard::read_setup_status();
println!("[main] setup status: {:?}", setup_status);
match setup_status {
setup_wizard::SetupStatus::NotStarted => Start::FromScratch,
setup_wizard::SetupStatus::InProgress(state) => Start::FromSetup(state),
setup_wizard::SetupStatus::Completed => Start::FromSaved,
}
}