Skip to main content

gpui/platform/
platform_info.rs

1//! Runtime identity of the host operating system and application target.
2//!
3//! Host conventions are independent of the backend delivering the application:
4//! a browser on macOS follows Mac keyboard conventions without native Mac APIs.
5//! Backends provide this identity; consumers read it through the application.
6
7/// The host operating system and the kind of application delivering the UI.
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
9pub struct PlatformInfo {
10    /// The operating system whose input conventions the application follows.
11    pub os: OperatingSystem,
12    /// How the application is delivered, independently of its host OS.
13    pub target: PlatformTarget,
14}
15
16/// The host operating system, including when the application runs in a browser.
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
18pub enum OperatingSystem {
19    /// Apple's desktop operating system.
20    Mac,
21    /// Microsoft Windows.
22    Windows,
23    /// Linux, including browser hosts running ChromeOS.
24    Linux,
25    /// FreeBSD.
26    FreeBsd,
27    /// iOS and iPadOS.
28    Ios,
29    /// Android.
30    Android,
31    /// The backend could not identify the host operating system.
32    Unknown,
33}
34
35/// The kind of application delivering the UI, independently of its host OS.
36#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
37pub enum PlatformTarget {
38    /// A native application, including headless execution.
39    Native,
40    /// An application running in a browser.
41    Web,
42}
43
44impl PlatformInfo {
45    /// Whether the host operating system is macOS.
46    pub fn is_mac(self) -> bool {
47        self.os == OperatingSystem::Mac
48    }
49}