1#![doc = include_str!("../README.md")]
2
3extern crate self as gpui;
4
5use std::{path::PathBuf, rc::Rc, sync::Arc};
6
7pub use gpui_core::*;
8
9pub fn background_executor() -> BackgroundExecutor {
11 gpui_platform::background_executor()
12}
13
14pub fn current_platform(headless: bool) -> Rc<dyn Platform> {
16 gpui_platform::current_platform(headless)
17}
18
19#[cfg(all(
21 feature = "test-support",
22 any(
23 target_os = "macos",
24 target_os = "linux",
25 target_os = "freebsd",
26 target_os = "windows"
27 )
28))]
29pub struct RealVisualTestContext(gpui_core::RealVisualTestContext);
30
31#[cfg(all(
32 feature = "test-support",
33 any(
34 target_os = "macos",
35 target_os = "linux",
36 target_os = "freebsd",
37 target_os = "windows"
38 )
39))]
40impl RealVisualTestContext {
41 pub fn new_if_supported() -> Option<Self> {
43 let capabilities = VisualTestCapabilities::detect();
44 (capabilities.real_renderer && capabilities.screenshot_capture).then(Self::new)
45 }
46
47 pub fn new() -> Self {
49 Self(gpui_core::RealVisualTestContext::with_platform(
50 gpui_platform::current_platform(false),
51 ))
52 }
53
54 pub fn with_asset_source(asset_source: Arc<dyn AssetSource>) -> Self {
56 Self(
57 gpui_core::RealVisualTestContext::with_platform_and_asset_source(
58 gpui_platform::current_platform(false),
59 asset_source,
60 ),
61 )
62 }
63
64 pub fn run<F>(self, on_finish_launching: F)
66 where
67 F: 'static + FnOnce(&mut Self),
68 {
69 let platform = self.0.visual_test_platform();
70 let mut cx = Some(self);
71 platform.run(Box::new(move || {
72 if let Some(mut cx) = cx.take() {
73 on_finish_launching(&mut cx);
74 }
75 }));
76 }
77}
78
79#[cfg(all(
80 feature = "test-support",
81 any(
82 target_os = "macos",
83 target_os = "linux",
84 target_os = "freebsd",
85 target_os = "windows"
86 )
87))]
88impl std::ops::Deref for RealVisualTestContext {
89 type Target = gpui_core::RealVisualTestContext;
90
91 fn deref(&self) -> &Self::Target {
92 &self.0
93 }
94}
95
96#[cfg(all(
97 feature = "test-support",
98 any(
99 target_os = "macos",
100 target_os = "linux",
101 target_os = "freebsd",
102 target_os = "windows"
103 )
104))]
105impl std::ops::DerefMut for RealVisualTestContext {
106 fn deref_mut(&mut self) -> &mut Self::Target {
107 &mut self.0
108 }
109}
110
111pub struct Application(gpui_core::Application);
116
117impl Application {
118 #[allow(clippy::new_without_default)]
122 pub fn new() -> Self {
123 #[cfg(any(test, feature = "test-support"))]
124 log::info!("GPUI was compiled in test mode");
125
126 Self(gpui_platform::application())
127 }
128
129 pub fn headless() -> Self {
131 Self(gpui_platform::headless())
132 }
133
134 pub fn with_platform(platform: Rc<dyn Platform>) -> Self {
136 Self(gpui_core::Application::with_platform(platform))
137 }
138
139 pub fn inaccessible(self) -> Self {
141 Self(self.0.inaccessible())
142 }
143
144 pub fn with_assets(self, asset_source: impl AssetSource) -> Self {
146 Self(self.0.with_assets(asset_source))
147 }
148
149 pub fn with_http_client(self, http_client: Arc<dyn http_client::HttpClient>) -> Self {
151 Self(self.0.with_http_client(http_client))
152 }
153
154 pub fn with_resource_profile(self, profile: impl Into<AppResourceProfile>) -> Self {
156 Self(self.0.with_resource_profile(profile))
157 }
158
159 pub fn with_quit_mode(self, mode: QuitMode) -> Self {
162 Self(self.0.with_quit_mode(mode))
163 }
164
165 pub fn run<F>(self, on_finish_launching: F)
167 where
168 F: 'static + FnOnce(&mut App),
169 {
170 self.0.run(on_finish_launching)
171 }
172
173 pub fn run_embedded<F>(self, on_finish_launching: F) -> ApplicationHandle
175 where
176 F: 'static + FnOnce(&mut App),
177 {
178 self.0.run_embedded(on_finish_launching)
179 }
180
181 pub fn on_open_urls<F>(&self, callback: F) -> &Self
183 where
184 F: 'static + FnMut(Vec<String>),
185 {
186 self.0.on_open_urls(callback);
187 self
188 }
189
190 pub fn on_reopen<F>(&self, callback: F) -> &Self
192 where
193 F: 'static + FnMut(&mut App),
194 {
195 self.0.on_reopen(callback);
196 self
197 }
198
199 pub fn background_executor(&self) -> BackgroundExecutor {
201 self.0.background_executor()
202 }
203
204 pub fn foreground_executor(&self) -> ForegroundExecutor {
206 self.0.foreground_executor()
207 }
208
209 pub fn text_system(&self) -> Arc<TextSystem> {
211 self.0.text_system()
212 }
213
214 pub fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf> {
216 self.0.path_for_auxiliary_executable(name)
217 }
218}