Skip to content

Commit

Permalink
Add custom UI status
Browse files Browse the repository at this point in the history
This patch adds a custom UI status that can be defined and handled by
the runner.  Applications that want to use this status should have a
configuration option that lets the runner provide a value to use for
that status.  The runner is responsible for correctly handling this
status value.

Fixes #5
  • Loading branch information
robin-nitrokey authored and sosthene-nitrokey committed Jun 20, 2023
1 parent 51e6850 commit f3c95ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ generate_enums! {
Reboot: 42
Uptime: 43
Wink: 44
SetCustomStatus: 45

//////////////
// Counters //
Expand Down Expand Up @@ -325,6 +326,9 @@ pub mod request {
Wink:
- duration: core::time::Duration

SetCustomStatus:
- status: u8

CreateCounter:
- location: Location

Expand Down Expand Up @@ -481,6 +485,8 @@ pub mod reply {

Wink:

SetCustomStatus:

CreateCounter:
- id: CounterId

Expand Down
4 changes: 4 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,10 @@ pub trait UiClient: PollClient {
fn wink(&mut self, duration: core::time::Duration) -> ClientResult<'_, reply::Wink, Self> {
self.request(request::Wink { duration })
}

fn set_custom_status(&mut self, status: u8) -> ClientResult<'_, reply::SetCustomStatus, Self> {
self.request(request::SetCustomStatus { status })
}
}

/// Builder for [`ClientImplementation`][].
Expand Down
6 changes: 6 additions & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub use crate::store::{
filestore::{ClientFilestore, Filestore, ReadDirFilesState, ReadDirState},
keystore::{ClientKeystore, Keystore},
};
use crate::types::ui::Status;
use crate::types::*;
use crate::Bytes;
use crate::{api::*, interrupt::InterruptFlag};
Expand Down Expand Up @@ -584,6 +585,11 @@ impl<P: Platform> ServiceResources<P> {
Ok(Reply::Wink(reply::Wink {}))
}

Request::SetCustomStatus(request) => {
self.platform.user_interface().set_status(Status::Custom(request.status));
Ok(Reply::SetCustomStatus(reply::SetCustomStatus {}))
}

Request::CreateCounter(request) => {
counterstore.create(request.location)
.map(|id| Reply::CreateCounter(reply::CreateCounter { id } ))
Expand Down
1 change: 1 addition & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub mod ui {
WaitingForUserPresence,
Processing,
Error,
Custom(u8),
}
}

Expand Down

0 comments on commit f3c95ab

Please sign in to comment.