|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**Quick Web Apps** (`dev.heppen.webapps`) is a web app manager for the COSMIC desktop environment. Users create, manage, and launch web applications that run in isolated WebKitGTK webview windows. Built with Rust using `libcosmic` (iced-based GUI framework) and `wry`/`tao` for the webview runtime. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +The project uses `just` as the task runner: |
| 12 | + |
| 13 | +```bash |
| 14 | +just # Build release (default) |
| 15 | +just build-debug # Debug build |
| 16 | +just build-release # Release build |
| 17 | +just check # Clippy with -W clippy::pedantic |
| 18 | +just run # Run with RUST_BACKTRACE=full |
| 19 | +just dev # cargo fmt + run |
| 20 | +just clean # cargo clean |
| 21 | +sudo just install # Install binaries, desktop entry, icons to /app/ |
| 22 | +``` |
| 23 | + |
| 24 | +Flatpak build (primary distribution method): |
| 25 | +```bash |
| 26 | +flatpak run --command=flathub-build org.flatpak.Builder --install dev.heppen.webapps.json |
| 27 | +``` |
| 28 | + |
| 29 | +There is no test suite. There is no flake.nix — use the Containerfile in `.devcontainer/` or system-installed deps. |
| 30 | + |
| 31 | +### System Dependencies |
| 32 | + |
| 33 | +Building requires: `pkg-config`, `libssl-dev`, `libxkbcommon-dev`, `libwebkit2gtk-4.1-dev`, `just` |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +### Two Binaries |
| 38 | + |
| 39 | +The crate produces two binaries (see `Cargo.toml [[bin]]` sections): |
| 40 | + |
| 41 | +1. **`dev-heppen-webapps`** (`src/bin/dev-heppen-webapps/main.rs`) — The main GUI application where users create/edit/delete web apps |
| 42 | +2. **`dev-heppen-webapps-webview`** (`src/bin/webview.rs`) — Lightweight webview process spawned per web app. Reads config from the database, creates a GTK+WebKitGTK window, and runs an event loop |
| 43 | + |
| 44 | +Each web app runs as a separate `dev-heppen-webapps-webview <app_id>` process. |
| 45 | + |
| 46 | +### Library Layer (`src/`) |
| 47 | + |
| 48 | +- **`lib.rs`** — Core types (`Icon`, `IconType`, `Category`, `WindowSize`, `WebviewArgs`), XDG path helpers (`database_path()`, `profiles_path()`, `icons_location()`), icon search/validation, URL validation |
| 49 | +- **`browser.rs`** — `Browser` struct: app configuration (URL, title, profile path, window size, decorations, private mode, mobile simulation). Serialized to/from RON |
| 50 | +- **`launcher.rs`** — `WebAppLauncher` struct: wraps `Browser` + name/icon/category. Uses `ashpd` (XDG Desktop Portal) `DynamicLauncher` to create/delete `.desktop` entries. Stores webapp data as `.ron` files in the database directory |
| 51 | +- **`localize.rs`** — i18n via `i18n-embed` with Fluent. Uses `fl!()` macro. Translation files: `i18n/{lang}/webapps.ftl` |
| 52 | + |
| 53 | +### GUI Application (`src/bin/dev-heppen-webapps/`) |
| 54 | + |
| 55 | +- **`pages/mod.rs`** — `QuickWebApps`: the `cosmic::Application` implementation. Manages nav bar (installed apps list), dialogs (icon picker, delete confirmation, icon downloader), theme system, and config subscription |
| 56 | +- **`pages/editor.rs`** — `AppEditor`: form for creating/editing a web app (title, URL, icon, category, window size, toggles for persistent profile/decorations/private mode/mobile simulation) |
| 57 | +- **`pages/iconpicker.rs`** — `IconPicker`: modal dialog for searching system icon packs (Papirus) or picking custom files |
| 58 | +- **`config.rs`** — `AppConfig` with CosmicConfig integration (persists theme choice) |
| 59 | +- **`themes.rs`** — Light/Dark built-in themes + custom RON theme import |
| 60 | + |
| 61 | +### Key Data Flow |
| 62 | + |
| 63 | +**Creating a web app:** |
| 64 | +1. User fills `AppEditor` form → generates unique `app_id` (title + random 4-digit suffix) |
| 65 | +2. `WebAppLauncher::create()` calls XDG DynamicLauncher portal to install a `.desktop` entry |
| 66 | +3. Launcher config saved as RON to `$XDG_DATA_HOME/dev.heppen.webapps/database/{app_id}.ron` |
| 67 | + |
| 68 | +**Launching a web app:** |
| 69 | +1. Desktop entry runs `dev.heppen.webapps.webview {app_id}` |
| 70 | +2. Webview binary loads `Browser::from_appid()` from the RON database |
| 71 | +3. Creates GTK window with WebKitGTK webview using stored settings |
| 72 | + |
| 73 | +### Data Storage (all XDG-compliant) |
| 74 | + |
| 75 | +| Path | Content | |
| 76 | +|------|---------| |
| 77 | +| `$XDG_DATA_HOME/dev.heppen.webapps/database/*.ron` | Webapp configs (RON format) | |
| 78 | +| `$XDG_DATA_HOME/dev.heppen.webapps/profiles/{app_id}/` | Per-app WebKitGTK browser data | |
| 79 | +| `$XDG_DATA_HOME/dev.heppen.webapps/icons/` | Cached icons | |
| 80 | +| `$XDG_DATA_HOME/dev.heppen.webapps/themes/` | Custom theme RON files | |
| 81 | +| `$XDG_CONFIG_HOME/cosmic/{version}/dev.heppen.webapps.ron` | App config (via CosmicConfig) | |
| 82 | + |
| 83 | +## i18n |
| 84 | + |
| 85 | +14 languages supported. English source: `i18n/en/webapps.ftl`. Add translations by creating `i18n/{lang_code}/webapps.ftl`. Strings are accessed via `fl!("key")` or `fl!("key", arg = value)`. |
| 86 | + |
| 87 | +## App ID |
| 88 | + |
| 89 | +The app ID `dev.heppen.webapps` is used throughout: Flatpak manifest, desktop entry, config paths, binary naming. It is defined as `APPID` in the justfile and `APP_ID` constant in `src/lib.rs`. |
| 90 | + |
| 91 | +## Key Dependencies |
| 92 | + |
| 93 | +- **libcosmic** (git dep from pop-os/libcosmic) — COSMIC app framework, provides `cosmic::Application` trait, widgets, nav bar, config system, theme engine |
| 94 | +- **wry** + **tao** + **gtk** — WebKitGTK webview creation and window management (webview binary only) |
| 95 | +- **ashpd** — XDG Desktop Portal client for DynamicLauncher (creating/removing `.desktop` entries) |
| 96 | +- **ron** — Rusty Object Notation for config serialization |
| 97 | +- **i18n-embed** + **i18n-embed-fl** — Compile-time embedded Fluent translations |
0 commit comments