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