Skip to main content
KeyOS API Reference

gui_server_api/msg/
navigation.rs

1// SPDX-FileCopyrightText: 2024 Foundation Devices, Inc. <hello@foundation.xyz>
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4use server::WithAppId;
5use xous::AppId;
6
7use crate::{error::NavigationError, ModalStyle};
8
9#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
10#[response(NavigationResult)]
11pub struct ShowModal {
12    pub modal_style: ModalStyle,
13    #[rkyv(with = WithAppId)]
14    pub app_id: AppId,
15    pub args: Vec<u8>,
16}
17
18#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
19#[response(NavigationResult)]
20pub struct NavigateTo {
21    #[rkyv(with = WithAppId)]
22    pub app_id: AppId,
23    pub args: Vec<u8>,
24}
25
26/// Reason an app launch failed. Carries enough information for the SDK / UI to
27/// pick a useful follow-up (import a cert, enable developer mode, restart, …)
28/// instead of just printing a generic "launch failed" message.
29#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
30pub enum LaunchFailureReason {
31    /// App is signed by a key not in the allowed set.
32    SignatureRejected,
33    /// No matching allowed-publisher certificate is installed, so this third-party app cannot launch.
34    NoCertificate,
35    /// The matching publisher certificate's validity window has passed.
36    PublisherCertificateExpired,
37    /// The matching publisher certificate's validity window has not started yet.
38    PublisherCertificateNotYetActive,
39    /// Anything else: app-manager-internal failure, IPC failure, etc.
40    Internal,
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
44pub enum RunAppResponse {
45    Launched { pid: usize },
46    AlreadyRunning { pid: usize },
47    Locked,
48    NotReady,
49    AppIdNotFound,
50    LaunchFailed { reason: LaunchFailureReason },
51}
52
53#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
54#[response(RunAppResponse)]
55pub struct RunApp {
56    #[rkyv(with = WithAppId)]
57    pub app_id: AppId,
58}
59
60#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
61#[response(())]
62pub struct FinishResponse {
63    pub response: Vec<u8>,
64}
65
66impl FinishResponse {
67    pub fn as_slice(&self) -> &[u8] { &self.response }
68}
69
70pub type NavigationResult = Result<FinishResponse, NavigationError>;
71
72#[derive(Debug, server::Message)]
73pub struct NavigationCancel;
74
75#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
76#[response(Option<Vec<u8>>)]
77pub struct GetPendingNavRequest;
78
79#[derive(Debug, Copy, Clone, server::Message)]
80pub struct LoginSuccess;