use std::time::Duration;
use super::Engine;
use crate::i18n;
use crate::runtime::App;
use crate::runtime::termination::{self, Step, Termination};
impl<A: App> Engine<A> {
pub(crate) fn terminate(&mut self, cause: Termination, now: Duration) {
if self.quit {
return;
}
self.clock = now;
match termination::receive(&mut self.ending, cause, now) {
Step::Ignore => {}
Step::End => self.quit = true,
Step::Ask(cause) => {
let message = {
let app = &self.app;
i18n::scope(self.env.i18n_arc(), || app.terminating(cause))
};
match message {
Some(message) => self.update(message),
None => self.quit = true,
}
}
}
}
pub(crate) fn ending_deadline(&self) -> Option<Duration> {
self.ending.map(|ending| ending.deadline)
}
pub(crate) fn end_when_due(&mut self, now: Duration) {
if self.ending_deadline().is_some_and(|deadline| deadline <= now) {
self.quit = true;
}
}
}