use std::path::{Path, PathBuf};
use super::{
executable::{self, HarnessLocation, HARNESS_PATH_ENV},
home::{AntigravityAuthStatus, AntigravityHome},
ANTIGRAVITY_LABEL_NAME,
};
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum ServerInstall {
Missing,
Found {
path: PathBuf,
harness: HarnessLocation,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct AntigravitySetup {
pub(crate) server: ServerInstall,
pub(crate) auth: AntigravityAuthStatus,
}
impl AntigravitySetup {
pub(crate) fn from_env(home: &Path) -> Self {
let server = match executable::resolve() {
Ok(found) => ServerInstall::Found {
harness: executable::harness_location(
found.path(),
executable::harness_override_from_env(),
),
path: found.path().to_path_buf(),
},
Err(_) => ServerInstall::Missing,
};
Self {
server,
auth: AntigravityHome::from_env(home).status(),
}
}
pub(crate) fn is_ready(&self) -> bool {
let installed = match &self.server {
ServerInstall::Found {
harness: HarnessLocation::Override(_) | HarnessLocation::Beside(_),
..
} => true,
ServerInstall::Missing
| ServerInstall::Found {
harness: HarnessLocation::Missing { .. } | HarnessLocation::OverrideMissing(_),
..
} => false,
};
installed && self.auth.is_signed_in()
}
pub(crate) fn description(&self) -> String {
let state = match &self.server {
ServerInstall::Missing => "not installed - run /login antigravity".into(),
ServerInstall::Found {
harness: HarnessLocation::Missing { expected },
..
} => format!("{} is missing", crate::paths::display(expected)),
ServerInstall::Found {
harness: HarnessLocation::OverrideMissing(path),
..
} => format!(
"{HARNESS_PATH_ENV} names {}, which is not a file",
crate::paths::display(path)
),
ServerInstall::Found {
harness: HarnessLocation::Override(_) | HarnessLocation::Beside(_),
..
} => match &self.auth {
AntigravityAuthStatus::Configured { method } => format!("signed in ({method})"),
AntigravityAuthStatus::SignedOut { .. }
| AntigravityAuthStatus::MissingToken { .. } => {
"not signed in - run /login antigravity".into()
}
AntigravityAuthStatus::Unreadable { settings, detail } => format!(
"could not read {}: {detail}",
crate::paths::display(settings)
),
},
};
format!("{ANTIGRAVITY_LABEL_NAME}: {state}")
}
}