Skip to main content

appcore_contracts/policy/
update.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: update.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/07/22 15:41:18 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/07/22 15:41:18 by dnettoRaw
8//      ###########      S: 1.0.1-rc.8
9// =============================================================================
10
11use super::*;
12
13/// Application update preferences, independent of update providers.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct UpdatePolicy {
16    channel: String,
17    automatic: bool,
18}
19
20impl UpdatePolicy {
21    /// Creates an update policy.
22    pub fn new(channel: impl Into<String>, automatic: bool) -> ContractResult<Self> {
23        let policy = Self {
24            channel: channel.into(),
25            automatic,
26        };
27        policy.validate()?;
28        Ok(policy)
29    }
30
31    /// Returns the application-selected update channel.
32    pub fn channel(&self) -> &str {
33        &self.channel
34    }
35
36    /// Reports whether automatic updates are allowed.
37    pub fn is_automatic(&self) -> bool {
38        self.automatic
39    }
40
41    pub(crate) fn validate(&self) -> ContractResult<()> {
42        validate_text("update.channel", &self.channel, 64)
43    }
44}