Skip to content

Commit

Permalink
pass SharedTimer, scope and re-order
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Mar 28, 2024
1 parent f9fdbd2 commit 972c392
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 22 additions & 19 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/timer_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl<T: Widget<MainState>> Widget<MainState> for WithMenu<T> {
});
} 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(),
Expand Down

0 comments on commit 972c392

Please sign in to comment.