Skip to main content

Open

Struct Open 

Source
pub struct Open<Msg> { /* private fields */ }
Expand description

Starts a program beside the application: the desktop’s own opener for an address or a path, or a program named outright. The screen stays where it is and nothing is drawn again.

The answer is optional. With Open::answer a message says whether the program was started; whether the desktop then really showed the thing is not something a terminal can know, so OpenOutcome::Opened says the opener was handed the target and no more.

use qframe::prelude::*;
use qframe::runtime::{Open, OpenOutcome};

enum Msg {
    SignIn(String),
    Opened(OpenOutcome),
}

fn update(msg: Msg) -> Command<Msg> {
    match msg {
        // The address goes to whatever browser this person uses; the screen never blinks.
        Msg::SignIn(address) => Command::open_with(Open::new(address).answer(Msg::Opened)),
        Msg::Opened(_) => Command::none(),
    }
}

Implementations§

Source§

impl<Msg: Send + 'static> Open<Msg>

Source

pub fn new(target: impl Into<OsString>) -> Self

Opens target — an address, a file or a folder — with the opener of this desktop: xdg-open, open on macOS, start on Windows.

Source

pub fn program(program: impl Into<OsString>) -> Self

Starts program itself instead of the desktop’s opener, the same way: quietly, beside the application, with nothing drawn again.

Source

pub fn arg(self, arg: impl Into<OsString>) -> Self

Adds one argument.

Source

pub fn args(self, args: impl IntoIterator<Item = impl Into<OsString>>) -> Self

Adds several arguments, in order.

Source

pub fn dir(self, dir: impl Into<PathBuf>) -> Self

Starts the program in dir instead of the application’s working directory.

Source

pub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self

Sets an environment variable for the program. The rest of the environment is inherited.

Source

pub fn answer( self, on_open: impl FnOnce(OpenOutcome) -> Msg + Send + 'static, ) -> Self

Delivers on_open(outcome) once the program has been started, or could not be.

Without it nothing is delivered: an application that has nothing to say about the opening asks for no message.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Open<Msg>

§

impl<Msg> !Sync for Open<Msg>

§

impl<Msg> !UnwindSafe for Open<Msg>

§

impl<Msg> Freeze for Open<Msg>
where Option<Box<dyn FnOnce(OpenOutcome) -> Msg + Send>>: Freeze,

§

impl<Msg> Send for Open<Msg>
where Option<Box<dyn FnOnce(OpenOutcome) -> Msg + Send>>: Send,

§

impl<Msg> Unpin for Open<Msg>
where Option<Box<dyn FnOnce(OpenOutcome) -> Msg + Send>>: Unpin,

§

impl<Msg> UnsafeUnpin for Open<Msg>
where Option<Box<dyn FnOnce(OpenOutcome) -> Msg + Send>>: UnsafeUnpin,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.