1pub mod app;
14pub mod keyboard_help;
15pub mod openapi;
16pub mod openapi_sync;
17pub mod path_picker;
18pub mod screens;
19pub mod text_search;
20pub mod utils;
21
22use anyhow::Result;
23
24use crate::client::RommClient;
25use crate::config::{openapi_cache_path, Config};
26
27use self::app::App;
28use self::openapi_sync::sync_openapi_registry;
29use self::screens::connected_splash::StartupSplash;
30use self::screens::setup_wizard::SetupWizard;
31
32fn install_panic_hook() {
33 let original_hook = std::panic::take_hook();
34 std::panic::set_hook(Box::new(move |panic| {
35 let _ = crossterm::terminal::disable_raw_mode();
36 let _ = crossterm::execute!(
37 std::io::stdout(),
38 crossterm::terminal::LeaveAlternateScreen,
39 crossterm::event::DisableMouseCapture
40 );
41 original_hook(panic);
42 }));
43}
44
45fn startup_splash_for(
46 from_setup_wizard: bool,
47 config: &Config,
48 server_version: &Option<String>,
49) -> Option<StartupSplash> {
50 if from_setup_wizard {
51 return Some(StartupSplash::new(
52 config.base_url.clone(),
53 server_version.clone(),
54 ));
55 }
56 if server_version.is_some() {
57 return Some(StartupSplash::new(
58 config.base_url.clone(),
59 server_version.clone(),
60 ));
61 }
62 None
63}
64
65async fn run_started(client: RommClient, config: Config, from_setup_wizard: bool) -> Result<()> {
66 install_panic_hook();
67 let cache_path = openapi_cache_path()?;
68 let (registry, server_version) = sync_openapi_registry(&client, &cache_path).await?;
69
70 let splash = startup_splash_for(from_setup_wizard, &config, &server_version);
71 let mut app = App::new(client, config, registry, server_version, splash);
72 app.run().await
73}
74
75pub async fn run(client: RommClient, config: Config) -> Result<()> {
77 run_started(client, config, false).await
78}
79
80pub async fn run_interactive(verbose: bool) -> Result<()> {
82 let (from_wizard, config) = match crate::config::load_config() {
83 Ok(c) => (false, c),
84 Err(_) => (true, SetupWizard::new().run(verbose).await?),
85 };
86 let client = RommClient::new(&config, verbose)?;
87 run_started(client, config, from_wizard).await
88}