1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! 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
//!
//! ```no_run
//! # use rahti_native::{AppPaths, EmbeddedServer, NativeError};
//! # async fn example(router: axum::Router) -> Result<(), NativeError> {
//! // 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);
//!
//! # let _ = (url, running);
//! # Ok(())
//! # }
//! ```
//!
//! 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.
// Framework surface: exported for native shells to use, so "nothing in this
// crate calls it yet" is not a defect.
const DEV_ENV: &str = "RAHTI_DEV";
pub use ;
pub use ;
pub use ;
pub use NativeError;
pub use ;
pub use ;
pub use ;
pub use Platform;
pub use ;
pub use ;
/// Turn off every development affordance, for a package that is being shipped.
///
/// Release builds already default to dev mode off, so this is belt and braces
/// — but the belt matters here in a way it does not on a server. `RAHTI_DEV`
/// is read from the process environment, an installed application inherits the
/// environment of whoever launched it, and a user with `RAHTI_DEV=1` exported
/// for their own project would otherwise start a shipped application with its
/// diagnostics endpoint, its reload stream and its `.rahti/dev.log` writer
/// live — inside a WebView with access to native commands.
///
/// So a release package states the value rather than inheriting it. A debug
/// build is left alone: that is `cargo rahti native dev`, where the
/// diagnostics are the point.