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 trusted set.
32    SignatureRejected,
33    /// No matching trusted publisher certificate is installed, so this third-party app cannot be trusted.
34    NoTrustedPublisherCertificate,
35    /// Anything else: app-manager-internal failure, IPC failure, etc.
36    Internal,
37}
38
39#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
40pub enum RunAppResponse {
41    Launched { pid: usize },
42    AlreadyRunning { pid: usize },
43    Locked,
44    NotReady,
45    AppIdNotFound,
46    LaunchFailed { reason: LaunchFailureReason },
47}
48
49#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
50#[response(RunAppResponse)]
51pub struct RunApp {
52    #[rkyv(with = WithAppId)]
53    pub app_id: AppId,
54}
55
56#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
57#[response(())]
58pub struct FinishResponse {
59    pub response: Vec<u8>,
60}
61
62impl FinishResponse {
63    pub fn as_slice(&self) -> &[u8] { &self.response }
64}
65
66pub type NavigationResult = Result<FinishResponse, NavigationError>;
67
68#[derive(Debug, server::Message)]
69pub struct NavigationCancel;
70
71#[derive(Debug, server::Message, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
72#[response(Option<Vec<u8>>)]
73pub struct GetPendingNavRequest;
74
75#[derive(Debug, Copy, Clone, server::Message)]
76pub struct LoginSuccess;