startup.rs (2416B)
1 use crate::runtime::{AppRuntimeSnapshot, runtime_mode_label}; 2 3 #[derive(Clone, Debug, Eq, PartialEq)] 4 pub struct AppStartupEvent { 5 pub category: &'static str, 6 pub name: &'static str, 7 pub message: &'static str, 8 pub metadata: AppStartupEventMetadata, 9 } 10 11 #[derive(Clone, Debug, Eq, PartialEq)] 12 pub struct AppStartupEventMetadata { 13 pub home_screen: String, 14 pub core_package: String, 15 pub host_surface: String, 16 pub runtime_mode: String, 17 } 18 19 pub fn launch_startup_event(snapshot: &AppRuntimeSnapshot) -> AppStartupEvent { 20 AppStartupEvent { 21 category: "bootstrap", 22 name: "runtime.launch", 23 message: "app launch", 24 metadata: AppStartupEventMetadata { 25 home_screen: snapshot.title.clone(), 26 core_package: snapshot.core.package_name.clone(), 27 host_surface: snapshot.host.platform_name.clone(), 28 runtime_mode: runtime_mode_label(&snapshot.runtime_mode).to_owned(), 29 }, 30 } 31 } 32 33 #[cfg(test)] 34 mod tests { 35 use crate::{ 36 APP_PROJECTION_SOURCE, AppBuildIdentity, AppRuntimeCapture, AppRuntimeMode, 37 AppRuntimeSnapshot, 38 }; 39 40 use super::launch_startup_event; 41 42 #[test] 43 fn launch_startup_event_uses_runtime_snapshot_fields() { 44 let snapshot = AppRuntimeSnapshot::from_capture( 45 AppBuildIdentity { 46 package_name: "radroots_app".to_owned(), 47 package_version: "0.1.0".to_owned(), 48 build_profile: "debug".to_owned(), 49 target_triple: "aarch64-apple-darwin".to_owned(), 50 projection_source: APP_PROJECTION_SOURCE.to_owned(), 51 git_commit: None, 52 }, 53 AppRuntimeMode::Development, 54 AppRuntimeCapture { 55 host_locale: "en".to_owned(), 56 operating_system: "macos".to_owned(), 57 run_id: "run-development-123-pid456".to_owned(), 58 }, 59 ); 60 61 let event = launch_startup_event(&snapshot); 62 63 assert_eq!(event.category, "bootstrap"); 64 assert_eq!(event.name, "runtime.launch"); 65 assert_eq!(event.message, "app launch"); 66 assert_eq!(event.metadata.home_screen, "Radroots"); 67 assert_eq!(event.metadata.core_package, "radroots_app_core"); 68 assert_eq!(event.metadata.host_surface, "desktop"); 69 assert_eq!(event.metadata.runtime_mode, "development"); 70 } 71 }