All checks were successful
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
90 lines
3.0 KiB
Rust
90 lines
3.0 KiB
Rust
use crate::firmware::firmware_state::{AppCrashesStep, FirmwareState, HubHomeStep};
|
|
use crate::firmware::prometeu_context::PrometeuContext;
|
|
use prometeu_hal::log::LogSource;
|
|
use prometeu_system::CrashReport;
|
|
use prometeu_system::task::{TaskId, TaskState};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct ShellRunningStep {
|
|
pub task_id: TaskId,
|
|
}
|
|
|
|
impl ShellRunningStep {
|
|
pub fn new(task_id: TaskId) -> Self {
|
|
Self { task_id }
|
|
}
|
|
|
|
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
|
ctx.os.info(LogSource::Hub, "Entering ShellRunning".to_string());
|
|
}
|
|
|
|
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
|
let Some(task_state) = ctx.os.lifecycle().task_state(self.task_id) else {
|
|
let report = CrashReport::VmPanic {
|
|
message: format!("ShellRunningStep has no task for {:?}", self.task_id),
|
|
pc: None,
|
|
};
|
|
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
};
|
|
|
|
match task_state {
|
|
TaskState::Foreground => {
|
|
// Continue below.
|
|
}
|
|
|
|
TaskState::Closed => {
|
|
return Some(FirmwareState::HubHome(HubHomeStep));
|
|
}
|
|
|
|
TaskState::Crashed => {
|
|
let report = CrashReport::VmPanic {
|
|
message: format!("Shell task {:?} is already crashed", self.task_id),
|
|
pc: None,
|
|
};
|
|
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
}
|
|
|
|
TaskState::Suspended | TaskState::Background => {
|
|
let report = CrashReport::VmPanic {
|
|
message: format!(
|
|
"ShellRunningStep expected foreground task {:?}, got {:?}",
|
|
self.task_id, task_state,
|
|
),
|
|
pc: None,
|
|
};
|
|
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
}
|
|
}
|
|
|
|
let outcome = ctx.hub.update_shell_profile(ctx.os, ctx.vm, ctx.signals, ctx.hw);
|
|
|
|
if let Some(report) = outcome.crash {
|
|
let _ = ctx.os.lifecycle().crash_task(self.task_id, Some(&report));
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
}
|
|
|
|
if !outcome.focused_window_active {
|
|
ctx.os.info(
|
|
LogSource::Hub,
|
|
format!("Closing shell task {:?}: no focused window active", self.task_id),
|
|
);
|
|
if let Err(error) = ctx.os.lifecycle().close_task(self.task_id) {
|
|
ctx.os.error(
|
|
LogSource::Hub,
|
|
format!("Failed to close shell task {:?}: {:?}", self.task_id, error),
|
|
);
|
|
}
|
|
return Some(FirmwareState::HubHome(HubHomeStep));
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
pub fn on_exit(&mut self, ctx: &mut PrometeuContext) {
|
|
ctx.os.info(LogSource::Hub, "Exiting ShellRunning".to_string());
|
|
}
|
|
}
|