From 320fec364d843b1e2cce16e9a34d0dec4e4b7120 Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Sat, 16 Mar 2024 18:07:06 -0400 Subject: [PATCH] pass SharedTimer, scope and re-order --- src/config.rs | 41 ++++++++++++++++++++++------------------- src/timer_form.rs | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/config.rs b/src/config.rs index 9ba8b9a..f8e4b37 100644 --- a/src/config.rs +++ b/src/config.rs @@ -249,35 +249,38 @@ impl Config { pub fn open_splits( &mut self, - timer: &mut Timer, + shared_timer: &SharedTimer, layout_data: &mut LayoutData, auto_splitter: &livesplit_core::auto_splitting::Runtime, path: PathBuf, ) -> Result<()> { - let file = fs::read(&path).context("Failed reading the file.")?; - let run = composite::parse(&file, Some(&path)).context("Failed parsing the file.")?; - timer.set_run(run.run).ok().context( - "The splits can't be used with the timer because they don't contain a single segment.", - )?; - - self.splits.can_save = run.kind == TimerKind::LiveSplit; - self.splits.current = Some(path); - self.splits.add_to_history(timer.run()); - - self.save_config(); + { + let timer = &mut shared_timer.write().unwrap(); + let file = fs::read(&path).context("Failed reading the file.")?; + let run = composite::parse(&file, Some(&path)).context("Failed parsing the file.")?; + timer.set_run(run.run).ok().context( + "The splits can't be used with the timer because they don't contain a single segment.", + )?; + + self.splits.can_save = run.kind == TimerKind::LiveSplit; + self.splits.current = Some(path); + self.splits.add_to_history(timer.run()); - #[cfg(feature = "auto-splitting")] - self.maybe_replace_auto_splitter(auto_splitter, timer.clone().into_shared()); + self.save_config(); - if let Some(linked_layout) = timer.run().linked_layout() { - match linked_layout { - LinkedLayout::Default => self.new_layout(None, layout_data), - LinkedLayout::Path(path) => { - let _ = self.open_layout(None, layout_data, Path::new(path)); + if let Some(linked_layout) = timer.run().linked_layout() { + match linked_layout { + LinkedLayout::Default => self.new_layout(None, layout_data), + LinkedLayout::Path(path) => { + let _ = self.open_layout(None, layout_data, Path::new(path)); + } } } } + #[cfg(feature = "auto-splitting")] + self.maybe_replace_auto_splitter(auto_splitter, shared_timer.clone()); + Ok(()) } diff --git a/src/timer_form.rs b/src/timer_form.rs index c8cdc91..7a87da4 100644 --- a/src/timer_form.rs +++ b/src/timer_form.rs @@ -348,7 +348,7 @@ impl> Widget for WithMenu { }); } else if let Some(file_info) = command.get(CONTEXT_MENU_OPEN_SPLITS) { let result = data.config.borrow_mut().open_splits( - &mut data.timer.write().unwrap(), + &data.timer, &mut data.layout_data.borrow_mut(), &data.auto_splitter, file_info.path().to_path_buf(),