implements PLN-0062 native shell lifecycle wiring
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
mod prometeu_hub;
|
||||
|
||||
pub use prometeu_hub::PrometeuHub;
|
||||
pub use prometeu_hub::{NativeShellApp, PrometeuHub, SystemProfileAction, SystemProfileUpdate};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[allow(clippy::module_inception)]
|
||||
mod prometeu_hub;
|
||||
|
||||
pub use prometeu_hub::PrometeuHub;
|
||||
pub use prometeu_hub::{NativeShellApp, PrometeuHub, SystemProfileAction, SystemProfileUpdate};
|
||||
|
||||
@@ -1,16 +1,49 @@
|
||||
use crate::windows::WindowOwner;
|
||||
use crate::{CrashReport, SystemOS};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::log::{LogLevel, LogSource};
|
||||
use prometeu_hal::primitives::Rect;
|
||||
use prometeu_hal::{HardwareBridge, InputSignals};
|
||||
use prometeu_vm::VirtualMachine;
|
||||
|
||||
/// PrometeuHub: Launcher and system UI environment.
|
||||
pub struct PrometeuHub;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum NativeShellApp {
|
||||
ShellA,
|
||||
ShellB,
|
||||
}
|
||||
|
||||
impl NativeShellApp {
|
||||
pub fn app_id(self) -> u32 {
|
||||
match self {
|
||||
Self::ShellA => 10_001,
|
||||
Self::ShellB => 10_002,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn title(self) -> &'static str {
|
||||
match self {
|
||||
Self::ShellA => "ShellA",
|
||||
Self::ShellB => "ShellB",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color(self) -> Color {
|
||||
match self {
|
||||
Self::ShellA => Color::GREEN,
|
||||
Self::ShellB => Color::BLUE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SystemProfileAction {
|
||||
LaunchNativeShell(NativeShellApp),
|
||||
CloseShell,
|
||||
}
|
||||
|
||||
pub struct SystemProfileUpdate {
|
||||
pub crash: Option<CrashReport>,
|
||||
pub action: Option<SystemProfileAction>,
|
||||
}
|
||||
|
||||
impl Default for PrometeuHub {
|
||||
@@ -28,43 +61,19 @@ impl PrometeuHub {
|
||||
// Initializes the Window System and lists apps
|
||||
}
|
||||
|
||||
pub fn gui_update(&mut self, os: &mut SystemOS, hw: &mut dyn HardwareBridge) {
|
||||
pub fn gui_update(
|
||||
&mut self,
|
||||
_os: &mut SystemOS,
|
||||
hw: &mut dyn HardwareBridge,
|
||||
) -> Option<SystemProfileAction> {
|
||||
hw.gfx_mut().clear(Color::BLACK);
|
||||
|
||||
let mut next_window = None;
|
||||
|
||||
if hw.pad().a().pressed {
|
||||
os.log(LogLevel::Debug, LogSource::Hub, 0, "window A opened".to_string());
|
||||
next_window = Some((
|
||||
"Green Window".to_string(),
|
||||
Rect { x: 0, y: 0, w: 160, h: 90 },
|
||||
Color::GREEN,
|
||||
));
|
||||
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellA))
|
||||
} else if hw.pad().b().pressed {
|
||||
os.log(LogLevel::Debug, LogSource::Hub, 0, "window B opened".to_string());
|
||||
next_window = Some((
|
||||
"Indigo Window".to_string(),
|
||||
Rect { x: 160, y: 0, w: 160, h: 90 },
|
||||
Color::INDIGO,
|
||||
));
|
||||
} else if hw.pad().x().pressed {
|
||||
os.log(LogLevel::Debug, LogSource::Hub, 0, "window X opened".to_string());
|
||||
next_window = Some((
|
||||
"Yellow Window".to_string(),
|
||||
Rect { x: 0, y: 90, w: 160, h: 90 },
|
||||
Color::YELLOW,
|
||||
));
|
||||
} else if hw.pad().y().pressed {
|
||||
os.log(LogLevel::Debug, LogSource::Hub, 0, "window Y opened".to_string());
|
||||
next_window =
|
||||
Some(("Red Window".to_string(), Rect { x: 160, y: 90, w: 160, h: 90 }, Color::RED));
|
||||
}
|
||||
|
||||
if let Some((title, rect, color)) = next_window {
|
||||
let mut window = os.windows();
|
||||
window.remove_all_windows();
|
||||
let id = window.add_window(title, WindowOwner::Hub, rect, color);
|
||||
window.set_focus(id);
|
||||
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellB))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,12 +97,11 @@ impl PrometeuHub {
|
||||
hw: &mut dyn HardwareBridge,
|
||||
) -> SystemProfileUpdate {
|
||||
let mut crash = None;
|
||||
let mut action = self.gui_update(os, hw);
|
||||
|
||||
self.gui_update(os, hw);
|
||||
|
||||
if let Some(focused_id) = os.windows().focused_window() {
|
||||
if os.windows().focused_window().is_some() {
|
||||
if hw.pad().start().down {
|
||||
os.windows().close_window(focused_id);
|
||||
action = Some(SystemProfileAction::CloseShell);
|
||||
} else {
|
||||
crash = os.vm().tick(vm, signals, hw);
|
||||
}
|
||||
@@ -102,6 +110,6 @@ impl PrometeuHub {
|
||||
self.render(os, hw);
|
||||
hw.gfx_mut().present();
|
||||
|
||||
SystemProfileUpdate { crash }
|
||||
SystemProfileUpdate { crash, action }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user