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§
- Android
Config - AppPaths
- The resolved directories of one installation.
- Auth
Config - Bundle
Config - Database
Config - Embedded
Asset - One file of the application’s
public/, compiled into the binary. - Embedded
Server - A bound loopback listener, not yet serving anything.
- Launch
Token - The URL the host points the WebView at.
- Native
Command - One entry in the bridge allowlist.
- Native
Config - A project’s native packaging configuration.
- Native
Error - A native startup or packaging failure.
- Running
Server - A server that is serving.
- Security
Config - Window
Config
Enums§
- Capability
- What a command lets the page do.
- Database
Mode - 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
--targetvaluescargo rahti nativeaccepts.
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_headerslayer will send. - install_
session_ secret - Put the session key, and the project’s cookie name, where
rahti::authwill read them. - is_
allowed - Whether the shell should route
nameat 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
cspis an old default this build would now write differently.