@@ -146,6 +146,13 @@ const MIN_ZOOM_FACTOR: f32 = 0.2;
146
146
#[ cfg( not( target_arch = "wasm32" ) ) ]
147
147
const MAX_ZOOM_FACTOR : f32 = 5.0 ;
148
148
149
+ #[ cfg( target_arch = "wasm32" ) ]
150
+ struct PendingFilePromise {
151
+ recommended_application_id : Option < ApplicationId > ,
152
+ recommended_recording_id : Option < re_log_types:: StoreId > ,
153
+ promise : poll_promise:: Promise < Vec < re_data_source:: FileContents > > ,
154
+ }
155
+
149
156
/// The Rerun Viewer as an [`eframe`] application.
150
157
pub struct App {
151
158
build_info : re_build_info:: BuildInfo ,
@@ -169,7 +176,7 @@ pub struct App {
169
176
rx : ReceiveSet < LogMsg > ,
170
177
171
178
#[ cfg( target_arch = "wasm32" ) ]
172
- open_files_promise : Option < poll_promise :: Promise < Vec < re_data_source :: FileContents > > > ,
179
+ open_files_promise : Option < PendingFilePromise > ,
173
180
174
181
/// What is serialized
175
182
pub ( crate ) state : AppState ,
@@ -564,6 +571,18 @@ impl App {
564
571
store_context : Option < & StoreContext < ' _ > > ,
565
572
cmd : UICommand ,
566
573
) {
574
+ let active_application_id = store_context
575
+ . and_then ( |ctx| {
576
+ ctx. hub
577
+ . active_app ( )
578
+ // Don't redirect data to the welcome screen.
579
+ . filter ( |& app_id| app_id != & StoreHub :: welcome_screen_app_id ( ) )
580
+ } )
581
+ . cloned ( ) ;
582
+ let active_recording_id = store_context
583
+ . and_then ( |ctx| ctx. hub . active_recording_id ( ) )
584
+ . cloned ( ) ;
585
+
567
586
match cmd {
568
587
UICommand :: SaveRecording => {
569
588
if let Err ( err) = save_recording ( self , store_context, None ) {
@@ -602,12 +621,57 @@ impl App {
602
621
#[ cfg( target_arch = "wasm32" ) ]
603
622
UICommand :: Open => {
604
623
let egui_ctx = egui_ctx. clone ( ) ;
605
- self . open_files_promise = Some ( poll_promise:: Promise :: spawn_local ( async move {
624
+
625
+ // Open: we want to try and load into a new dedicated recording.
626
+ let recommended_application_id = None ;
627
+ let recommended_recording_id = None ;
628
+ let promise = poll_promise:: Promise :: spawn_local ( async move {
606
629
let file = async_open_rrd_dialog ( ) . await ;
607
630
egui_ctx. request_repaint ( ) ; // Wake ui thread
608
631
file
609
- } ) ) ;
632
+ } ) ;
633
+
634
+ self . open_files_promise = Some ( PendingFilePromise {
635
+ recommended_application_id,
636
+ recommended_recording_id,
637
+ promise,
638
+ } ) ;
610
639
}
640
+
641
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
642
+ UICommand :: Import => {
643
+ for file_path in open_file_dialog_native ( ) {
644
+ self . command_sender
645
+ . send_system ( SystemCommand :: LoadDataSource ( DataSource :: FilePath (
646
+ FileSource :: FileDialog {
647
+ recommended_application_id : active_application_id. clone ( ) ,
648
+ recommended_recording_id : active_recording_id. clone ( ) ,
649
+ } ,
650
+ file_path,
651
+ ) ) ) ;
652
+ }
653
+ }
654
+ #[ cfg( target_arch = "wasm32" ) ]
655
+ UICommand :: Import => {
656
+ let egui_ctx = egui_ctx. clone ( ) ;
657
+
658
+ // Import: we want to try and load into the current recording.
659
+ let recommended_application_id = active_application_id;
660
+ let recommended_recording_id = active_recording_id;
661
+
662
+ let promise = poll_promise:: Promise :: spawn_local ( async move {
663
+ let file = async_open_rrd_dialog ( ) . await ;
664
+ egui_ctx. request_repaint ( ) ; // Wake ui thread
665
+ file
666
+ } ) ;
667
+
668
+ self . open_files_promise = Some ( PendingFilePromise {
669
+ recommended_application_id,
670
+ recommended_recording_id,
671
+ promise,
672
+ } ) ;
673
+ }
674
+
611
675
UICommand :: CloseCurrentRecording => {
612
676
let cur_rec = store_context. map ( |ctx| ctx. recording . store_id ( ) ) ;
613
677
if let Some ( cur_rec) = cur_rec {
@@ -1586,14 +1650,19 @@ impl eframe::App for App {
1586
1650
}
1587
1651
1588
1652
#[ cfg( target_arch = "wasm32" ) ]
1589
- if let Some ( promise) = & self . open_files_promise {
1653
+ if let Some ( PendingFilePromise {
1654
+ recommended_application_id,
1655
+ recommended_recording_id,
1656
+ promise,
1657
+ } ) = & self . open_files_promise
1658
+ {
1590
1659
if let Some ( files) = promise. ready ( ) {
1591
1660
for file in files {
1592
1661
self . command_sender
1593
1662
. send_system ( SystemCommand :: LoadDataSource ( DataSource :: FileContents (
1594
1663
FileSource :: FileDialog {
1595
- recommended_application_id : None ,
1596
- recommended_recording_id : None ,
1664
+ recommended_application_id : recommended_application_id . clone ( ) ,
1665
+ recommended_recording_id : recommended_recording_id . clone ( ) ,
1597
1666
} ,
1598
1667
file. clone ( ) ,
1599
1668
) ) ) ;
0 commit comments