parent
17b554d0dd
commit
16f639d0af
6 changed files with 213 additions and 12 deletions
48
cosmic-greeter-config/src/lib.rs
Normal file
48
cosmic-greeter-config/src/lib.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
pub mod user;
|
||||
|
||||
use std::{collections::HashMap, num::NonZeroU32};
|
||||
|
||||
use cosmic_config::{cosmic_config_derive::CosmicConfigEntry, CosmicConfigEntry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const APP_ID: &str = "com.system76.CosmicGreeter";
|
||||
pub const CONFIG_VERSION: u64 = 1;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, CosmicConfigEntry, Deserialize, Serialize)]
|
||||
#[version = 1]
|
||||
#[id = "com.system76.CosmicGreeter"]
|
||||
pub struct Config {
|
||||
#[serde(skip_serializing_if = "HashMap::is_empty")]
|
||||
pub users: HashMap<NonZeroU32, user::UserState>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> (Self, Option<cosmic_config::Config>) {
|
||||
crate::load()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn load<C>() -> (C, Option<cosmic_config::Config>)
|
||||
where
|
||||
C: Default + CosmicConfigEntry,
|
||||
{
|
||||
match cosmic_config::Config::new(APP_ID, CONFIG_VERSION) {
|
||||
Ok(handler) => {
|
||||
let config = C::get_entry(&handler)
|
||||
.inspect_err(|(errors, _)| {
|
||||
for err in errors {
|
||||
log::error!("{err}")
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|(_, config)| config);
|
||||
(config, Some(handler))
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to get settings for `{APP_ID}` (v {CONFIG_VERSION}): {e:?}");
|
||||
(C::default(), None)
|
||||
}
|
||||
}
|
||||
}
|
||||
20
cosmic-greeter-config/src/user.rs
Normal file
20
cosmic-greeter-config/src/user.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Per user state for Greeter.
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct UserState {
|
||||
#[serde(skip_serializing_if = "invalid_uid")]
|
||||
pub uid: NonZeroU32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub last_session: Option<String>,
|
||||
}
|
||||
|
||||
// Only serialize users not system accounts
|
||||
const fn invalid_uid(uid: &NonZeroU32) -> bool {
|
||||
uid.get() < 1000
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue