Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions crates/gpui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ impl Application {
#[cfg(any(test, feature = "test-support"))]
log::info!("GPUI was compiled in test mode");

let liveness = Arc::new(());
Self(App::new_app(
current_platform(false),
current_platform(false, Arc::downgrade(&liveness)),
liveness,
Arc::new(()),
Arc::new(NullHttpClient),
))
Expand All @@ -149,8 +151,10 @@ impl Application {
/// but makes it possible to run an application in an context like
/// SSH, where GUI applications are not allowed.
pub fn headless() -> Self {
let liveness = Arc::new(());
Self(App::new_app(
current_platform(true),
current_platform(true, Arc::downgrade(&liveness)),
liveness,
Arc::new(()),
Arc::new(NullHttpClient),
))
Expand Down Expand Up @@ -584,7 +588,7 @@ impl GpuiMode {
/// You need a reference to an `App` to access the state of a [Entity].
pub struct App {
pub(crate) this: Weak<AppCell>,
pub(crate) liveness: std::sync::Arc<()>,
pub(crate) _liveness: Arc<()>,
pub(crate) platform: Rc<dyn Platform>,
pub(crate) mode: GpuiMode,
text_system: Arc<TextSystem>,
Expand Down Expand Up @@ -646,13 +650,14 @@ impl App {
#[allow(clippy::new_ret_no_self)]
pub(crate) fn new_app(
platform: Rc<dyn Platform>,
liveness: Arc<()>,
asset_source: Arc<dyn AssetSource>,
http_client: Arc<dyn HttpClient>,
) -> Rc<AppCell> {
let executor = platform.background_executor();
let background_executor = platform.background_executor();
let foreground_executor = platform.foreground_executor();
assert!(
executor.is_main_thread(),
background_executor.is_main_thread(),
"must construct App on main thread"
);

Expand All @@ -664,7 +669,7 @@ impl App {
let app = Rc::new_cyclic(|this| AppCell {
app: RefCell::new(App {
this: this.clone(),
liveness: std::sync::Arc::new(()),
_liveness: liveness,
platform: platform.clone(),
text_system,
text_rendering_mode: Rc::new(Cell::new(TextRenderingMode::default())),
Expand All @@ -673,7 +678,7 @@ impl App {
flushing_effects: false,
pending_updates: 0,
active_drag: None,
background_executor: executor,
background_executor,
foreground_executor,
svg_renderer: SvgRenderer::new(asset_source.clone()),
loading_assets: Default::default(),
Expand Down Expand Up @@ -1494,7 +1499,6 @@ impl App {
pub fn to_async(&self) -> AsyncApp {
AsyncApp {
app: self.this.clone(),
liveness_token: std::sync::Arc::downgrade(&self.liveness),
background_executor: self.background_executor.clone(),
foreground_executor: self.foreground_executor.clone(),
}
Expand Down
8 changes: 2 additions & 6 deletions crates/gpui/src/app/async_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use super::{Context, WeakEntity};
#[derive(Clone)]
pub struct AsyncApp {
pub(crate) app: Weak<AppCell>,
pub(crate) liveness_token: std::sync::Weak<()>,
pub(crate) background_executor: BackgroundExecutor,
pub(crate) foreground_executor: ForegroundExecutor,
}
Expand Down Expand Up @@ -186,7 +185,7 @@ impl AsyncApp {
{
let mut cx = self.clone();
self.foreground_executor
.spawn_context(self.liveness_token.clone(), async move { f(&mut cx).await })
.spawn(async move { f(&mut cx).await })
}

/// Determine whether global state of the specified type has been assigned.
Expand Down Expand Up @@ -335,10 +334,7 @@ impl AsyncWindowContext {
{
let mut cx = self.clone();
self.foreground_executor
.spawn_context(
self.app.liveness_token.clone(),
async move { f(&mut cx).await },
)
.spawn(async move { f(&mut cx).await })
}

/// Present a platform dialog.
Expand Down
7 changes: 4 additions & 3 deletions crates/gpui/src/app/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,16 @@ impl TestAppContext {
/// Creates a new `TestAppContext`. Usually you can rely on `#[gpui::test]` to do this for you.
pub fn build(dispatcher: TestDispatcher, fn_name: Option<&'static str>) -> Self {
let arc_dispatcher = Arc::new(dispatcher.clone());
let liveness = std::sync::Arc::new(());
let background_executor = BackgroundExecutor::new(arc_dispatcher.clone());
let foreground_executor = ForegroundExecutor::new(arc_dispatcher);
let foreground_executor =
ForegroundExecutor::new(arc_dispatcher, Arc::downgrade(&liveness));
let platform = TestPlatform::new(background_executor.clone(), foreground_executor.clone());
let asset_source = Arc::new(());
let http_client = http_client::FakeHttpClient::with_404_response();
let text_system = Arc::new(TextSystem::new(platform.text_system()));

let mut app = App::new_app(platform.clone(), asset_source, http_client);
let app = App::new_app(platform.clone(), liveness, asset_source, http_client);
app.borrow_mut().mode = GpuiMode::test();

Self {
Expand Down Expand Up @@ -405,7 +407,6 @@ impl TestAppContext {
pub fn to_async(&self) -> AsyncApp {
AsyncApp {
app: Rc::downgrade(&self.app),
liveness_token: std::sync::Arc::downgrade(&self.app.borrow().liveness),
background_executor: self.background_executor.clone(),
foreground_executor: self.foreground_executor.clone(),
}
Expand Down
6 changes: 4 additions & 2 deletions crates/gpui/src/app/visual_test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ impl VisualTestAppContext {
/// - Screenshots can be captured via ScreenCaptureKit
/// - All platform APIs work as they do in production
pub fn new() -> Self {
let platform = current_platform(false);
let liveness = Arc::new(());
let liveness_weak = Arc::downgrade(&liveness);
let platform = current_platform(false, liveness_weak);
let background_executor = platform.background_executor();
let foreground_executor = platform.foreground_executor();
let text_system = Arc::new(TextSystem::new(platform.text_system()));

let asset_source = Arc::new(());
let http_client = http_client::FakeHttpClient::with_404_response();

let mut app = App::new_app(platform.clone(), asset_source, http_client);
let mut app = App::new_app(platform.clone(), liveness, asset_source, http_client);
app.borrow_mut().mode = GpuiMode::test();

Self {
Expand Down
Loading