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 std::fmt;
5
6use server::WithAppId;
7use xous::AppId;
8
9use crate::{error::NavigationError, ModalStyle};
10
11#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
12#[response(NavigationResult)]
13pub struct ShowModal {
14    pub modal_style: ModalStyle,
15    #[rkyv(with = WithAppId)]
16    pub app_id: AppId,
17    pub args: Vec<u8>,
18}
19
20#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
21#[response(NavigationResult)]
22pub struct NavigateTo {
23    #[rkyv(with = WithAppId)]
24    pub app_id: AppId,
25    pub args: Vec<u8>,
26}
27
28/// Reason an app launch failed. Carries enough information for the SDK / UI to
29/// pick a useful follow-up (import a cert, enable developer mode, restart, …)
30/// instead of just printing a generic "launch failed" message.
31#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
32pub enum LaunchFailureReason {
33    /// App is signed by a key not in the allowed set.
34    SignatureRejected,
35    /// No matching allowed-publisher certificate is installed, so this third-party app cannot launch.
36    NoCertificate,
37    /// The matching publisher certificate's validity window has passed.
38    PublisherCertificateExpired,
39    /// The matching publisher certificate's validity window has not started yet.
40    PublisherCertificateNotYetActive,
41    /// The app requires a newer KeyOS release.
42    KeyOsVersionTooOld,
43    /// Anything else: app-manager-internal failure, IPC failure, etc.
44    Internal,
45    /// The running KeyOS version could not be determined, so compatibility cannot be checked.
46    RunningKeyOsVersionUnavailable,
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
50pub enum RunAppResponse {
51    Launched { pid: usize },
52    AlreadyRunning { pid: usize },
53    Locked,
54    NotReady,
55    AppIdNotFound,
56    LaunchFailed { reason: LaunchFailureReason },
57}
58
59#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
60#[response(RunAppResponse)]
61pub struct RunApp {
62    #[rkyv(with = WithAppId)]
63    pub app_id: AppId,
64}
65
66#[derive(server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
67#[response(())]
68pub struct FinishResponse {
69    pub response: Vec<u8>,
70}
71
72// These are the serialized bytes of a navigation response, which for a QR scan is the
73// scanned payload that ScanQrResult redacts.
74impl fmt::Debug for FinishResponse {
75    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
76        formatter
77            .debug_struct("FinishResponse")
78            .field("response", &format_args!("<{} bytes>", self.response.len()))
79            .finish()
80    }
81}
82
83impl FinishResponse {
84    pub fn as_slice(&self) -> &[u8] { &self.response }
85}
86
87pub type NavigationResult = Result<FinishResponse, NavigationError>;
88
89#[derive(Debug, server::Message)]
90pub struct NavigationCancel;
91
92#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
93#[response(Option<Vec<u8>>)]
94pub struct GetPendingNavRequest;
95
96#[derive(Debug, Copy, Clone, server::Message)]
97pub struct LoginSuccess;