Get started
How apps work
A MIRA app is one file with two halves: a glasses app and an optional phone companion.
Two halves
| Glasses app | Phone companion (optional) | |
|---|---|---|
| Runs on | MIRA glasses | The MIRA iPhone app |
| Written in | Rust, compiled to WebAssembly | HTML, CSS and JavaScript |
| Good for | Drawing the display, handling taps and swipes, head tracking | Your app’s phone screen, networking, storage, microphone audio, voice commands |
| Talks through | Shared/companion.rs | miraCompanion |
The two halves exchange small JSON messages over Bluetooth. Keep networking, accounts and anything secret on the phone, and send the glasses only what they need to draw.
Installed apps live on the glasses. An installed app opens on your glasses even when your phone isn’t connected, but anything that needs the phone, like companion messages or web data, won’t work until it reconnects.
One file
A finished app is one HTML file under 2 MB. It contains a small manifest with the app’s name, your optional phone screen, and the compiled WebAssembly module encoded as base64. Glasses-only apps use the same file format. See Package and validate for the exact layout.
Lifecycle
Your glasses module exports its memory and four functions, plus an optional fifth. MIRA calls them; none of them return a value.
| Export | When MIRA calls it |
|---|---|
app_init() | Once, when the app opens. Do your setup here. |
app_render(elapsed_ms) | Repeatedly while the display is on, with the milliseconds since the previous call. Update your state and redraw when something changed. |
app_event(event) | When the wearer taps, swipes or holds. See Input. |
app_stop() | Right before the app closes. MIRA then releases everything the app was using. |
app_update(elapsed_ms) | Optional. Repeatedly, even while the display is off. See Timing and the display. |
#![no_std]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }
#[no_mangle]
pub extern "C" fn app_init() { /* set up state, draw the first frame */ }
#[no_mangle]
pub extern "C" fn app_render(elapsed_ms: i32) { /* advance timers, redraw if needed */ }
#[no_mangle]
pub extern "C" fn app_event(event: i32) { /* 0 tap, 1 and 2 swipes, ... */ }
#[no_mangle]
pub extern "C" fn app_stop() {}Timing and the display
While the display is on, MIRA calls your app every 40 ms. That suits animation, but a still screen doesn’t need it. Call foreground_interval_ms(ms) to pick 20 to 60,000 ms, or 0 for no regular calls, and go back to 40 ms when something starts moving. Phone data, request replies, head-tracking threshold changes and audio level changes still reach your app between calls. You can also shorten the interval from app_event, for example when a tap starts an animation. MIRA uses the fastest interval anything on the glasses asks for, so your app can be called more often.
While the display is off, MIRA doesn’t call app_render. If your app needs to keep working then, for example to run a timer or follow updates from the phone, also export app_update(elapsed_ms):
- MIRA calls
app_updateto advance your state, with the display on or off. Handle timers and phone messages there. app_renderthen only draws, and only while the display is on. Its argument becomesforce, which is1on the first call after the display wakes: redraw everything then, even if nothing changed.- In
app_init, set how oftenapp_updateruns while the display is off withbackground_interval_ms(ms): 200 to 60,000 ms, or0for the default of 2,000 ms. New data from the phone can wake it sooner. - Before drawing from
app_event, checkdisplay_active(). It’s nonzero while the display is on.
#[link(wasm_import_module = "mira")]
extern "C" {
fn background_interval_ms(interval: i32) -> i32;
}
#[no_mangle]
pub unsafe extern "C" fn app_init() {
background_interval_ms(1_000); // update once a second while the display is off
}
#[no_mangle]
pub extern "C" fn app_update(elapsed_ms: i32) { /* advance timers, handle phone messages */ }
#[no_mangle]
pub extern "C" fn app_render(force: i32) { /* draw; redraw everything when force is 1 */ }Rules for the glasses module
- Use
#![no_std], a panic handler and fixed-size buffers instead of heap allocation. - The module gets one 64 KiB memory page, which includes an 8 KiB stack. The module itself can be up to 128 KB.
- Keep every callback short. Each one runs under an instruction budget, so spread heavy work across several frames.
- WASI, threads, SIMD, reference types and a start section aren’t available. Of bulk memory, only
memory.copyandmemory.fillare. Put setup inapp_init. - Import only the documented functions from the
miramodule. The API reference lists them all.
The shell around your app
Your app runs inside MIRA’s shell. The shell draws the look-up dashboard, notifications and MIRA’s answers, and it sees every gesture first:
- Double tap takes the wearer out of your app, unless your app claims double tap for itself.
- Looking up opens the dashboard, unless your app is reading head orientation.
- Notifications and MIRA’s answers can appear on top of your app.
content::context_changed() reports whether a notification, the dashboard or one of MIRA’s answers has covered or uncovered your app since you last asked. The example app checks it on every frame and redraws when it’s true.
Talking to the phone
There are two ways for the glasses app to reach the phone:
- Your companion. Send and receive JSON messages with your own phone code. See Phone companion.
- MIRA services. Ask the MIRA app for work it already does, such as live transcription, with
ble_request. See Phone requests.
Both are asynchronous. Never block a frame waiting for the phone, and keep local navigation working while a reply is pending.