implements PLN-0061 shell running lifecycle integration
This commit is contained in:
@@ -175,10 +175,13 @@ mod tests {
|
||||
use prometeu_bytecode::model::{BytecodeModule, FunctionMeta, SyscallDecl};
|
||||
use prometeu_drivers::hardware::Hardware;
|
||||
use prometeu_hal::cartridge::{AppMode, AssetsPayloadSource};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::primitives::Rect;
|
||||
use prometeu_hal::syscalls::caps;
|
||||
use prometeu_system::CrashReport;
|
||||
use prometeu_system::process::ProcessState;
|
||||
use prometeu_system::task::TaskState;
|
||||
use prometeu_system::task::{TaskId, TaskState};
|
||||
use prometeu_system::windows::WindowOwner;
|
||||
|
||||
fn halting_program() -> Vec<u8> {
|
||||
let code = assemble("HALT").expect("assemble");
|
||||
@@ -262,6 +265,34 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_shell_running_firmware() -> (Firmware, Hardware, InputSignals, TaskId) {
|
||||
let mut firmware = Firmware::new(None);
|
||||
let mut hardware = Hardware::new();
|
||||
let signals = InputSignals::default();
|
||||
|
||||
firmware.load_cartridge(valid_cartridge(AppMode::Shell));
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
|
||||
let task_id = match &firmware.state {
|
||||
FirmwareState::ShellRunning(step) => step.task_id,
|
||||
other => panic!("expected ShellRunning state, got {:?}", other),
|
||||
};
|
||||
|
||||
(firmware, hardware, signals, task_id)
|
||||
}
|
||||
|
||||
fn focus_window(firmware: &mut Firmware, owner: WindowOwner) {
|
||||
let mut windows = firmware.os.windows();
|
||||
windows.remove_all_windows();
|
||||
let id = windows.add_window(
|
||||
"Test Window".to_string(),
|
||||
owner,
|
||||
Rect { x: 0, y: 0, w: 10, h: 10 },
|
||||
Color::WHITE,
|
||||
);
|
||||
windows.set_focus(id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_cartridge_transitions_to_app_crashes_when_vm_init_fails() {
|
||||
let mut firmware = Firmware::new(None);
|
||||
@@ -362,14 +393,79 @@ mod tests {
|
||||
|
||||
firmware.load_cartridge(valid_cartridge(AppMode::Shell));
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
let task_id = match &firmware.state {
|
||||
FirmwareState::ShellRunning(step) => step.task_id,
|
||||
other => panic!("expected ShellRunning state, got {:?}", other),
|
||||
};
|
||||
|
||||
let tick_index_before_system_update = firmware.os.vm().tick_index();
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
|
||||
assert!(matches!(firmware.state, FirmwareState::ShellRunning(_)));
|
||||
assert!(firmware.os.windows().focused_window_belongs_to_task(task_id));
|
||||
assert_eq!(firmware.os.vm().tick_index(), tick_index_before_system_update + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_running_closes_task_and_returns_hub_home_without_focused_window() {
|
||||
let (mut firmware, mut hardware, signals, task_id) = load_shell_running_firmware();
|
||||
|
||||
firmware.os.windows().remove_all_windows();
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
|
||||
assert!(matches!(firmware.state, FirmwareState::HubHome(_)));
|
||||
assert_eq!(firmware.os.lifecycle().task_state(task_id), Some(TaskState::Closed));
|
||||
assert_eq!(
|
||||
firmware.os.lifecycle().process_state_for_task(task_id),
|
||||
Ok(ProcessState::Stopped)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_running_closes_task_and_returns_hub_home_for_focused_hub_window() {
|
||||
let (mut firmware, mut hardware, signals, task_id) = load_shell_running_firmware();
|
||||
|
||||
focus_window(&mut firmware, WindowOwner::Hub);
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
|
||||
assert!(matches!(firmware.state, FirmwareState::HubHome(_)));
|
||||
assert_eq!(firmware.os.lifecycle().task_state(task_id), Some(TaskState::Closed));
|
||||
assert_eq!(
|
||||
firmware.os.lifecycle().process_state_for_task(task_id),
|
||||
Ok(ProcessState::Stopped)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_running_closes_task_and_returns_hub_home_for_focused_overlay_window() {
|
||||
let (mut firmware, mut hardware, signals, task_id) = load_shell_running_firmware();
|
||||
|
||||
focus_window(&mut firmware, WindowOwner::Overlay);
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
|
||||
assert!(matches!(firmware.state, FirmwareState::HubHome(_)));
|
||||
assert_eq!(firmware.os.lifecycle().task_state(task_id), Some(TaskState::Closed));
|
||||
assert_eq!(
|
||||
firmware.os.lifecycle().process_state_for_task(task_id),
|
||||
Ok(ProcessState::Stopped)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_running_closes_task_and_returns_hub_home_for_other_task_window() {
|
||||
let (mut firmware, mut hardware, signals, task_id) = load_shell_running_firmware();
|
||||
|
||||
focus_window(&mut firmware, WindowOwner::Task(TaskId(task_id.0 + 1)));
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
|
||||
assert!(matches!(firmware.state, FirmwareState::HubHome(_)));
|
||||
assert_eq!(firmware.os.lifecycle().task_state(task_id), Some(TaskState::Closed));
|
||||
assert_eq!(
|
||||
firmware.os.lifecycle().process_state_for_task(task_id),
|
||||
Ok(ProcessState::Stopped)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_cartridge_routes_game_apps_to_game_running() {
|
||||
let mut firmware = Firmware::new(None);
|
||||
@@ -380,5 +476,6 @@ mod tests {
|
||||
firmware.tick(&signals, &mut hardware);
|
||||
|
||||
assert!(matches!(firmware.state, FirmwareState::GameRunning(_)));
|
||||
assert_eq!(firmware.os.windows().window_count(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,10 +66,13 @@ impl ShellRunningStep {
|
||||
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
||||
}
|
||||
|
||||
if !outcome.focused_window_active {
|
||||
if !ctx.os.windows().focused_window_belongs_to_task(self.task_id) {
|
||||
ctx.os.info(
|
||||
LogSource::Hub,
|
||||
format!("Closing shell task {:?}: no focused window active", self.task_id),
|
||||
format!(
|
||||
"Closing shell task {:?}: focused window does not belong to task",
|
||||
self.task_id,
|
||||
),
|
||||
);
|
||||
if let Err(error) = ctx.os.lifecycle().close_task(self.task_id) {
|
||||
ctx.os.error(
|
||||
|
||||
@@ -11,7 +11,6 @@ pub struct PrometeuHub;
|
||||
|
||||
pub struct SystemProfileUpdate {
|
||||
pub crash: Option<CrashReport>,
|
||||
pub focused_window_active: bool,
|
||||
}
|
||||
|
||||
impl Default for PrometeuHub {
|
||||
@@ -103,9 +102,6 @@ impl PrometeuHub {
|
||||
self.render(os, hw);
|
||||
hw.gfx_mut().present();
|
||||
|
||||
SystemProfileUpdate {
|
||||
crash,
|
||||
focused_window_active: os.windows().focused_window().is_some(),
|
||||
}
|
||||
SystemProfileUpdate { crash }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user