diff --git a/main/src/infrastructure/ui/app/app_instance.rs b/main/src/infrastructure/ui/app/app_instance.rs index 93e18e318..54a057d12 100644 --- a/main/src/infrastructure/ui/app/app_instance.rs +++ b/main/src/infrastructure/ui/app/app_instance.rs @@ -29,7 +29,10 @@ pub trait AppInstance: Debug { fn notify_app_is_ready(&mut self, callback: AppCallback); } -pub fn create_app_instance(session: WeakSession) -> impl AppInstance { +pub fn create_shared_app_instance(session: WeakSession) -> SharedAppInstance { + fn share(value: impl AppInstance + 'static) -> SharedAppInstance { + Rc::new(RefCell::new(value)) + } // I was experimenting with 2 different ways of embedding the app GUI into REAPER: // // - Parented mode: We create a new SWELL window on ReaLearn side (HWND on Windows, NSView on @@ -44,17 +47,15 @@ pub fn create_app_instance(session: WeakSession) -> impl AppInstance { // 3. We stop sending events when the app window is hidden, not wasting resources when the // app is not shown anyway. (However, with just a bit more effort, we could implement this // for standalone mode as well.) - #[cfg(target_os = "windows")] - { + if cfg!(target_os = "windows") { // On Windows, parented mode works wonderfully. It needs some tricks (see View // implementation) but it's worth it. That's why we use parented mode on Windows. let app_panel = AppPanel::new(session); - ParentedAppInstance { + let instance = ParentedAppInstance { panel: SharedView::new(app_panel), - } - } - #[cfg(target_os = "macos")] - { + }; + share(instance) + } else if cfg!(target_os = "macos") { // On macOS, parented mode is possible only by using Cocoa child windows (see app side // embedding docs). This means that the app doesn't really render itself in the NSView // provided by ReaLearn but places an NSWindow on top of the NSWindow provided by ReaLearn. @@ -64,10 +65,13 @@ pub fn create_app_instance(session: WeakSession) -> impl AppInstance { // This could be solved on app side by navigating up the child/parent window chain, but // it's not something I want to do now as long as we don't support docking anyway. // Therefore: Standalone mode on macOS! - StandaloneAppInstance { + let instance = StandaloneAppInstance { session, running_state: None, - } + }; + share(instance) + } else { + panic!("OS not supported yet"); } } diff --git a/main/src/infrastructure/ui/app/app_library.rs b/main/src/infrastructure/ui/app/app_library.rs index 6e4527dda..865cadb03 100644 --- a/main/src/infrastructure/ui/app/app_library.rs +++ b/main/src/infrastructure/ui/app/app_library.rs @@ -38,28 +38,25 @@ impl Drop for AppLibrary { impl AppLibrary { pub fn load(app_base_dir: PathBuf) -> Result { - let (main_library, dependencies) = { - #[cfg(target_os = "windows")] - { - ( - "playtime.dll", - [ - // Important: This must be the first. Because below plug-in libraries - // depend on it. - "flutter_windows.dll", - // The rest can have an arbitrary order. - "desktop_drop_plugin.dll", - "native_context_menu_plugin.dll", - "screen_retriever_plugin.dll", - "url_launcher_windows_plugin.dll", - "window_manager_plugin.dll", - "pointer_lock_plugin.dll", - ], - ) - } - #[cfg(target_os = "macos")] - { - ( + let (main_library, dependencies) = if cfg!(target_os = "windows") { + ( + "playtime.dll", + [ + // Important: This must be the first. Because below plug-in libraries + // depend on it. + "flutter_windows.dll", + // The rest can have an arbitrary order. + "desktop_drop_plugin.dll", + "native_context_menu_plugin.dll", + "screen_retriever_plugin.dll", + "url_launcher_windows_plugin.dll", + "window_manager_plugin.dll", + "pointer_lock_plugin.dll", + ] + .as_slice(), + ) + } else if cfg!(target_os = "macos") { + ( "Contents/MacOS/playtime", [ // Important: This must be the first. Because below plug-in libraries @@ -74,19 +71,18 @@ impl AppLibrary { "Contents/Frameworks/url_launcher_macos.framework/url_launcher_macos", "Contents/Frameworks/window_manager.framework/window_manager", "Contents/Frameworks/pointer_lock.framework/pointer_lock", - ], - ) - } - #[cfg(target_os = "linux")] - { - ( - "playtime.so", - ["flutter_linux.so", "url_launcher_linux_plugin.so"], + ].as_slice(), ) - } + } else if cfg!(target_os = "linux") { + ( + "playtime.so", + ["flutter_linux.so", "url_launcher_linux_plugin.so"].as_slice(), + ) + } else { + bail!("OS not supported"); }; let loaded_dependencies: Result> = dependencies - .into_iter() + .iter() .map(|dep| load_library(&app_base_dir.join(dep))) .collect(); let library = AppLibrary { diff --git a/main/src/infrastructure/ui/independent_panel_manager.rs b/main/src/infrastructure/ui/independent_panel_manager.rs index 7fe86971b..c98bd00b1 100644 --- a/main/src/infrastructure/ui/independent_panel_manager.rs +++ b/main/src/infrastructure/ui/independent_panel_manager.rs @@ -29,9 +29,7 @@ impl IndependentPanelManager { main_panel, mapping_panels: Default::default(), #[cfg(feature = "playtime")] - app_instance: std::rc::Rc::new(std::cell::RefCell::new( - crate::infrastructure::ui::create_app_instance(session.clone()), - )), + app_instance: crate::infrastructure::ui::create_shared_app_instance(session.clone()), message_panel: SharedView::new(SessionMessagePanel::new(session)), } }