Skip to main content

Os

Struct Os 

Source
pub struct Os { /* private fields */ }
Expand description

The operating system’s windows and services, for the application’s handlers.

App::run gives it to the setup closure, which puts it in the router’s state, so a handler reaches it as state.os. A test gives the handlers testing::FakeOs::os instead, with the testing feature.

Implementations§

Source§

impl Os

Source

pub fn launches(&self) -> Launches

The launches of the application that start while it runs.

A start of the application while this copy runs hands its command line and working directory over and exits, and the copy that runs brings a window forward. On macOS a file or a link the person opens with the application, which the system hands the copy running rather than starting another, arrives here too, with each file as its path and each link as its text in Launch::args. Each Launches gets the launches handed over after it was made, so a setup that takes one before it returns the router misses none.

Source

pub async fn notify( &self, notification: Notification, ) -> Result<Notified, Error>

Shows notification among the system’s notifications.

The returned Notified tells whether the person clicked it. On macOS, the notification comes from the application installed with the identifier App::new names; a run outside such a bundle shows it under another application’s name.

§Errors

Fails with ErrorKind::Notification when the system does not show it, as on Linux without a notification server.

Source

pub async fn shortcut(&self, shortcut: Shortcut) -> Result<Presses, Error>

Registers shortcut for the rest of the run, so the application hears it while another application has focus.

Each call returns its own Presses of the presses and releases after it, and a shortcut asked for again is not registered twice. On Linux, the shortcut is grabbed from the X server, so a Wayland session delivers it only while an X11 window has focus, and none at all without Xwayland, where registering still returns Ok.

§Errors

Fails with ErrorKind::Shortcut when the system does not register it, as when another application holds it, and when the application is closing.

Source

pub async fn tray(&self, tray: Tray) -> Result<(), Error>

Shows tray in the system tray, in place of the tray shown before.

While a tray is shown, closing the last window leaves the application running, and the tray’s Quit item ends it.

§Errors

Fails with ErrorKind::Tray when the tray’s icon is not a PNG or the system has no tray, and when the application is closing.

Source

pub fn menus(&self, menus: impl IntoIterator<Item = Menu>) -> Result<(), Error>

Puts menus in the menu bar, in place of the menus put there before.

On macOS they go between the Edit and Window menus of the application’s menu bar, and on Linux in a bar at the top of every window, opened then or later. Windows shows no menu bar of this crate’s, since muda puts one in a window only through an unsafe call, which this crate forbids; there the menus are recorded and nothing is shown.

§Errors

Fails when the application is closing.

Source

pub fn badge(&self, count: u32) -> Result<(), Error>

Shows count on the application’s icon, or clears it at 0.

macOS writes the number on the Dock icon. Linux sets it on the launcher entry of <program>.desktop, the desktop file of the packages cargo-packager builds, which Ubuntu’s dock shows. Windows puts a red dot on each window’s taskbar button, since a button has no room for a number.

§Errors

Fails when the application is closing.

Source

pub fn windows(&self) -> Windows<'_>

The application’s windows.

Source

pub fn dialog(&self) -> Dialog

A file dialog, to be given a title and filters before it is shown.

Source

pub async fn tell(&self, message: Message)

Shows message in the system’s message box, with an OK button, and waits for the person to close it.

Source

pub async fn confirm(&self, message: Message) -> bool

Shows message with OK and Cancel buttons, and returns whether the person chose OK. Closing the box counts as Cancel.

Source

pub async fn ask(&self, message: Message) -> Answer

Shows message with Yes, No, and Cancel buttons, and returns the one the person chose. Closing the box counts as Cancel.

Source

pub fn autostart(&self) -> Autostart<'_>

Whether the system starts the application when the person logs in.

Source

pub fn clipboard(&self) -> Clipboard<'_>

The system clipboard.

Source

pub fn open_external(&self, url: &SafeUrl) -> Result<(), Error>

Opens url in the person’s web browser, or their mail program for a mailto: URL.

§Errors

Fails with ErrorKind::NotExternal when url names no scheme, as /notes does, since the system would open such a path as a file, and fails when the system cannot open it.

Trait Implementations§

Source§

impl Clone for Os

Source§

fn clone(&self) -> Os

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Os

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Os

§

impl RefUnwindSafe for Os

§

impl Send for Os

§

impl Sync for Os

§

impl Unpin for Os

§

impl UnsafeUnpin for Os

§

impl UnwindSafe for Os

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more