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;