Skip to main content

runlatch_core/
model.rs

1//! Provider-agnostic data model shared across all autostart providers.
2
3use serde::Serialize;
4
5/// Whether an autostart entry applies to the current user or the whole system.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
7#[serde(rename_all = "lowercase")]
8pub enum Scope {
9    /// User-level autostart (e.g. `~/.config/autostart`, systemd `--user` units).
10    User,
11    /// System-level autostart (e.g. `/etc/xdg/autostart`, systemd system units).
12    System,
13}
14
15/// A single autostart item, normalized across providers.
16///
17/// `id` is stable and unique *within a provider*; pair it with [`AutostartEntry::source`]
18/// (the provider id) to address an entry unambiguously across the whole registry.
19///
20/// ```
21/// use runlatch_core::{AutostartEntry, Scope};
22///
23/// let entry = AutostartEntry {
24///     id: "redshift".into(),
25///     display_name: "Redshift".into(),
26///     description: None,
27///     command: "redshift-gtk".into(),
28///     icon: None,
29///     enabled: true,
30///     source: "xdg-autostart".into(),
31///     scope: Scope::User,
32/// };
33/// assert_eq!(format!("{}:{}", entry.source, entry.id), "xdg-autostart:redshift");
34/// ```
35#[derive(Debug, Clone, Serialize)]
36pub struct AutostartEntry {
37    /// Stable, unique within a provider (e.g. a `.desktop` file stem or a unit name).
38    pub id: String,
39    /// Human-readable name for display.
40    pub display_name: String,
41    /// Optional longer description.
42    pub description: Option<String>,
43    /// The command that runs at startup.
44    pub command: String,
45    /// Optional icon name or path.
46    pub icon: Option<String>,
47    /// Whether the entry is currently enabled.
48    pub enabled: bool,
49    /// The id of the provider that produced this entry, e.g. `"systemd-user"`.
50    pub source: String,
51    /// Whether the entry is user- or system-scoped.
52    pub scope: Scope,
53}