Skip to main content

tilo_dialogs/
caps.rs

1//! What this crate provides on each target, as data an app can query.
2
3pub use tilo_platform_caps::{Availability, availability, available};
4
5pub type Unsupported = tilo_platform_caps::Unsupported<Feature>;
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum Feature {
10    OpenContents,
11    SaveContents,
12    Paths,
13    Launch,
14    OpenUri,
15}
16
17/// Choosing files to read by contents.
18pub(crate) const WEB_PATHS: &str = "This browser can't choose a file by its place on this device.";
19pub(crate) const WEB_LAUNCH: &str = "This browser can't open files from this device in other apps.";
20
21impl tilo_platform_caps::Feature for Feature {
22    /// Saving bytes where the person chooses; on the web the browser downloads
23    /// them.
24    fn targets(self) -> [Availability; 3] {
25        use Availability::{Available, Unsupported};
26        match self {
27            Self::OpenContents | Self::SaveContents | Self::OpenUri => {
28                [Available, Available, Available]
29            }
30            Self::Paths => [Available, Available, Unsupported(WEB_PATHS)],
31            Self::Launch => [Available, Available, Unsupported(WEB_LAUNCH)],
32        }
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39    use tilo_platform_caps::Feature as _;
40
41    #[test]
42    fn this_target_reads_its_own_column() {
43        assert_eq!(availability(Feature::Paths), Availability::Available);
44        let web = Feature::Paths.targets()[2];
45        assert_eq!(web, Availability::Unsupported(WEB_PATHS));
46    }
47}