Skip to main content

tray_wrapper/
server_generator.rs

1use std::{pin::Pin, sync::Arc};
2
3/// This is the core of the library, in short you need to supply a function that
4/// when called returns async futures that can be polled.
5pub type ServerGenerator = Arc<dyn Fn() -> ServerGeneratorResult + Send + Sync>;
6
7/// This is the return type for the async tasks, the future's return type is to indicate
8/// to the wrapper if it should keep being executed.
9pub type ServerGeneratorResult = Pin<Box<dyn Future<Output = ContinueRunning> + Send>>;
10
11/// The various options on if it should continue to execute the server again.
12pub enum ContinueRunning {
13    /// The server generator should be called again
14    Continue,
15    /// There is no point in trying to execute again. The wrapper terminates
16    /// the event loop and the process exits.
17    Exit,
18    /// There is no point in trying to execute again and we have a reason.
19    ///
20    /// Unlike [`Exit`], this does *not* terminate the event loop. The error is
21    /// surfaced on the tray icon (an "E" overlay) and in the menu's status item,
22    /// and the app stays running until the user clicks Quit. This is deliberate:
23    /// a tray app that vanishes silently on failure leaves the user with no
24    /// signal as to what happened.
25    ///
26    /// [`Exit`]: ContinueRunning::Exit
27    ExitWithError(String),
28}