Writing a Luft app
A Luft app is a Sabine app with two halves: a Svelte page styled with @luft/ui (packages/web/ui), and a Rust native side built on luft-app (packages/app). Copy the layout of an app in apps/system or apps/store, such as Rover, and change what you need.
The native side
Section titled “The native side”Add luft-app to the app’s desktop/Cargo.toml with the features it needs, such as apps, thumbnails, watch, fonts or camera:
luft-app = { workspace = true, features = ["apps", "thumbnails"] }use luft_app::{Backdrop, Events, GlassWindow};
const WINDOW: GlassWindow = GlassWindow { title: "Settings", size: (1040, 720), min_size: (760, 520), sidebar_width: 280, single_instance: Some("com.lantharos.settings"), backdrop: Backdrop::WINDOW,};
pub fn run_app() -> ! { let events = Events::default(); luft_app::run(&events, |window| register(WINDOW.apply(window), &events), |_| {})}sidebar_widthmust match the page’s--sidebar-width, and is0for a window without a sidebar.backdropsays what the glass is for and which material it would like, see Glass.- With
single_instanceset, launching the app again focuses the running window and sends the new arguments as asingleInstance.activateevent, which bridge commands take as anActivation, the same typeActivation::current_process()gives for the app’s own launch. runwatches Kestrel’s palette and the desktop’s fonts for the page. The last closure runs at the same point, for the app’s own watchers.
Bridge commands go through the Commands trait, for handlers that return Result<T, String>:
window .command("about_info", |_: Value| info()) .with("network_open", &events, open) .command_async("disks_list", list)with also passes a shared context such as Events or the app’s state. command_async and with_async take async functions, awaited on Sabine’s runtime, and anything that waits on D-Bus belongs there. spawn runs background work on the same runtime, and block_on waits on it from a thread of the app’s own.
Sandboxed apps only see the files they’re given. Activation::paths_within_reach and the file chooser in luft_app::portal hand back paths the app can open, through the document portal, for the files it was opened with or the person picked.
A window with a sidebar is glass all around: the sidebar and an 8px frame on the other three sides, around the content as an opaque sheet with 9px corners inside the window’s 15px ones. Exact concentric corners, 8px tighter, look pinched next to the window’s curve, so the sheet’s are a little rounder; the blur and opaque regions GlassWindow and GlassShell report use the same radius. Only the frame and sidebar are blurred, and nothing is drawn under the sheet. Beneath the page, the sheet is the content colour of the light or dark style, so a window that fades in or out as it opens or closes never darkens in the light style. A window without a sidebar is opaque. Kestrel draws the glass as the material people chose for app windows: Luca, a blur of what is behind, Maris, the surface colour with a hint of the wallpaper, Niko, a blur of what is behind in the lightness of the surface, or Rina, Luca’s blur with a narrow rim of light along the window’s rounded edges. Backdrop::WINDOW follows that choice. An app whose layout needs one material asks for it with BackdropPreference::Luca, BackdropPreference::Maris or BackdropPreference::Niko, and a window that is a popover or a palette rather than an app’s main window sets BackdropRole::Transient, so it follows the choice for panels and menus:
use luft_app::Backdrop;use sabine::{BackdropPreference, BackdropRole};
const PALETTE: Backdrop = Backdrop { role: BackdropRole::Transient, preference: BackdropPreference::User,};GlassShell leaves out the glass’s own tint over Maris and Niko, which already are the whole surface, and keeps it over Luca and Rina, where it keeps text readable. A window whose sidebar comes and goes, such as one that hides it for a single opened file, sets followSidebar on GlassShell, which gives the window the regions of whichever layout it shows. How the materials are drawn is in The compositor.
The page
Section titled “The page”Add "@luft/ui": "workspace:*" to the app’s devDependencies, and import its styles right after Tailwind, which also makes Tailwind scan the package:
@import 'tailwindcss';@import '@luft/ui/styles.css';import { luftFonts, luftLocales, sabineTarget } from '@luft/ui/vite';
export default defineConfig({ plugins: [luftFonts(), luftLocales(), sabineTarget(), tailwindcss(), svelte()]});luftLocalesbundles the app’slocalesfolder and the kit’s own messages, one chunk per language, loaded only when that language is in use.luftFontsserves Open Runde and Maple Mono at/fonts/, copies them into the build, and scales everypxorremfont size and line height by the desktop’s text size.sabineTargetbuilds for the Chromium Sabine ships.
Extend @luft/ui/tsconfig.base.json in tsconfig.json, and preload /fonts/OpenRunde-Regular.woff2 in index.html.
<GlassShell> <aside class="glass-sidebar drag-region px-3 py-4"> <nav class="flex flex-col gap-0.5" {@attach selectionPill()}> <button type="button" class="nav-item" class:active aria-current={active ? 'page' : undefined}>…</button> </nav> </aside> <main class="glass-content"> <TitleBar {title} /> <PageStage {page} {order}>…</PageStage> </main></GlassShell>TitleBar is the 68px bar every app window starts with: the title, an optional detail, leading buttons such as Back, actions before WindowControls, and compact for a document’s name over a second line. WindowControls tells Sabine where its buttons are, so they work even while the page is busy; with an onclose of its own, the close button stays with the page, which decides when to close. Sidebar items use nav-item, with tall for two lines, nav-detail for the second line, nav-count for a number on the right, and nav-heading and nav-action for a group’s title and its add button. The selected item sits on a light pill with its icon in the accent colour. EmptyState is the icon, title, message and button an empty page shows.
The shared styles give every app the same behaviour: buttons and other controls keep the arrow cursor and only links show the hand, text in the window can’t be selected except in fields and where an app adds select-text, every scroller has the same thin scrollbar, and toasts sit centred over the content beside the sidebar.
Inside GlassShell, right-clicking a text field or selected text opens Luft’s edit menu, with corrections for a misspelled word and whichever of undo, redo, cut, copy, paste and select all apply there. Sabine only asks for it when the page leaves the contextmenu event alone, so an app’s own menu, opened from a handler that calls preventDefault(), takes its place.
Dialog windows
Section titled “Dialog windows”A Dialog opens over the page it belongs to. When that page’s window is too small for it, open the dialog as a window of its own, attached to its parent: Kestrel keeps it centred over the parent, dims the parent and keeps it from being used until the dialog closes. The parent’s page passes await appWindow.identifier() to a command that opens the window:
window .fixed_size(420, 240) .frameless() .transparent(true) .skip_taskbar(true) .parent_window(parent) .modal(true)The dialog’s page renders the same Dialog inside DialogWindow, which sizes the window to the dialog and shows it once it fits:
<DialogWindow> <Dialog title={title} onclose={() => appWindow.close()}>…</Dialog></DialogWindow>Schelf’s install window opens its dialogs this way, and gets their answers back through the command that opened them.
Startup state
Section titled “Startup state”Flatten luft_app::Appearance into the app’s startup state, and start @luft/ui’s appearance store from it:
#[derive(Serialize)]struct AppState { #[serde(flatten)] appearance: Appearance,}
AppState { appearance: Appearance::current().await }import { appearance } from '@luft/ui';
appearance.start(await invoke('app_state'));await i18n.ready;The store gets the palette, fonts, motion preference, corners and the session’s languages, and follows their changes. appearance.start also loads the app’s translation, so wait for i18n.ready before showing the window and it never shows untranslated labels. Translating Luft covers writing strings that can be translated.
The palette is dark unless the app sets data-scheme="light". To follow the desktop:
$effect(() => { document.documentElement.dataset.scheme = appearance.scheme;});appearance.posture is tablet while the computer is folded into a tablet and laptop otherwise, also on the page as data-posture, so apps can give fingers and the pen more room. appearance.keyboard says whether there’s a keyboard to type on. Fields marked inputmode="none" never bring up the on-screen keyboard, so leave them for text only a real keyboard types. Colours and motion covers the palette’s roles and the shared motion.
Bringing windows back
Section titled “Bringing windows back”After a restart to install an update, Kestrel opens the apps that were open and puts their windows back (Kestrel). Sabine apps also bring back what each window showed:
- Every window carries a key of its own as its Wayland toplevel tag, which Kestrel’s record keeps.
- Kestrel starts the app with the keys of its windows in
SABINE_RESTORE_WINDOWSand places each window where the one with the same tag was. - While a window is open, the app keeps what it shows in
~/.local/state/<app id>/windows, readable only by the account, a moment after it changes. Closing the window or quitting the app removes it, so a window you closed never comes back.
Keep paths, page names and ids there, never passwords, tokens or anything unlocked. Something the app was asked to open, such as a file it was started with, goes before what it showed. Draft, Heft and Flatbed don’t need this: they open on what you were working on every time.
Thumbnails
Section titled “Thumbnails”The thumbnails feature makes thumbnails in the shared freedesktop cache and sends them to the page in batches. Each request replaces the one before, so asking for the files on screen keeps the queue short while scrolling.
Common pictures, Easel documents and Photoshop files are read in the app itself. A Photoshop file’s thumbnail comes from the merged picture Photoshop saves alongside the layers: only the rows and columns the thumbnail needs are read from it, so a large file costs about as much as a small one, and the layers are never opened.
Files that need a thumbnailer go to one of those in the thumbnailers folders of ~/.local/share and XDG_DATA_DIRS. It runs in a bubblewrap sandbox that sees only /usr, its own program, the file itself and a private folder for the result, with no network and no way to open new user namespaces, so a hostile file can only break its own thumbnail.
Luft’s own thumbnailer, luft-thumbnailer in services/thumbnailer, gives AppImages, Flatpak bundles and .flatpakref files their app’s icon. It reads an AppImage’s icons from its squashfs without running or unpacking it, a bundle’s from its header, and a reference’s from the icons Flatpak already downloaded, so it never goes online. SVG icons are drawn with only the images embedded in them, never files they point to.