morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::client::ApplicationHost Class Referencefinal

The application's side of the commands a document host does not answer itself (spec 6): sign-in and sign-out, which install a principal into the source, and the file commands, which read a picked file from disk and save a downloaded one, moving the bytes over the source's file side channel or inline. More...

#include <shell.hpp>

Inheritance diagram for morph::client::ApplicationHost:
morph::ui::InterpreterHost

Public Member Functions

 ApplicationHost (Source &source, SignInMapper signIn, std::filesystem::path downloads, std::function< void(SignedIn)> signedIn, std::function< void()> signedOut, std::function< void(std::string const &)> onProblem={})
 A host over source.
bool signIn (ui::Value const &reply) override
 Maps the reply and hands a principal to signedIn.
void signOut () override
 Calls signedOut.
bool uploadFor (ui::UploadRequest const &request, std::function< void(ui::Value)> progress, std::function< void(std::expected< ui::Value, std::string >)> done) override
 Reads the picked file from disk and sends it through the source's file store.
bool download (ui::Value const &file, std::string const &option, ui::Value const &name, std::function< void(std::expected< ui::Value, std::string >)> done) override
 Fetches a file by reference and saves it in the downloads directory. A preview is not supported.
bool readFile (ui::Value const &file, std::size_t maxBytes, std::function< void(std::expected< ui::InlineFile, std::string >)> done) override
 Reads a picked file whose bytes a document moves inline; its size is read first, and one over the cap is refused without reading it.
bool saveFile (ui::InlineFile const &file, std::string const &option, std::function< void(std::expected< ui::Value, std::string >)> done) override
 Saves a file a document holds the bytes of in the downloads directory. A preview is not supported.
void setNotifySink (std::function< bool(std::string const &, std::string const &)> sink)
 Sets what notify calls to show a transient message; empty falls through to the base class's false.
bool notify (std::string const &text, std::string const &role) override
 Calls the notify sink if one is set.
Public Member Functions inherited from morph::ui::InterpreterHost
 InterpreterHost (InterpreterHost const &)=delete
InterpreterHost & operator= (InterpreterHost const &)=delete
 InterpreterHost (InterpreterHost &&)=delete
InterpreterHost & operator= (InterpreterHost &&)=delete
virtual bool navigate (NavigateRequest const &request, std::function< void(Value)> onResult, std::function< void()> onCancel)
 Opens another screen.
virtual bool closeSelf (std::string const &screen, std::optional< Value > result)
 Ends the screen that ran return or close: self.
virtual bool hostCommand (std::string const &name, Value const &args)
 Runs a command the application registered (host/1).
virtual bool switchBackend (std::string const &name, std::function< void(std::expected< void, std::string >)> done)
 Switches to a backend the application's source lists (AppSource::switchBackend, spec 6 §9).
virtual void resetPrefs (std::string const &screen, std::string const &point)
 The document reset a customization point, or all of them; the host forgets the stored choice.
virtual void setLocale (std::string const &locale)
 Stores the active locale as a preference. The interpreter has already re-resolved every t.
virtual bool setAppValue (std::string const &name, Value const &value)
 Writes app.name with set (spec 6 §5).
virtual bool upload (Value const &file, std::function< void(Value)> progress, std::function< void(std::expected< Value, std::string >)> done)
 Sends a file through the server's file side channel (files/1).
virtual bool uploadFor (UploadRequest const &request, std::function< void(Value)> progress, std::function< void(std::expected< Value, std::string >)> done)
 Sends a file through the server's file side channel, knowing the mutation that will reference it. The interpreter calls this one; the default calls upload(file, …), so a host that overrides only that keeps working.
virtual bool download (Value const &file, std::string const &option, Value const &name, std::function< void(std::expected< Value, std::string >)> done)
 Fetches a file by reference to save it, or to a local temporary reference for a viewer.
virtual bool readFile (Value const &file, std::size_t maxBytes, std::function< void(std::expected< InlineFile, std::string >)> done)
 Reads a file's bytes for upload into bytes. A host reads the file's size first and refuses one over maxBytes without reading it; the interpreter refuses a reply over the cap as well.
virtual bool saveFile (InlineFile const &file, std::string const &option, std::function< void(std::expected< Value, std::string >)> done)
 Saves a file a document holds the bytes of, for download from bytes.
virtual void preferenceChanged (std::string const &screen, std::string const &point, Value const &value)
 The user chose at a customization point through a customize editor; the host stores the choice.
virtual void permissionsStale ()
 A call was refused with error kind denied: the permitted set is a snapshot, so the host asks the server again and calls Session::setPermitted.

Detailed Description

The application's side of the commands a document host does not answer itself (spec 6): sign-in and sign-out, which install a principal into the source, and the file commands, which read a picked file from disk and save a downloaded one, moving the bytes over the source's file side channel or inline.

A shell of an application's own builds one and passes it as DocumentScreenHostOptions::application; mountShell builds its own.

Definition at line 53 of file shell.hpp.

Constructor & Destructor Documentation

◆ ApplicationHost()

morph::client::ApplicationHost::ApplicationHost ( Source & source,
SignInMapper signIn,
std::filesystem::path downloads,
std::function< void(SignedIn)> signedIn,
std::function< void()> signedOut,
std::function< void(std::string const &)> onProblem = {} )

A host over source.

Parameters
sourceThe source sign-ins are installed into and files move through. Borrowed: it outlives the host.
signInMaps a sign-in reply to what is installed. Required.
downloadsWhere a download saves a file; the working directory when empty.
signedInCalled with what a sign-in installs, for the shell to install it and reload.
signedOutCalled on a signOut.
onProblemCalled with a refused sign-in's reason; may be empty.
Exceptions
std::invalid_argumentwhen signIn is empty.

Member Function Documentation

◆ signIn()

bool morph::client::ApplicationHost::signIn ( ui::Value const & reply)
overridevirtual

Maps the reply and hands a principal to signedIn.

Parameters
replyThe sign-in mutation's reply.
Returns
Whether it signed in: the mapper answered a principal.

Reimplemented from morph::ui::InterpreterHost.

◆ signOut()

void morph::client::ApplicationHost::signOut ( )
overridevirtual

Calls signedOut.

Reimplemented from morph::ui::InterpreterHost.

◆ uploadFor()

bool morph::client::ApplicationHost::uploadFor ( ui::UploadRequest const & request,
std::function< void(ui::Value)> progress,
std::function< void(std::expected< ui::Value, std::string >)> done )
override

Reads the picked file from disk and sends it through the source's file store.

Parameters
requestThe file and the mutation it is for.
progressCalled with the progress, as an exact fraction.
doneCalled with the file's reference, or the failure.
Returns
Whether it can: the source has a file side channel and the file is a path.

◆ download()

bool morph::client::ApplicationHost::download ( ui::Value const & file,
std::string const & option,
ui::Value const & name,
std::function< void(std::expected< ui::Value, std::string >)> done )
override

Fetches a file by reference and saves it in the downloads directory. A preview is not supported.

Parameters
fileThe reference.
optiondialog; preview answers not supported.
nameThe suggested name; null keeps the file's own.
doneCalled with the saved path, or the failure.
Returns
Whether it can.

◆ readFile()

bool morph::client::ApplicationHost::readFile ( ui::Value const & file,
std::size_t maxBytes,
std::function< void(std::expected< ui::InlineFile, std::string >)> done )
override

Reads a picked file whose bytes a document moves inline; its size is read first, and one over the cap is refused without reading it.

Parameters
fileThe picked path.
maxBytesThe session's inline cap.
doneCalled with the file, or the failure.
Returns
Whether it can: the file is a path.

◆ saveFile()

bool morph::client::ApplicationHost::saveFile ( ui::InlineFile const & file,
std::string const & option,
std::function< void(std::expected< ui::Value, std::string >)> done )
override

Saves a file a document holds the bytes of in the downloads directory. A preview is not supported.

Parameters
fileThe file.
optiondialog; preview answers not supported.
doneCalled with the saved path, or the failure.
Returns
Whether it can.

◆ setNotifySink()

void morph::client::ApplicationHost::setNotifySink ( std::function< bool(std::string const &, std::string const &)> sink)

Sets what notify calls to show a transient message; empty falls through to the base class's false.

Parameters
sinkGiven the text and the role; returns whether it showed it.

◆ notify()

bool morph::client::ApplicationHost::notify ( std::string const & text,
std::string const & role )
overridevirtual

Calls the notify sink if one is set.

Parameters
textThe message.
roleinfo, success, warning or error; empty for the default.
Returns
Whether the sink showed it; false when none is set.

Reimplemented from morph::ui::InterpreterHost.


The documentation for this class was generated from the following file: