AirLibrary/Updates/
PlatformDetect.rs1#[derive(Debug, Clone)]
10pub struct PlatformInfo {
11 pub platform:&'static str,
12
13 pub arch:&'static str,
14
15 pub package_format:PackageFormat,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum PackageFormat {
21 WindowsExe,
22
23 MacOsDmg,
24
25 LinuxAppImage,
26
27 LinuxDeb,
28
29 LinuxRpm,
30}
31
32impl PackageFormat {
33 pub fn extension(&self) -> &'static str {
34 match self {
35 PackageFormat::WindowsExe => "exe",
36
37 PackageFormat::MacOsDmg => "dmg",
38
39 PackageFormat::LinuxAppImage => "AppImage",
40
41 PackageFormat::LinuxDeb => "deb",
42
43 PackageFormat::LinuxRpm => "rpm",
44 }
45 }
46}
47
48pub fn detect_platform() -> PlatformInfo {
50 let platform = if cfg!(target_os = "windows") {
51 "windows"
52 } else if cfg!(target_os = "macos") {
53 "macos"
54 } else if cfg!(target_os = "linux") {
55 "linux"
56 } else {
57 "unknown"
58 };
59
60 let arch = if cfg!(target_arch = "x86_64") {
61 "x64"
62 } else if cfg!(target_arch = "aarch64") {
63 "arm64"
64 } else if cfg!(target_arch = "x86") {
65 "ia32"
66 } else {
67 "unknown"
68 };
69
70 let package_format = match (platform, arch) {
71 ("windows", _) => PackageFormat::WindowsExe,
72
73 ("macos", _) => PackageFormat::MacOsDmg,
74
75 ("linux", _) => PackageFormat::LinuxAppImage,
76
77 _ => PackageFormat::LinuxAppImage,
78 };
79
80 PlatformInfo { platform, arch, package_format }
81}