Skip to main content

App

Struct App 

Source
pub struct App<U = ()> { /* private fields */ }
Expand description

A desktop application, named by a reverse domain name.

The identifier decides where App::data_dir is, and so where the application keeps its port and its lock. On Windows and Linux the web views keep their cookies and localStorage there too; on macOS, WKWebView keeps them in ~/Library/WebKit.

U is (), or Updates once App::updates has named where new versions are found, and then App::run hands the setup an Updater too.

Implementations§

Source§

impl App

Source

pub const fn new(id: &'static str) -> Self

An application named by id, such as dev.example.notes.

§Panics

Panics unless id is two or more parts joined by dots, each of ASCII letters, digits, and hyphens. In a const, that is a compile error.

Source

pub const fn updates(self, updates: Updates) -> App<Updates>

Finds the application’s new versions where updates says, with the Updater App::run hands the setup.

Source§

impl<U> App<U>

Source

pub const fn size(self, width: u32, height: u32) -> Self

Opens the window width by height logical pixels large.

§Panics

Panics when the size is narrower or shorter than min_size. In a const, that is a compile error.

ⓘ
use hypersig_desktop::App;

const APP: App = App::new("dev.example.notes").min_size(800, 600).size(640, 480);
Source

pub const fn min_size(self, width: u32, height: u32) -> Self

Keeps the window at least width by height logical pixels large.

§Panics

Panics when size is narrower or shorter than this. In a const, that is a compile error.

Source

pub const fn resizable(self, resizable: bool) -> Self

Whether the person can resize the window, which they can by default.

Source

pub const fn frame(self, frame: Frame) -> Self

Draws frame around each window, which is the system’s by default.

With Frame::None, the page draws the title bar: MovesWindow::moves_window marks the part the person drags the window by, and Window::close and Window::place answer its buttons. On macOS the window then has no close, minimize, and zoom buttons of its own, and on Linux no shadow where the window manager draws it with the border.

Source

pub const fn allow(self, device: Device) -> Self

Lets the pages use device through getUserMedia.

The web view grants a page only the devices named here, without asking the person, and refuses the others. The system still asks the person once whether the application may use the device. On macOS, the web view offers no navigator.mediaDevices unless the bundle’s Info.plist has NSMicrophoneUsageDescription for the microphone and NSCameraUsageDescription for the camera, which a run outside a bundle lacks.

WebView2, on Windows, keeps a grant in the web view’s data, so a later version that no longer names the device is still granted it until that data is removed.

Source

pub fn data_dir(&self) -> Result<PathBuf, Error>

The directory where this application keeps its files.

It is ~/Library/Application Support/<id> on macOS, %LOCALAPPDATA%\<id> on Windows, and $XDG_DATA_HOME/<id> or ~/.local/share/<id> elsewhere. App::run creates it before it polls the future that builds the router, so that future can open a file inside it.

§Errors

Fails with ErrorKind::NoDataDir when the environment variable the directory is found from is unset or not an absolute path.

Source§

impl App<Updates>

Source

pub fn run<S, F>(self, first_page: &Url, setup: S) -> Result<(), Error>
where S: FnOnce(Os, Updater) -> F, F: Future<Output: IntoRouter> + Send + 'static,

Serves the router setup builds and shows first_page in a window, as App::run does.

setup receives the Os and the Updater that finds new versions where App::updates says.

§Errors

Fails where App::run fails.

§Panics

Panics on macOS when it is not called on the main thread.

Source§

impl App

Source

pub fn run<S, F>(self, first_page: &Url, setup: S) -> Result<(), Error>
where S: FnOnce(Os) -> F, F: Future<Output: IntoRouter> + Send + 'static,

Serves the router setup builds and shows first_page in a window.

setup receives the Os the router’s handlers open windows and reach the operating system through, and returns the future that builds the router. That future runs on a Tokio runtime this method starts, while the first window and its web view are made, and the window is shown once its page has loaded.

When another copy of the application runs, this start opens no window: it hands its command line to that copy, which hears of it through Os::launches and brings a window forward, and returns Ok(()).

Closing the last window while no tray is shown, Quit in the menu or in the tray’s menu, or Ctrl-C in the terminal stops the server, which is given five seconds to finish the requests it is answering, and the method returns once it has stopped.

The windows and their event loop take the thread that calls this, which on macOS must be the main thread, so main is not #[tokio::main].

§Errors

Fails with ErrorKind::InRuntime when called inside a Tokio runtime, as from a #[tokio::main] function. Fails too when the application’s directory cannot be made, when another copy of the application runs and does not take this start’s command line, when the setup returns an error, and when a window, a web view, or the server fails.

§Panics

Panics on macOS when it is not called on the main thread.

Trait Implementations§

Source§

impl<U: Clone> Clone for App<U>

Source§

fn clone(&self) -> App<U>

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<U: Copy> Copy for App<U>

Source§

impl<U: Debug> Debug for App<U>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<U> Freeze for App<U>
where U: Freeze,

§

impl<U> RefUnwindSafe for App<U>
where U: RefUnwindSafe,

§

impl<U> Send for App<U>
where U: Send,

§

impl<U> Sync for App<U>
where U: Sync,

§

impl<U> Unpin for App<U>
where U: Unpin,

§

impl<U> UnsafeUnpin for App<U>
where U: UnsafeUnpin,

§

impl<U> UnwindSafe for App<U>
where U: UnwindSafe,

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