#![doc = include_str!("../README.md")]
extern crate self as gpui;
use std::{path::PathBuf, rc::Rc, sync::Arc};
pub use gpui_core::*;
pub fn background_executor() -> BackgroundExecutor {
gpui_platform::background_executor()
}
pub fn current_platform(headless: bool) -> Rc<dyn Platform> {
gpui_platform::current_platform(headless)
}
#[cfg(all(
feature = "test-support",
any(
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
target_os = "windows"
)
))]
pub struct RealVisualTestContext(gpui_core::RealVisualTestContext);
#[cfg(all(
feature = "test-support",
any(
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
target_os = "windows"
)
))]
impl RealVisualTestContext {
pub fn new_if_supported() -> Option<Self> {
let capabilities = VisualTestCapabilities::detect();
(capabilities.real_renderer && capabilities.screenshot_capture).then(Self::new)
}
pub fn new() -> Self {
Self(gpui_core::RealVisualTestContext::with_platform(
gpui_platform::current_platform(false),
))
}
pub fn with_asset_source(asset_source: Arc<dyn AssetSource>) -> Self {
Self(
gpui_core::RealVisualTestContext::with_platform_and_asset_source(
gpui_platform::current_platform(false),
asset_source,
),
)
}
pub fn run<F>(self, on_finish_launching: F)
where
F: 'static + FnOnce(&mut Self),
{
let platform = self.0.visual_test_platform();
let mut cx = Some(self);
platform.run(Box::new(move || {
if let Some(mut cx) = cx.take() {
on_finish_launching(&mut cx);
}
}));
}
}
#[cfg(all(
feature = "test-support",
any(
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
target_os = "windows"
)
))]
impl std::ops::Deref for RealVisualTestContext {
type Target = gpui_core::RealVisualTestContext;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[cfg(all(
feature = "test-support",
any(
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
target_os = "windows"
)
))]
impl std::ops::DerefMut for RealVisualTestContext {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
pub struct Application(gpui_core::Application);
impl Application {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
#[cfg(any(test, feature = "test-support"))]
log::info!("GPUI was compiled in test mode");
Self(gpui_platform::application())
}
pub fn headless() -> Self {
Self(gpui_platform::headless())
}
pub fn with_platform(platform: Rc<dyn Platform>) -> Self {
Self(gpui_core::Application::with_platform(platform))
}
pub fn inaccessible(self) -> Self {
Self(self.0.inaccessible())
}
pub fn with_assets(self, asset_source: impl AssetSource) -> Self {
Self(self.0.with_assets(asset_source))
}
pub fn with_http_client(self, http_client: Arc<dyn http_client::HttpClient>) -> Self {
Self(self.0.with_http_client(http_client))
}
pub fn with_resource_profile(self, profile: impl Into<AppResourceProfile>) -> Self {
Self(self.0.with_resource_profile(profile))
}
pub fn with_quit_mode(self, mode: QuitMode) -> Self {
Self(self.0.with_quit_mode(mode))
}
pub fn run<F>(self, on_finish_launching: F)
where
F: 'static + FnOnce(&mut App),
{
self.0.run(on_finish_launching)
}
pub fn run_embedded<F>(self, on_finish_launching: F) -> ApplicationHandle
where
F: 'static + FnOnce(&mut App),
{
self.0.run_embedded(on_finish_launching)
}
pub fn on_open_urls<F>(&self, callback: F) -> &Self
where
F: 'static + FnMut(Vec<String>),
{
self.0.on_open_urls(callback);
self
}
pub fn on_reopen<F>(&self, callback: F) -> &Self
where
F: 'static + FnMut(&mut App),
{
self.0.on_reopen(callback);
self
}
pub fn background_executor(&self) -> BackgroundExecutor {
self.0.background_executor()
}
pub fn foreground_executor(&self) -> ForegroundExecutor {
self.0.foreground_executor()
}
pub fn text_system(&self) -> Arc<TextSystem> {
self.0.text_system()
}
pub fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf> {
self.0.path_for_auxiliary_executable(name)
}
}