1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#[cfg(feature = "android")]
pub mod android_config;
#[cfg(feature = "apple")]
pub mod apple_config;

#[cfg(feature = "android")]
pub use android_config::*;
#[cfg(feature = "apple")]
pub use apple_config::*;

use crossbow::Permission;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

/// Cross-platform configuration for Android and Apple for Crossbow.
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct CrossbowMetadata {
    /// Application name for Android and Apple.
    ///
    /// **Important:** This property has lower priority than Android or Apple `manifest`
    /// or `info_plist` property.
    pub app_name: Option<String>,
    /// Assets directory path relatively to project path.
    ///
    /// If specified more than one - all assets will be placed into one directory.
    ///
    /// **Important:** This property has lower priority than Android or Apple `assets`
    /// property.
    #[serde(default)]
    pub assets: Vec<PathBuf>,
    /// Cross-platform permissions for Android and Apple.
    ///
    /// **Important:** This property has lower priority than AndroidManifest or Apple
    /// Info.plist properties.
    #[serde(default)]
    pub permissions: Vec<Permission>,
    /// Cross-platform icon for Android and Apple.
    ///
    /// All necessary icons will be automatically generated for Android and iOS.
    pub icon: Option<PathBuf>,
    #[cfg(feature = "android")]
    #[serde(default)]
    pub android: AndroidConfig,
    #[cfg(feature = "apple")]
    #[serde(default)]
    pub apple: AppleConfig,
}

impl CrossbowMetadata {
    #[cfg(feature = "android")]
    pub fn get_android_assets(&self) -> &[PathBuf] {
        if !self.android.assets.is_empty() {
            &self.android.assets
        } else {
            &self.assets
        }
    }

    #[cfg(feature = "apple")]
    pub fn get_apple_assets(&self) -> &[PathBuf] {
        if !self.apple.assets.is_empty() {
            &self.apple.assets
        } else {
            &self.assets
        }
    }

    #[cfg(feature = "android")]
    pub fn get_android_resources(&self) -> &[PathBuf] {
        &self.android.resources
    }

    #[cfg(feature = "apple")]
    pub fn get_apple_resources(&self) -> &[PathBuf] {
        &self.apple.resources
    }
}