Refactor next_mode()
The return type better reflects the next state
This commit is contained in:
parent
253385c2a7
commit
9d6fa954b2
1 changed files with 20 additions and 13 deletions
|
|
@ -97,7 +97,7 @@ impl App {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_mode(&mut self) -> Option<Mode> {
|
pub fn next_mode(&mut self) -> (Option<Mode>, Option<Mode>) {
|
||||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
let new_mode = match (self.prev_mode, self.cur_mode) {
|
||||||
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
||||||
(_, Mode::ScanDisks) => Mode::SelectDisks,
|
(_, Mode::ScanDisks) => Mode::SelectDisks,
|
||||||
|
|
@ -119,19 +119,22 @@ impl App {
|
||||||
(_, Mode::Confirm) => panic!("This shouldn't happen."),
|
(_, Mode::Confirm) => panic!("This shouldn't happen."),
|
||||||
};
|
};
|
||||||
|
|
||||||
if new_mode == self.cur_mode {
|
let prev_mode = {
|
||||||
None
|
|
||||||
} else {
|
|
||||||
match self.cur_mode {
|
match self.cur_mode {
|
||||||
// Update prev_mode if appropriate
|
Mode::Confirm => Some(self.prev_mode),
|
||||||
Mode::Confirm => {}
|
|
||||||
Mode::PreClone | Mode::Clone | Mode::PostClone | Mode::Done => {
|
Mode::PreClone | Mode::Clone | Mode::PostClone | Mode::Done => {
|
||||||
// Override since we're past the point of no return
|
// Override since we're past the point of no return
|
||||||
self.prev_mode = self.cur_mode;
|
Some(self.cur_mode)
|
||||||
}
|
}
|
||||||
_ => self.prev_mode = self.cur_mode,
|
_ => Some(self.cur_mode),
|
||||||
}
|
}
|
||||||
Some(new_mode)
|
};
|
||||||
|
|
||||||
|
if new_mode == self.cur_mode {
|
||||||
|
// No mode change needed
|
||||||
|
(None, None)
|
||||||
|
} else {
|
||||||
|
(prev_mode, Some(new_mode))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -367,12 +370,16 @@ impl App {
|
||||||
};
|
};
|
||||||
self.action_tx.send(Action::SetMode(new_mode))?;
|
self.action_tx.send(Action::SetMode(new_mode))?;
|
||||||
}
|
}
|
||||||
Action::NextScreen => {
|
Action::NextScreen => match self.next_mode() {
|
||||||
if let Some(mode) = self.next_mode() {
|
(None, None) => {}
|
||||||
|
(Some(prev), Some(next)) => {
|
||||||
|
self.prev_mode = prev;
|
||||||
|
self.cur_mode = next;
|
||||||
self.action_tx.send(Action::DismissPopup)?;
|
self.action_tx.send(Action::DismissPopup)?;
|
||||||
self.action_tx.send(Action::SetMode(mode))?;
|
self.action_tx.send(Action::SetMode(next))?;
|
||||||
}
|
}
|
||||||
}
|
_ => panic!("Failed to determine next mode"),
|
||||||
|
},
|
||||||
Action::ScanDisks => self.action_tx.send(Action::SetMode(Mode::ScanDisks))?,
|
Action::ScanDisks => self.action_tx.send(Action::SetMode(Mode::ScanDisks))?,
|
||||||
Action::Select(one, two) => {
|
Action::Select(one, two) => {
|
||||||
match self.cur_mode {
|
match self.cur_mode {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue