Skip to main content

Crate rahti_native

Crate rahti_native 

Source
Expand description

Running a Rahti application inside a native package.

A native Rahti package is the application it already was. The Rust backend is compiled for the target platform and runs inside the installed program; the generated Axum router answers on a loopback socket; and the operating system’s WebView loads the same server-rendered HTML, the same PulsePoint bundle, the same RPCs and the same WebSockets it would over the network.

This is not a compiler from HTML to native widgets. Nothing here translates markup. What the user sees is a WebView, and calling its contents native controls would be untrue.

§What this crate is, and is not

It is the platform-neutral half: where a packaged application’s files live, how its server binds, how its session key survives a restart, and which native commands its JavaScript may call. It has no Tauri dependency, so it compiles and tests in an ordinary cargo test --workspace run.

The Tauri half is generated into the application’s own native/ directory by cargo rahti native init. That shell owns the identifier, the icons, the permissions and the window — application decisions, in application files.

It is also not the application’s startup. Connecting a database, applying migrations and installing an auth policy are decisions a project makes in its own src/lib.rs; this crate starts a server, it does not start your server.

§The shape of a launch

// 1. Where this installation keeps its files.
let paths = AppPaths::resolve("com.example.myapp")?;
paths.prepare()?;

// 2. Write the embedded assets into internal storage, and put the paths
//    in the environment the application is about to read.
let assets = [rahti_native::EmbeddedAsset { path: "js/main.js", bytes: b"" }];
rahti_native::stage_embedded_assets(&assets, &paths.public(), "1.0.0")?;
paths.apply_environment(&paths.public());

// 3. Bind first, so the port is real before anything is told to go there.
let server = EmbeddedServer::bind().await?;
let url = server.base_url();

// 4. Serve, then create the window. Never the other way round.
let running = server.serve(router);
running.wait_until_ready().await?;
// open_webview(&url);

Step 3 before step 4 is the whole of the startup race: EmbeddedServer has no constructor that produces a URL it is not already listening on.

Structs§

AndroidConfig
AppPaths
The resolved directories of one installation.
AuthConfig
BundleConfig
DatabaseConfig
EmbeddedAsset
One file of the application’s public/, compiled into the binary.
EmbeddedServer
A bound loopback listener, not yet serving anything.
LaunchToken
The URL the host points the WebView at.
NativeCommand
One entry in the bridge allowlist.
NativeConfig
A project’s native packaging configuration.
NativeError
A native startup or packaging failure.
RunningServer
A server that is serving.
SecurityConfig
WindowConfig

Enums§

Capability
What a command lets the page do.
DatabaseMode
What a packaged application does about its database.
Platform
A platform a Rahti application can be packaged for.

Constants§

ASSET_STAMP
The file that records which version of the package staged the assets now in internal storage.
BRIDGE_PATH
Where the shell serves the bridge from, for a host that would rather link it than inject it.
LAUNCH_PARAM
The query parameter the launch URL carries, and the cookie it becomes.
MIN_ANDROID_SDK
The lowest Android API level Tauri 2 supports.
SCHEMA_VERSION
The version of this file format that this build understands.
SECRET_FILE
The file, under AppPaths::data.
TARGETS
The --target values cargo rahti native accepts.

Functions§

bridge_route
A route serving the bridge, for a host that links it from the document rather than injecting it at WebView creation.
bridge_script
The script, with the current allowlist compiled into it.
check_identifier
Reverse-DNS, and legal as an Android package name.
check_product_name
The installed application’s name, which is also a filename.
check_version
major.minor.patch, all numeric.
commands
The whole allowlist.
csp
The installed policy, if there is one.
default_csp
default-src 'self' and nothing external.
gate
Refuse anything that did not come from this launch.
harden_release
Turn off every development affordance, for a package that is being shipped.
install_csp
Install the policy the security_headers layer will send.
install_session_secret
Put the session key, and the project’s cookie name, where rahti::auth will read them.
is_allowed
Whether the shell should route name at all.
is_external_url
Whether a URL may be handed to the operating system.
launch_token
This launch’s token.
secure
Put a Rahti router behind the native security layers.
security_headers
Add the security headers to every response.
session_secret
This installation’s session key, generating one on first launch.
stage_embedded_assets
Write the embedded assets into internal storage, once per version.
stage_public_assets
Copy the package’s public assets into internal storage, once per version.
superseded_csp
Whether csp is an old default this build would now write differently.