Skip to main content

Module launch_args

Module launch_args 

Source
Expand description

Launch arguments — the typed parameters the app was started with.

This is the Cranpose equivalent of reading intent.extras in a Jetpack Compose activity. A Cranpose app on Android is a NativeActivity, so it sees neither the environment of the shell that ran am start nor, until now, the launching Intent; debug and instrumentation flags read through std::env::var silently return nothing on device. launch_args gives the same values back, typed, on every platform.

Where the values come from:

  • Android — the extras of the launching Intent, pushed in by the cranpose::android backend (adb shell am start ... --ez flag true). onNewIntent replaces the snapshot, exactly as setIntent replaces what getIntent().getExtras() returns for a Compose activity.
  • Desktop and iOS — the process command line (the built-in default below). Command line rather than environment because argv is the launch payload: it is per-launch, it is not inherited by child processes, and it is what the platform tooling already passes — xcrun simctl launch, XCUIApplication().launchArguments, and a plain shell invocation all set argv, while an exported environment variable leaks into every later process in that session and cannot be replaced on relaunch.
  • Web — nothing by default; a shell may install the query string.

Values keep the type the platform delivered (--ez/--ei/--el/--ef/ --es on Android), and text values are parsed on demand, so an argument written as text on the command line still reads back as a number.

use cranpose_services::launch_args;

let args = launch_args();
if args.is_debuggable() && args.boolean("ob_debug").unwrap_or(false) {
    let level = args.int("ob_level").unwrap_or(0);
    let seed = args.long("ob_seed").unwrap_or(0);
    let time_scale = args.float("ob_time_scale").unwrap_or(1.0);
    let screen = args.string("ob_screen").unwrap_or("");
    let _ = (level, seed, time_scale, screen);
}

Structs§

LaunchArgs
The launch arguments the app was started with.

Enums§

LaunchArgValue
One launch-argument value, in the type the platform delivered it.

Functions§

ProvideLaunchArgs
Provides launch arguments to content.
clear_platform_launch_args
Removes any platform-reported launch arguments (tests and teardown).
isDebuggable
Whether the OS considers this build debuggable, read from composition.
is_debuggable
Whether the OS considers this build debuggable — see LaunchArgs::is_debuggable.
launch_args
The launch arguments this app was started with.
launch_args_from_command_line
Parses --name=value (text) and bare --name (true) out of a command line.
local_launch_args
The composition local carrying the launch arguments.
set_platform_launch_args
Installs the launch arguments reported by the platform, replacing any previous snapshot.

Type Aliases§

LaunchArgsRef
Shared handle to a LaunchArgs snapshot.