Skip to main content

gpui_platform/
gpui_platform.rs

1//! Platform composition helpers for fc-gpui.
2//!
3//! This crate is an internal migration boundary. The published `fc-gpui`
4//! package remains the compatibility entry point for ordinary downstream users.
5
6use std::rc::Rc;
7
8pub use gpui::Platform;
9
10/// Returns a background executor for the current platform.
11pub fn background_executor() -> gpui::BackgroundExecutor {
12    current_platform(true).background_executor()
13}
14
15/// Builds an application using the current graphical platform.
16pub fn application() -> gpui::Application {
17    gpui::Application::with_platform(current_platform(false))
18}
19
20/// Builds an application using the current platform in headless mode.
21pub fn headless() -> gpui::Application {
22    gpui::Application::with_platform(current_platform(true))
23}
24
25/// Returns the current platform implementation.
26#[cfg(any(target_os = "linux", target_os = "freebsd"))]
27pub fn current_platform(headless: bool) -> Rc<dyn Platform> {
28    gpui_linux::current_platform(headless)
29}
30
31/// Returns the current platform implementation.
32#[cfg(target_os = "macos")]
33pub fn current_platform(headless: bool) -> Rc<dyn Platform> {
34    gpui_macos::current_platform(headless)
35}
36
37/// Returns the current platform implementation.
38#[cfg(target_os = "windows")]
39pub fn current_platform(headless: bool) -> Rc<dyn Platform> {
40    gpui_windows::current_platform(headless)
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn construction_entry_points_have_stable_types() {
49        let _: fn() -> gpui::Application = application;
50        let _: fn() -> gpui::Application = headless;
51        let _: fn() -> gpui::BackgroundExecutor = background_executor;
52        let _: fn(bool) -> Rc<dyn Platform> = current_platform;
53    }
54}