#[non_exhaustive]pub struct System {Show 14 fields
pub access: Arc<Access>,
pub data_dir: Option<PathBuf>,
pub asset_base: Option<AssetBase>,
pub paths: TrustedPaths,
pub quotas: Quotas,
pub locals: Locals,
pub exit: Option<Rc<dyn Fn(i32)>>,
pub websocket: Option<Arc<dyn WebSocketTransport>>,
pub filesystem: Option<Arc<dyn FileSystem>>,
pub os: Os,
pub clipboard_images: Option<bool>,
pub refuse_connections: Option<RefuseConnections>,
pub updater: Option<Arc<dyn UpdaterHost>>,
pub base_url: Option<Arc<str>>,
/* private fields */
}Expand description
The VM a call comes from, as the host configured it: what the app may
do and where its files are. A parameter sys: System of a module
function or a class’s member is not one JS passes: the call fills it
in (an async one when it is made, as its arguments are converted). A
host that configured nothing gives one that grants nothing.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.access: Arc<Access>The capabilities: the app’s declaration and the host’s grant.
data_dir: Option<PathBuf>The app’s own data directory (${dataDir}), when the host has one.
asset_base: Option<AssetBase>Where the app’s bundled (asset:/…) files are on disk, when the
host has them in directories it can name: a packaged desktop app’s
own, beside the running runner. process.run of an asset:/…
program resolves it through this; None on the web (the dev server
serves the files over HTTP) and on iOS and Android, where a bundled
file cannot run.
paths: TrustedPathsThe host’s anchors of ${pluginDir} and ${homeDir}.
quotas: QuotasThe VM’s counts of limited resources.
locals: LocalsThe VM’s own state of the runtime’s modules (process’s children).
exit: Option<Rc<dyn Fn(i32)>>What the host does when the app asks to exit (process.exit);
None: it installed nothing.
websocket: Option<Arc<dyn WebSocketTransport>>The host WebSocket transport, when the platform supplies one.
filesystem: Option<Arc<dyn FileSystem>>The host virtual filesystem, confined to this app’s data directory.
os: OsThe operating system the app runs on, as the host says.
clipboard_images: Option<bool>Whether the platform puts images on the clipboard and reads them
back; None: as NSH’s own backend on Self::os
(crate::platform::Environment::clipboard_images).
refuse_connections: Option<RefuseConnections>Refuses the app’s connections (net sockets and WebSockets, both
APIs) before they reach the network: a test’s, which reaches it
only when the test asks (nsh test’s network: "live"). None:
they connect. fetch goes through the host’s network instead.
updater: Option<Arc<dyn UpdaterHost>>What nsh/updater runs on; None: the app does not update.
base_url: Option<Arc<str>>What // media sources resolve against, the page’s URL on the web
(Access::media_url); None: such a source names no URL.
Implementations§
Source§impl System
impl System
Sourcepub fn new(
access: Arc<Access>,
data_dir: Option<PathBuf>,
paths: TrustedPaths,
quotas: Quotas,
) -> Self
pub fn new( access: Arc<Access>, data_dir: Option<PathBuf>, paths: TrustedPaths, quotas: Quotas, ) -> Self
The VM’s capabilities and directories.
Sourcepub fn check_connection(&self, target: &str) -> Result<(), JsError>
pub fn check_connection(&self, target: &str) -> Result<(), JsError>
Whether the app may connect to target (a WebSocket’s URL, a
socket’s host:port) as far as the host is concerned: the error
System::refuse_connections gives, when the host set one. The
app’s capabilities are checked apart.
Sourcepub fn readable_file(&self, path: &str) -> Result<PathBuf, JsError>
pub fn readable_file(&self, path: &str) -> Result<PathBuf, JsError>
The real path of the local file path names (absolute, or a
placeholder path such as ${dataDir}/report.pdf), checked as
fs/promises reads it: within the roots capabilities.fs.read
grants (the app’s declaration and the host’s grant), or a file the
user pasted or dropped, its links resolved and still inside
the root that grants it. For a module that hands a file the app
names to the system or to another app (a share sheet, a print job,
an upload), so the file is checked as the app’s own reads are.
Rejects as fs/promises would: ERR_ACCESS_DENIED for a path no
grant covers or a link leading out of its root, ENOENT for one that
does not exist, EISDIR for a folder (EINVAL for a FIFO or device),
ERR_FEATURE_UNAVAILABLE_ON_PLATFORM where the app’s
files are not native files (the web) or the platform has no native
filesystem.
Sourcepub fn with_refuse_connections(self, refuse: Option<RefuseConnections>) -> Self
pub fn with_refuse_connections(self, refuse: Option<RefuseConnections>) -> Self
Refuses the app’s connections with what refuse gives
(System::refuse_connections).
Sourcepub fn with_websocket(
self,
websocket: Option<Arc<dyn WebSocketTransport>>,
) -> Self
pub fn with_websocket( self, websocket: Option<Arc<dyn WebSocketTransport>>, ) -> Self
Uses the host WebSocket transport instead of the native stack.
Sourcepub fn with_asset_base(self, base: Option<AssetBase>) -> Self
pub fn with_asset_base(self, base: Option<AssetBase>) -> Self
Sets where the app’s bundled (asset:/…) files are on disk, when
the host has them in directories it can name (process.run of an
asset:/… program resolves through this).
Sourcepub fn with_updater(self, updater: Option<Arc<dyn UpdaterHost>>) -> Self
pub fn with_updater(self, updater: Option<Arc<dyn UpdaterHost>>) -> Self
Uses the host virtual filesystem.
Sets what nsh/updater runs on.
Sourcepub fn with_base_url(self, base_url: Option<Arc<str>>) -> Self
pub fn with_base_url(self, base_url: Option<Arc<str>>) -> Self
What // media sources resolve against (System::base_url).
Sourcepub fn with_filesystem(self, filesystem: Option<Arc<dyn FileSystem>>) -> Self
pub fn with_filesystem(self, filesystem: Option<Arc<dyn FileSystem>>) -> Self
The host virtual filesystem the VM’s storage runs on.
Sourcepub fn with_clipboard_images(self, clipboard_images: Option<bool>) -> Self
pub fn with_clipboard_images(self, clipboard_images: Option<bool>) -> Self
Whether the platform puts images on the clipboard; None: as NSH’s
own backend on the OS
(crate::platform::Environment::clipboard_images).
Sourcepub fn with_locals(self, locals: Locals) -> Self
pub fn with_locals(self, locals: Locals) -> Self
The VM’s state of the runtime modules, kept with it.