Skip to main content
KeyOS API Reference

foundation_manifest/
lib.rs

1// SPDX-FileCopyrightText: 2026 Foundation Devices, Inc. <hello@foundation.xyz>
2// SPDX-License-Identifier: MIT
3
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct AppManifest {
6    pub app_name: String,
7    pub app_id: String,
8    pub icon: String,
9    pub permissions: Vec<String>,
10    pub target_api_version: String,
11}
12
13impl AppManifest {
14    pub fn example() -> Self {
15        Self {
16            app_name: "Hello World".to_string(),
17            app_id: "com.foundation.hello-world".to_string(),
18            icon: "icon.png".to_string(),
19            permissions: vec!["nfc".to_string()],
20            target_api_version: "1".to_string(),
21        }
22    }
23
24    pub fn to_toml_string(&self) -> String {
25        let permissions = if self.permissions.is_empty() {
26            "[]".to_string()
27        } else {
28            format!(
29                "[{}]",
30                self.permissions
31                    .iter()
32                    .map(|permission| format!("\"{permission}\""))
33                    .collect::<Vec<_>>()
34                    .join(", ")
35            )
36        };
37
38        format!(
39            "[app]\nname = \"{}\"\napp_id = \"{}\"\nicon = \"{}\"\npermissions = {}\ntarget_api_version = \"{}\"\n",
40            self.app_name, self.app_id, self.icon, permissions, self.target_api_version
41        )
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::AppManifest;
48
49    #[test]
50    fn example_manifest_renders_to_toml() {
51        let rendered = AppManifest::example().to_toml_string();
52        assert!(rendered.contains("name = \"Hello World\""));
53        assert!(rendered.contains("target_api_version = \"1\""));
54    }
55}