use omaha_client::{app_set::AppSet, common::App};
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum AppIdSource {
VbMetadata,
ChannelConfig,
DefaultEmpty,
}
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub struct AppMetadata {
pub appid_source: AppIdSource,
}
pub struct MinimalAppSet {
system_app: App,
system_app_metadata: AppMetadata,
}
impl MinimalAppSet {
pub fn new(system_app: App, system_app_metadata: AppMetadata) -> Self {
Self {
system_app,
system_app_metadata,
}
}
pub fn get_system_product_id(&self) -> &str {
self.system_app
.extra_fields
.get("product_id")
.map(|s| &**s)
.unwrap_or("")
}
pub fn get_system_current_channel(&self) -> &str {
self.system_app.get_current_channel()
}
pub fn get_system_target_channel(&self) -> &str {
self.system_app.get_target_channel()
}
pub fn set_system_target_channel(&mut self, channel: Option<String>, id: Option<String>) {
self.system_app.set_target_channel(channel, id);
}
pub fn get_system_app_metadata(&self) -> &AppMetadata {
&self.system_app_metadata
}
}
impl AppSet for MinimalAppSet {
fn get_apps(&self) -> Vec<App> {
std::iter::once(&self.system_app).cloned().collect()
}
fn iter_mut_apps(&mut self) -> Box<dyn Iterator<Item = &mut App> + '_> {
Box::new(std::iter::once(&mut self.system_app))
}
fn get_system_app_id(&self) -> &str {
&self.system_app.id
}
}