(&self, dump_types: &[DumpType])
| 593 | |
| 594 | #[tracing::instrument(level = "debug", skip(self))] |
| 595 | fn dump_store(&self, dump_types: &[DumpType]) { |
| 596 | let db = Database::open("moosync").build(); |
| 597 | |
| 598 | let data = dump_types |
| 599 | .iter() |
| 600 | .map(|d| match d { |
| 601 | DumpType::PlayerState => ( |
| 602 | "dump_player_state", |
| 603 | bitcode::encode(&self.data.player_details), |
| 604 | ), |
| 605 | DumpType::SongQueue => ( |
| 606 | "dump_song_queue", |
| 607 | bitcode::encode(&self.data.queue.song_queue), |
| 608 | ), |
| 609 | DumpType::CurrentIndex => ( |
| 610 | "dump_current_index", |
| 611 | bitcode::encode(&self.data.queue.current_index), |
| 612 | ), |
| 613 | DumpType::QueueData => ("dump_queue_data", bitcode::encode(&self.data.queue.data)), |
| 614 | }) |
| 615 | .collect_vec(); |
| 616 | |
| 617 | if let Ok(db) = db { |
| 618 | spawn_local(async move { |
| 619 | if let Ok(db) = db.await { |
| 620 | for dump_type in data { |
| 621 | if let Err(e) = |
| 622 | write_to_indexed_db(&db, "player_store", dump_type.0, dump_type.1).await |
| 623 | { |
| 624 | tracing::error!("Failed to dump store: {:?}", e); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | }); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | #[tracing::instrument(level = "debug", skip(db, signal))] |
| 633 | fn restore_store(signal: RwSignal<Option<PlayerStoreData>>, db: Database) { |
no test coverage detected