Some checks failed
Update All Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Triage Project Sync (#84) / Sync triage project (push) Has been cancelled
release_nightly / notify_on_failure (push) Has been cancelled
release_nightly / check_style (push) Has been cancelled
release_nightly / run_tests_windows (push) Has been cancelled
release_nightly / clippy_windows (push) Has been cancelled
release_nightly / bundle_linux_aarch64 (push) Has been cancelled
release_nightly / bundle_linux_x86_64 (push) Has been cancelled
release_nightly / bundle_mac_aarch64 (push) Has been cancelled
release_nightly / bundle_mac_x86_64 (push) Has been cancelled
release_nightly / bundle_windows_aarch64 (push) Has been cancelled
release_nightly / bundle_windows_x86_64 (push) Has been cancelled
release_nightly / build_nix_linux_x86_64 (push) Has been cancelled
release_nightly / build_nix_mac_aarch64 (push) Has been cancelled
release_nightly / update_nightly_tag (push) Has been cancelled
Hotfix Review Monitor / check-hotfix-reviews (push) Has been cancelled
Stale PR Review Reminder / check-stale-prs (push) Has been cancelled
Update Weekly Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Bump collab-staging Tag / update-collab-staging-tag (push) Has been cancelled
compliance_check / scheduled_compliance_check (push) Has been cancelled
Single-commit orphan branch: full zed-industries/zed @ 8c74db0 source tree with a 3-file patch applied (no upstream history). Patch (crates/gpui_linux/src/linux/wayland/): - serial.rs: add SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; add latest_serial_of() - window.rs: activate() uses keyboard-enter serial (Mutter focus gate) Mutter honors window activation only when the token carries the keyboard- focus serial from wl_keyboard.enter; GPUI used a stale mouse-press serial. See docs/tray-window-focus-wayland.md in logiguard. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
187 lines
5.6 KiB
Rust
187 lines
5.6 KiB
Rust
//! Convenience crate that re-exports GPUI's platform traits and the
|
|
//! `current_platform` constructor so consumers don't need `#[cfg]` gating.
|
|
|
|
pub use gpui::Platform;
|
|
|
|
use std::rc::Rc;
|
|
|
|
/// Returns a background executor for the current platform.
|
|
pub fn background_executor() -> gpui::BackgroundExecutor {
|
|
current_platform(true).background_executor()
|
|
}
|
|
|
|
pub fn application() -> gpui::Application {
|
|
gpui::Application::with_platform(current_platform(false))
|
|
}
|
|
|
|
pub fn headless() -> gpui::Application {
|
|
gpui::Application::with_platform(current_platform(true))
|
|
}
|
|
|
|
/// Unlike `application`, this function returns a single-threaded web application.
|
|
#[cfg(target_family = "wasm")]
|
|
pub fn single_threaded_web() -> gpui::Application {
|
|
gpui::Application::with_platform(Rc::new(gpui_web::WebPlatform::new(false)))
|
|
}
|
|
|
|
/// Initializes panic hooks and logging for the web platform.
|
|
/// Call this before running the application in a wasm_bindgen entrypoint.
|
|
#[cfg(target_family = "wasm")]
|
|
pub fn web_init() {
|
|
console_error_panic_hook::set_once();
|
|
gpui_web::init_logging();
|
|
}
|
|
|
|
/// Returns the default [`Platform`] for the current OS.
|
|
pub fn current_platform(headless: bool) -> Rc<dyn Platform> {
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
Rc::new(gpui_macos::MacPlatform::new(headless))
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
{
|
|
Rc::new(
|
|
gpui_windows::WindowsPlatform::new(headless)
|
|
.expect("failed to initialize Windows platform"),
|
|
)
|
|
}
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
|
{
|
|
gpui_linux::current_platform(headless)
|
|
}
|
|
|
|
#[cfg(target_family = "wasm")]
|
|
{
|
|
let _ = headless;
|
|
Rc::new(gpui_web::WebPlatform::new(true))
|
|
}
|
|
}
|
|
|
|
/// Returns a new [`HeadlessRenderer`] for the current platform, if available.
|
|
#[cfg(feature = "test-support")]
|
|
pub fn current_headless_renderer() -> Option<Box<dyn gpui::PlatformHeadlessRenderer>> {
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
Some(Box::new(
|
|
gpui_macos::metal_renderer::MetalHeadlessRenderer::new(),
|
|
))
|
|
}
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
{
|
|
None
|
|
}
|
|
}
|
|
|
|
#[cfg(all(test, target_os = "macos"))]
|
|
mod tests {
|
|
use super::*;
|
|
use gpui::{AppContext, Empty, VisualTestAppContext};
|
|
use std::cell::RefCell;
|
|
use std::time::Duration;
|
|
|
|
// Note: All VisualTestAppContext tests are ignored by default because they require
|
|
// the macOS main thread. Standard Rust tests run on worker threads, which causes
|
|
// SIGABRT when interacting with macOS AppKit/Cocoa APIs.
|
|
//
|
|
// To run these tests, use:
|
|
// cargo test -p gpui visual_test_context -- --ignored --test-threads=1
|
|
|
|
#[test]
|
|
#[ignore] // Requires macOS main thread
|
|
fn test_foreground_tasks_run_with_run_until_parked() {
|
|
let mut cx = VisualTestAppContext::new(current_platform(false));
|
|
|
|
let task_ran = Rc::new(RefCell::new(false));
|
|
|
|
// Spawn a foreground task via the App's spawn method
|
|
// This should use our TestDispatcher, not the MacDispatcher
|
|
{
|
|
let task_ran = task_ran.clone();
|
|
cx.update(|cx| {
|
|
cx.spawn(async move |_| {
|
|
*task_ran.borrow_mut() = true;
|
|
})
|
|
.detach();
|
|
});
|
|
}
|
|
|
|
// The task should not have run yet
|
|
assert!(!*task_ran.borrow());
|
|
|
|
// Run until parked should execute the foreground task
|
|
cx.run_until_parked();
|
|
|
|
// Now the task should have run
|
|
assert!(*task_ran.borrow());
|
|
}
|
|
|
|
#[test]
|
|
#[ignore] // Requires macOS main thread
|
|
fn test_advance_clock_triggers_delayed_tasks() {
|
|
let mut cx = VisualTestAppContext::new(current_platform(false));
|
|
|
|
let task_ran = Rc::new(RefCell::new(false));
|
|
|
|
// Spawn a task that waits for a timer
|
|
{
|
|
let task_ran = task_ran.clone();
|
|
let executor = cx.background_executor.clone();
|
|
cx.update(|cx| {
|
|
cx.spawn(async move |_| {
|
|
executor.timer(Duration::from_millis(500)).await;
|
|
*task_ran.borrow_mut() = true;
|
|
})
|
|
.detach();
|
|
});
|
|
}
|
|
|
|
// Run until parked - the task should be waiting on the timer
|
|
cx.run_until_parked();
|
|
assert!(!*task_ran.borrow());
|
|
|
|
// Advance clock past the timer duration
|
|
cx.advance_clock(Duration::from_millis(600));
|
|
|
|
// Now the task should have completed
|
|
assert!(*task_ran.borrow());
|
|
}
|
|
|
|
#[test]
|
|
#[ignore] // Requires macOS main thread - window creation fails on test threads
|
|
fn test_window_spawn_uses_test_dispatcher() {
|
|
let mut cx = VisualTestAppContext::new(current_platform(false));
|
|
|
|
let task_ran = Rc::new(RefCell::new(false));
|
|
|
|
let window = cx
|
|
.open_offscreen_window_default(|_, cx| cx.new(|_| Empty))
|
|
.expect("Failed to open window");
|
|
|
|
// Spawn a task via window.spawn - this is the critical test case
|
|
// for tooltip behavior, as tooltips use window.spawn for delayed show
|
|
{
|
|
let task_ran = task_ran.clone();
|
|
cx.update_window(window.into(), |_, window, cx| {
|
|
window
|
|
.spawn(cx, async move |_| {
|
|
*task_ran.borrow_mut() = true;
|
|
})
|
|
.detach();
|
|
})
|
|
.ok();
|
|
}
|
|
|
|
// The task should not have run yet
|
|
assert!(!*task_ran.borrow());
|
|
|
|
// Run until parked should execute the foreground task spawned via window
|
|
cx.run_until_parked();
|
|
|
|
// Now the task should have run
|
|
assert!(*task_ran.borrow());
|
|
}
|
|
}
|