Skip to main content

gpui_core/platform/
platform_info.rs

1//! Runtime identity of the host operating system and application target.
2
3/// The host operating system and the kind of application delivering the UI.
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5pub struct PlatformInfo {
6    /// The operating system whose input conventions the application follows.
7    pub os: OperatingSystem,
8    /// How the application is delivered.
9    pub target: PlatformTarget,
10}
11
12/// The host operating system.
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
14pub enum OperatingSystem {
15    /// macOS.
16    Mac,
17    /// Windows.
18    Windows,
19    /// Linux.
20    Linux,
21    /// FreeBSD.
22    FreeBsd,
23    /// iOS or iPadOS.
24    Ios,
25    /// Android.
26    Android,
27    /// The backend could not identify the host operating system.
28    Unknown,
29}
30
31/// The kind of application delivering the UI.
32#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
33pub enum PlatformTarget {
34    /// A native application, including headless execution.
35    Native,
36    /// An application running in a browser.
37    Web,
38}
39
40impl PlatformInfo {
41    /// Returns whether the host follows macOS input conventions.
42    pub fn is_mac(self) -> bool {
43        self.os == OperatingSystem::Mac
44    }
45}