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
impl App
Source§impl<U> App<U>
impl<U> App<U>
Sourcepub const fn resizable(self, resizable: bool) -> Self
pub const fn resizable(self, resizable: bool) -> Self
Whether the person can resize the window, which they can by default.
Sourcepub const fn frame(self, frame: Frame) -> Self
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.
Sourcepub const fn allow(self, device: Device) -> Self
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.
Sourcepub fn data_dir(&self) -> Result<PathBuf, Error>
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>
impl App<Updates>
Source§impl App
impl App
Sourcepub fn run<S, F>(self, first_page: &Url, setup: S) -> Result<(), Error>
pub fn run<S, F>(self, first_page: &Url, setup: S) -> Result<(), Error>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.