From 9537bbbb4831cf237d7b706a38e7fa8147a35cd8 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 10:00:18 -0700 Subject: [PATCH] Land #1347: build and run the Apple-event dispatch tests on every platform The macOS app code is not compiled by PR CI (Linux). The dispatch and its tests do not need the Apple-event crate, so they now build everywhere and check the opening and unsaved-changes paths against CadApp on each change. --- apps/cadcraft/src/apple_events.rs | 15 +++++++++++++-- apps/cadcraft/src/main.rs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/cadcraft/src/apple_events.rs b/apps/cadcraft/src/apple_events.rs index e84211bb5..642cafeaa 100644 --- a/apps/cadcraft/src/apple_events.rs +++ b/apps/cadcraft/src/apple_events.rs @@ -12,14 +12,25 @@ use std::path::PathBuf; use cadcraft_ui_egui::CadApp; +#[cfg(target_os = "macos")] use fmv_macos_events::{Event, Inbox, Registration}; +/// The shape of `fmv_macos_events::Event`, so [`dispatch`] and its tests also build and run where +/// that crate is not compiled (PR CI runs on Linux). On macOS the crate's own type is used. +#[cfg(not(target_os = "macos"))] +enum Event { + Open(Vec), + Quit, +} + /// Keeps the Apple-event handlers registered; hold it until the event loop returns. +#[cfg(target_os = "macos")] pub struct AppleEvents { _registration: Registration, inbox: Inbox, } +#[cfg(target_os = "macos")] impl AppleEvents { /// Register the handlers. Call on the main thread before the event loop starts, so the event /// that launched the app (a Finder double-click) is caught too. @@ -69,6 +80,7 @@ fn dispatch(events: impl IntoIterator, app: &mut CadApp) -> bool { } /// Drain the inbox each frame; a quit closes the window like Cmd+Q, prompting for unsaved drawings. +#[cfg(target_os = "macos")] pub fn poll(inbox: &Inbox, app: &mut CadApp, ctx: &egui::Context) { if dispatch(inbox.drain(), app) { ctx.send_viewport_cmd(egui::ViewportCommand::Close); @@ -77,11 +89,10 @@ pub fn poll(inbox: &Inbox, app: &mut CadApp, ctx: &egui::Context) { #[cfg(test)] mod tests { - use super::{dispatch, openable}; + use super::{Event, dispatch, openable}; use cadcraft_engine::Session; use cadcraft_ui_egui::closing::Choice; use cadcraft_ui_egui::{CadApp, Services}; - use fmv_macos_events::Event; use std::path::PathBuf; use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::{Duration, Instant}; diff --git a/apps/cadcraft/src/main.rs b/apps/cadcraft/src/main.rs index 50abb30d5..f78f0edfa 100644 --- a/apps/cadcraft/src/main.rs +++ b/apps/cadcraft/src/main.rs @@ -14,7 +14,7 @@ #![cfg_attr(all(target_os = "windows", not(debug_assertions)), windows_subsystem = "windows")] #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", test))] mod apple_events; mod control_server; mod desktop_theme;