diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d67bb772e..87bb219fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v7 + with: + submodules: true - name: Setup pnpm uses: pnpm/action-setup@v6 @@ -32,13 +34,25 @@ jobs: pnpm fetch pnpm install --frozen-lockfile --offline + - name: Setup JDK 21 (for @meshtastic/sdk-kmp) + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + + - name: Build @meshtastic/sdk-kmp + run: pnpm --filter @meshtastic/sdk-kmp build + - name: Build All Packages (with exclusions) shell: bash run: | set -euo pipefail # List packages to exclude (full paths under repo root) - EXCLUDED_DIRS=("packages/protobufs" "packages/transport-deno" "packages/ui" "packages/web") + EXCLUDED_DIRS=("packages/protobufs" "packages/sdk-kmp" "packages/ui" "packages/web") is_excluded() { local dir="$1" diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 0a28e4e0a..3ade3b99e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -21,6 +21,8 @@ jobs: CI: "true" steps: - uses: actions/checkout@v7 + with: + submodules: true - uses: pnpm/action-setup@v6 @@ -32,6 +34,18 @@ jobs: - name: Install workspace deps run: pnpm install --frozen-lockfile + - name: Setup JDK 21 (for @meshtastic/sdk-kmp) + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + + - name: Build @meshtastic/sdk-kmp + run: pnpm --filter @meshtastic/sdk-kmp build + - name: Install Chromium run: pnpm exec playwright install --with-deps chromium diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 55e73691f..88bfe1c1a 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -19,6 +19,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v7 + with: + submodules: true - name: Setup pnpm uses: pnpm/action-setup@v6 @@ -33,6 +35,18 @@ jobs: - name: Install dependencies (root) run: pnpm install --frozen-lockfile + - name: Setup JDK 21 (for @meshtastic/sdk-kmp) + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + + - name: Build @meshtastic/sdk-kmp + run: pnpm --filter @meshtastic/sdk-kmp build + - name: Run tests run: pnpm run test diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index bc5817f99..b23ef56f4 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -22,6 +22,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v7 + with: + submodules: true - name: Setup pnpm uses: pnpm/action-setup@v6 @@ -47,6 +49,18 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile + - name: Setup JDK 21 (for @meshtastic/sdk-kmp) + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + + - name: Build @meshtastic/sdk-kmp + run: pnpm --filter @meshtastic/sdk-kmp build + - name: Run linter run: pnpm run lint diff --git a/.github/workflows/release-packages.yml b/.github/workflows/release-packages.yml index 5e13ea4ac..c1226b97d 100644 --- a/.github/workflows/release-packages.yml +++ b/.github/workflows/release-packages.yml @@ -44,10 +44,24 @@ jobs: run: | set -euo pipefail if [ "${{ github.event.inputs.packages }}" = "all" ] || [ -z "${{ github.event.inputs.packages }}" ]; then - mapfile -t TARGETS < <(ls -d packages/*) + mapfile -t ALL < <(ls -d packages/*) else - IFS=',' read -ra TARGETS <<< "${{ github.event.inputs.packages }}" - TARGETS=("${TARGETS[@]/#/packages/}") + IFS=',' read -ra ALL <<< "${{ github.event.inputs.packages }}" + ALL=("${ALL[@]/#/packages/}") + fi + # Only publish packages that are not marked "private": true + # (protobufs, sdk-kmp and ui are all private workspace packages). + TARGETS=() + for dir in "${ALL[@]}"; do + if [ -f "$dir/package.json" ] && [ "$(node -p "require('./$dir/package.json').private === true")" = "false" ]; then + TARGETS+=("$dir") + else + echo "Skipping $dir (private or no package.json)" + fi + done + if [ "${#TARGETS[@]}" -eq 0 ]; then + echo "::error::No publishable (non-private) packages selected." + exit 1 fi printf '%s\n' "${TARGETS[@]}" | paste -sd, - > targets.txt echo "list=$(cat targets.txt)" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/release-web.yml b/.github/workflows/release-web.yml index 6f30930bb..e3fc8b252 100644 --- a/.github/workflows/release-web.yml +++ b/.github/workflows/release-web.yml @@ -34,6 +34,7 @@ jobs: uses: actions/checkout@v7 with: ref: ${{ inputs.ref != '' && inputs.ref || github.ref }} + submodules: true - name: Setup pnpm uses: pnpm/action-setup@v6 @@ -50,6 +51,18 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile + - name: Setup JDK 21 (for @meshtastic/sdk-kmp) + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + + - name: Build @meshtastic/sdk-kmp + run: pnpm --filter @meshtastic/sdk-kmp build + - name: Build web package working-directory: apps/web run: pnpm run build diff --git a/.gitmodules b/.gitmodules index e69de29bb..16b8ee914 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "packages/sdk-kmp/vendor/meshtastic-sdk"] + path = packages/sdk-kmp/vendor/meshtastic-sdk + url = https://github.com/danditomaso/meshtastic-sdk.git + branch = feat/storage-sqldelight-js diff --git a/.oxfmtrc.json b/.oxfmtrc.json index 32547c59b..f5b60173e 100644 --- a/.oxfmtrc.json +++ b/.oxfmtrc.json @@ -3,5 +3,5 @@ "useTabs": false, "tabWidth": 2, "printWidth": 80, - "ignorePatterns": ["*.md"] + "ignorePatterns": ["*.md", "packages/sdk-kmp/vendor/**"] } diff --git a/README.md b/README.md index aae4e0feb..ff46cf371 100644 --- a/README.md +++ b/README.md @@ -1,83 +1,41 @@ # Meshtastic Web Monorepo [![CI](https://img.shields.io/github/actions/workflow/status/meshtastic/web/ci.yml?branch=main&label=Web%20CI&logo=github&color=yellow)](https://github.com/meshtastic/web/actions/workflows/ci.yml) -[![CI](https://img.shields.io/github/actions/workflow/status/meshtastic/js/ci.yml?branch=master&label=JS%20CI&logo=github&color=yellow)](https://github.com/meshtastic/js/actions/workflows/ci.yml) [![CLA assistant](https://cla-assistant.io/readme/badge/meshtastic/web)](https://cla-assistant.io/meshtastic/web) [![Fiscal Contributors](https://opencollective.com/meshtastic/tiers/badge.svg?label=Fiscal%20Contributors&color=deeppink)](https://opencollective.com/meshtastic/) [![Vercel](https://img.shields.io/static/v1?label=Powered%20by&message=Vercel&style=flat&logo=vercel&color=000000)](https://vercel.com?utm_source=meshtastic&utm_campaign=oss) ## Overview -This monorepo consolidates the official [Meshtastic](https://meshtastic.org) web -interface, the domain-driven JavaScript SDK that drives it, and a set of -runtime-specific transport packages. Everything you need to read state from or -send commands to a Meshtastic device lives here. +This monorepo contains the official [Meshtastic](https://meshtastic.org) web +client, the shared UI library it uses, the generated protobuf stubs, and +`sdk-kmp`, a thin JavaScript facade over the Kotlin +[meshtastic-sdk](https://github.com/meshtastic/meshtastic-sdk) that handles +device connections and mesh state. > [!NOTE] > You can find the main Meshtastic documentation at https://meshtastic.org/docs/introduction/. ## Packages -Libraries live under `packages/`; the reference web client lives under `apps/`. - | Package | Purpose | | --- | --- | -| `packages/sdk` | Framework-agnostic TypeScript SDK. Domain-driven feature slices (device, chat, nodes, channels, config, telemetry, position, traceroute, files) built around a `MeshClient` orchestrator with `@preact/signals-core` reactive state. | -| `packages/sdk-react` | React hooks + `MeshProvider` on top of `@meshtastic/sdk`. Wraps signals in `useSyncExternalStore` for concurrent-safe renders. | | `apps/web` | Reference React web client. Hosted at [client.meshtastic.org](https://client.meshtastic.org). | +| `packages/sdk-kmp` | Wraps the Kotlin Multiplatform [meshtastic-sdk](https://github.com/meshtastic/meshtastic-sdk), compiled to JavaScript with Gradle (JDK 21), behind a small `@JsExport` facade plus browser transports. The web client's connection and mesh behaviour comes from here. The SDK source is pinned as a git submodule at `packages/sdk-kmp/vendor/meshtastic-sdk`. | | `packages/ui` | Shared Radix + Tailwind component library. | | `packages/protobufs` | Generated TypeScript stubs from [`meshtastic/protobufs`](https://github.com/meshtastic/protobufs), produced via `buf generate`. Source of truth for every wire-level type. | -| `packages/transport-http` | HTTP transport for devices exposing a network interface. | -| `packages/transport-web-bluetooth` | Web Bluetooth transport for BLE-capable devices (browsers). | -| `packages/transport-web-serial` | Web Serial transport for USB-serial devices (browsers). | -| `packages/transport-node` | TCP transport for Node.js. | -| `packages/transport-node-serial` | Serial transport for Node.js. | -| `packages/transport-deno` | TCP transport for Deno. | -| `packages/transport-mock` | In-memory transport for tests. | -All publishable packages ship to both [JSR](https://jsr.io/@meshtastic) and [NPM](https://www.npmjs.com/org/meshtastic). +All packages under `packages/` are private workspace packages; none are +published to npm or JSR from this repository. ## Architecture -`@meshtastic/sdk` organises its source by feature slice. Each slice follows the -same DDD layout: - -``` -features// - domain/ # entities & value objects — pure TypeScript types - application/ # use-cases (SendTextUseCase, FavoriteNodeUseCase, …) - infrastructure/ # protobuf ↔ domain mappers, admin-message adapters - state/ # signals-backed reactive stores - Client.ts # public facade exposing readable signals + command methods - index.ts -``` - -The shared kernel under `packages/sdk/src/core/` owns: - -- **`client/`** — `MeshClient`, the thin orchestrator that owns the transport, queue, event bus, and one instance of every slice client. -- **`transport/`** — the `Transport` interface every `transport-*` package implements. -- **`event-bus/`** — typed pub/sub channels populated by the packet codec. -- **`packet-codec/`** — frame parser (0x94 0xC3), `FromRadio` decoder, portnum router. -- **`queue/`**, **`xmodem/`** — packet ack/timeout pipeline and file-transfer protocol. -- **`signals/`** — signal and keyed-collection helpers consumed by every slice. -- **`logging/`** — `tslog` factory used consistently by every class. -- **`identifiers/`**, **`errors/`** — small primitives shared across slices. - -The protobuf boundary is strict: wire messages enter through the packet codec, -get mapped into domain entities inside `features/*/infrastructure/*Mapper.ts`, -and signals only ever expose the domain shape. - -``` - Transport ─▶ Packet codec ─▶ EventBus ─▶ Slice infrastructure - │ - ▼ - Signals (state) ─▶ sdk-react hooks ─▶ UI - ▲ - │ - Slice application (use-cases) ─▶ MeshClient.sendPacket ─▶ Queue ─▶ Transport -``` - -Expected domain errors are returned as `Result` via [`better-result`](https://www.npmjs.com/package/better-result); exceptions are reserved for programmer errors and truly exceptional conditions. +The web client never speaks the Meshtastic protocol itself. `apps/web` calls +the facade in `packages/sdk-kmp`, which drives the Kotlin SDK (framing, packet +queue, state, persistence) over a browser transport (Web Serial, Web Bluetooth, +or HTTP). Wire-level types come from `packages/protobufs`. See +`packages/sdk-kmp/README.md` for the facade surface and how the SDK version is +pinned. ## Getting Started @@ -89,11 +47,20 @@ Expected domain errors are returned as `Result` via [`better-result`](http `pnpm -r build`, since it runs `buf generate`). If you only want to run the web client in dev, `pnpm --filter meshtastic-web dev` does not need Buf as long as the protobuf stubs are already generated. +- [JDK 21](https://adoptium.net/) — required to build `@meshtastic/sdk-kmp`, + the Kotlin meshtastic-sdk compiled to JavaScript that the web client + connects through. `pnpm --filter meshtastic-web dev` builds it on first + run (its `predev` hook); on macOS `brew install openjdk@21` and + `export JAVA_HOME=/opt/homebrew/opt/openjdk@21`. Until the SDK's `js` + artifacts are released, it compiles from the `packages/sdk-kmp/vendor/meshtastic-sdk` + git submodule (clone with `--recurse-submodules`, or let the build run + `git submodule update --init`). See `packages/sdk-kmp/README.md` for how + the SDK version is pinned and how to switch to the release. ### Setup ```bash -git clone https://github.com/meshtastic/web.git +git clone --recurse-submodules https://github.com/meshtastic/web.git cd web pnpm install ``` @@ -120,8 +87,7 @@ not sequenced against workspace peers, so run `pnpm --filter @meshtastic/protobufs build` first if you are iterating on generated stubs consumed via a non-workspace protocol. -If you only need the web client, build it and its dependency graph without -touching every publishable package: +If you only need the web client, build it and its dependency graph: ```bash pnpm --filter meshtastic-web... build @@ -142,39 +108,10 @@ pnpm check:fix ## Developing -### Adding a new feature slice to `@meshtastic/sdk` - -1. Create `packages/sdk/src/features//` with `domain/`, `application/`, `infrastructure/`, `state/` subdirectories plus an `index.ts` barrel. -2. Implement a signals-backed store in `state/`. -3. Subscribe to the relevant `EventBus` channel(s) inside a `Client.ts` class and write mapped domain entities to the store. -4. Wire the new client into `MeshClient` and re-export types from `packages/sdk/mod.ts`. -5. Add vitest coverage: domain invariants, use-cases against `createFakeTransport()`, and round-trip mapper fixtures. -6. If the slice has React callers, add a matching hook under `packages/sdk-react/src/hooks/`. - -### Adding a new transport - -Implement the `Transport` interface exported from `@meshtastic/sdk/transport`: - -```ts -interface Transport { - toDevice: WritableStream; - fromDevice: ReadableStream; - disconnect(): Promise; -} -``` - -The SDK does the framing and decoding — transports only supply raw bytes. - ### Testing -Vitest is wired at the repo root and picks up `packages/*` projects. The SDK -ships `@meshtastic/sdk/testing` with `createFakeTransport()` for wiring tests -without real hardware. - -## Publishing - -Each publishable package has `build:npm` / `publish:npm` / `prepare:jsr` / -`publish:jsr` scripts. See each package's `package.json` for details. +Vitest is wired at the repo root (`pnpm test`) and picks up the `packages/*` and +`apps/*` projects. See `TESTING.md` for the testing strategy. ## Repository activity diff --git a/TESTING.md b/TESTING.md index 00cb21a7c..6104a6bbc 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,83 +1,39 @@ # Testing strategy -How this monorepo proves correctness, and where coverage currently sits. +How this monorepo proves correctness. The web client talks to devices through +the Kotlin meshtastic-sdk (`packages/sdk-kmp`), so protocol and persistence +behaviour is tested upstream in that SDK; this repo tests the facade and the UI. ## Levels -Tests live in five tiers. Each PR should add coverage at the **lowest level that catches the regression**, and only climb tiers when that's not possible. +Each PR should add coverage at the **lowest level that catches the regression**, and only climb tiers when that's not possible. | Tier | Scope | Tooling | Where | | --- | --- | --- | --- | -| 1. **Unit** | Pure functions, value objects, mappers, single classes with mocked deps | `vitest run` (Node env) | `*.test.ts` colocated with source | -| 2. **Slice integration** | Use-case + store + mapper exercised against in-memory deps; assert outbound bytes and signal state | `vitest` + `createFakeTransport()` | `*.test.ts` in slice dirs | -| 3. **Client integration** | `MeshClient` end-to-end with a fake transport feeding canned `FromRadio` packets | `vitest` + `@meshtastic/sdk/testing` | `packages/sdk/tests/integration/` | -| 4. **Storage integration** | Real Drizzle queries against sql.js in-memory; or against `@vitest/browser` for OPFS | `vitest` (Node + browser) | `packages/sdk-storage-sqlocal/{src,tests}` | -| 5. **Hook / DOM** | React hooks render under `` / ``, react to signals | `vitest` + `@testing-library/react` + `jsdom` | `packages/sdk-react/tests/` | -| 6. **E2E / simulator** | Whole stack: SDK → transport → simulator/firmware. Catches protocol drift | `@vitest/browser` for OPFS; `meshtasticd` simulator over TCP for protocol | future `tests/e2e/` | +| 1. **Unit** | Pure functions, stores, single classes with mocked deps | `vitest run` (Node env) | `*.test.ts` colocated with source | +| 2. **Facade** | The `@JsExport` facade and browser transports in `packages/sdk-kmp` | `vitest` | `packages/sdk-kmp` (`pnpm --filter @meshtastic/sdk-kmp test`) | +| 3. **Component / DOM** | React components and hooks, with the SDK facade mocked | `vitest` + `@testing-library/react` + `jsdom` | `apps/web/src/**` | +| 4. **E2E** | Whole web client in a real browser | Playwright | `e2e/` | -## Per-package coverage gates +## Per-package notes -| Package | Required floor | Notes | -| --- | --- | --- | -| `packages/sdk/core` | every primitive (signals, EventBus, Queue, packet-codec, identifiers) has a unit test; lifecycle covered by `MeshClient.test.ts` | adopt `c8` thresholds once stable | -| `packages/sdk/features/*` | each slice ships: 1 domain invariant test, 1 use-case test against fake transport, 1 mapper round-trip (where mappers exist) | Integration covered by `tests/integration/fake-transport.test.ts` | -| `packages/sdk-react` | each public hook has a `renderHook` test that asserts initial render + re-render on signal change | uses jsdom; provider wrapper required | -| `packages/sdk-storage-sqlocal` | every repository method tested against sql.js in-memory; **at least one OPFS-real test per repo** runs in browser mode | sql.js validates SQL correctness; OPFS validates VFS / Worker plumbing | -| `packages/transport-*` | minimum: framing round-trip, disconnect cleans up streams, error path emits status | low-level; ship as is | -| `packages/web` | component tests at `34` baseline; new SDK-driven UI components must add a hook-mock test | currently all green | - -## Current state (audit) - -| Package | Test files | Tests pass | Gaps | -| --- | --- | --- | --- | -| `packages/sdk` | 7 | 25 ✅ | nodes/channels/config/telemetry/position/traceroute/files slices have **no tests**; no `MeshClient` lifecycle test (only fake-transport integration); no schema migration test | -| `packages/sdk-react` | 1 | 2 ✅ | only `useMeshDevice` + a stubbed `useChat` test; missing `useNodes`, `useChannels`, `useConfig`, `useConnection`, `useTraceroute`, `useTelemetry`, `usePosition`, `useFileTransfer`, `useFavoriteNode`, `useIgnoreNode`, `useMeshRegistry`, `useClientById`, `useActiveClient`. No registry-aware re-render coverage. | -| `packages/sdk-storage-sqlocal` | 2 | 8 ✅ | sql.js only — **no real OPFS test**, no Worker boot test, no cross-tab BroadcastChannel test (mocked away), no migration v1→v2 test | -| `packages/web` | 34 | 294 ✅ | no `useConnections` test; new `meshRegistry` + `sdkStorage` modules untested; chat persistence end-to-end not exercised | -| `packages/transport-*` | 1 each (5 of 7) | varies | `transport-deno` + `transport-mock` have no tests; transports likely lack disconnect/error coverage | -| `packages/core` | 0 | n/a | legacy, slated for deletion in Phase C; tolerable | -| `packages/ui` | 0 | n/a | pure presentational; visual regression only | -| `packages/protobufs` | 0 | n/a | generated code; upstream's responsibility | - -## Concrete additions queued (priority order) - -1. **`packages/sdk` slice tests** — one Use-case + one Mapper test per slice (`nodes`, `channels`, `config`, `telemetry`, `position`, `traceroute`). Pattern: build a stub `MeshClient`, dispatch a synthetic event, assert signal value or outbound bytes. -2. **`packages/sdk-react` hook tests** — for every hook listed above, mount under ``, drive a signal change, assert `result.current`. One file, ~15 cases. -3. **`packages/sdk` `ChatClient` persistence test** — wire `InMemoryMessageRepository`, append messages, re-construct `ChatClient`, assert hydration. Validates the lazy-load contract. -4. **`packages/sdk-storage-sqlocal` migration test** — bootstrap empty DB, run `MIGRATIONS[]`, assert `_schema.version`. Then add a fake `version: 2` migration and prove it's applied idempotently. -5. **`packages/sdk-storage-sqlocal` browser mode** — add a second `vitest.browser.config.ts` using `@vitest/browser` (Playwright provider) so we exercise real OPFS + Worker. CI runs both modes. -6. **`packages/sdk-storage-sqlocal` BroadcastChannel test** — instantiate two `MultiTabCoordinator` instances in same process; one broadcasts, the other observes. (Node has no `BroadcastChannel` global; use `worker_threads`'s `BroadcastChannel` polyfill or jsdom env.) -7. **`packages/web` `meshRegistry` + `sdkStorage` lazy-init test** — assert `getStorageDb()` returns the same promise on repeated calls and only opens the DB once. -8. **`packages/sdk-react` registry test** — mount `` with two clients, switch active, confirm a hook re-renders against the new client. - -## E2E / simulator (Tier 6) — scope only - -Out of immediate scope; documenting for a follow-up PR. - -- Run `meshtasticd` (firmware simulator) in CI Docker via `services:` block. -- Spin up `MeshClient` with `TransportHTTP` pointed at the simulator's HTTP endpoint. -- Drive scripted scenarios: configure → send text → expect ack; channel update; node info exchange; traceroute. -- Use `@vitest/browser` so we also exercise the real OPFS persistence path during E2E. -- Run on `main` only (cost). Smoke subset on PR. - -Until that lands, `createFakeTransport()` covers the protocol layer at unit/integration speed. +| Package | Notes | +| --- | --- | +| `apps/web` | Component and store tests; new SDK-driven UI must mock the facade rather than the Kotlin build. | +| `packages/sdk-kmp` | Facade tests only; the underlying Kotlin SDK is tested in its own repository. | +| `packages/ui` | Pure presentational; no unit tests. | +| `packages/protobufs` | Generated code; upstream's responsibility. | ## Conventions -- Test file colocated with source: `Foo.ts` → `Foo.test.ts`. -- Integration tests under `tests/integration/`. -- Browser-mode tests use the suffix `.browser.test.ts` so they can be filtered. -- Protobuf fixtures live in `__fixtures__/*.fixtures.ts` next to mappers; binary data committed as base64, not raw bytes. -- Each test imports concrete classes from the source path (`./Foo.ts`), not the package barrel — fast type-check, zero re-export drift. -- No mocked SDK from inside SDK tests. Use `createFakeTransport()` and real `MeshClient` instances. +- Test file colocated with source: `Foo.ts` -> `Foo.test.ts`. +- Each test imports concrete classes from the source path (`./Foo.ts`), not the package barrel. ## Running ```sh -pnpm -r test # all packages, Node env -pnpm --filter @meshtastic/sdk test -pnpm --filter @meshtastic/sdk-storage-sqlocal test -pnpm --filter meshtastic-web test -# future: -pnpm --filter @meshtastic/sdk-storage-sqlocal test:browser +pnpm test # root vitest, all projects +pnpm --filter meshtastic-web test # web client only +pnpm --filter @meshtastic/sdk-kmp test +pnpm test:e2e # Playwright ``` diff --git a/apps/web/.oxlintrc.json b/apps/web/.oxlintrc.json index e457f9f52..05c851ddb 100644 --- a/apps/web/.oxlintrc.json +++ b/apps/web/.oxlintrc.json @@ -20,6 +20,12 @@ "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-non-null-assertion": "off" } + }, + { + "files": ["src/core/kmp/browserStorage.ts"], + "rules": { + "import/default": "off" + } } ] } diff --git a/apps/web/components.json b/apps/web/components.json new file mode 100644 index 000000000..887d243c8 --- /dev/null +++ b/apps/web/components.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "new-york", + "rsc": false, + "tsx": true, + "tailwind": { + "config": "", + "css": "src/index.css", + "baseColor": "neutral", + "cssVariables": true, + "prefix": "" + }, + "iconLibrary": "lucide", + "aliases": { + "components": "@components", + "utils": "@core/utils/cn", + "ui": "@components/shadcn", + "lib": "@core/utils", + "hooks": "@core/hooks" + } +} diff --git a/apps/web/package.json b/apps/web/package.json index 26c0c68a1..5f531e162 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -15,6 +15,7 @@ "scripts": { "preinstall": "npx only-allow pnpm", "setup:certs": "mkcert localhost 127.0.0.1 ::1", + "prebuild": "pnpm --filter @meshtastic/sdk-kmp ensure-dist", "build": "vite build", "build:analyze": "BUNDLE_ANALYZE=true pnpm run build", "lint": "oxlint", @@ -23,6 +24,7 @@ "format:fix": "oxfmt .", "check": "pnpm lint && pnpm format", "check:fix": "pnpm lint:fix && pnpm format:fix", + "predev": "pnpm --filter @meshtastic/sdk-kmp ensure-dist", "dev": "vite", "dev:https": "USE_HTTPS=true vite", "test": "vitest", @@ -32,17 +34,13 @@ "package": "gzipper c -i html,js,css,png,ico,svg,json,webmanifest,txt dist dist/output && tar -cvf dist/build.tar -C ./dist/output/ ." }, "dependencies": { + "@bufbuild/protobuf": "^2.16.0", "@hookform/resolvers": "^5.9.1", - "@meshtastic/sdk": "workspace:*", - "@meshtastic/sdk-react": "workspace:*", - "@meshtastic/sdk-storage-sqlocal": "workspace:*", - "@meshtastic/transport-http": "workspace:*", - "@meshtastic/transport-web-bluetooth": "workspace:*", - "@meshtastic/transport-web-serial": "workspace:*", + "@meshtastic/protobufs": "workspace:*", + "@meshtastic/sdk-kmp": "workspace:*", "@noble/curves": "^2.4.0", "@preact/signals-core": "^1.14.4", "@radix-ui/react-accordion": "^1.3.1", - "@radix-ui/react-alert-dialog": "^1.2.1", "@radix-ui/react-checkbox": "^1.4.1", "@radix-ui/react-dialog": "^1.3.1", "@radix-ui/react-dropdown-menu": "^2.2.1", @@ -59,6 +57,7 @@ "@radix-ui/react-toggle-group": "^1.2.1", "@radix-ui/react-tooltip": "^1.4.1", "@radix-ui/react-visually-hidden": "^1.2.13", + "@sqlite.org/sqlite-wasm": "3.51.2-build9", "@tailwindcss/vite": "^4.3.3", "@tanstack/react-router": "^1.170.44", "@tanstack/react-router-devtools": "^1.167.2", @@ -73,6 +72,7 @@ "clsx": "^2.1.1", "cmdk": "^1.1.1", "crypto-random-string": "^6.0.0", + "drizzle-orm": "^0.45.4", "i18next": "^26.4.5", "i18next-browser-languagedetector": "^8.2.1", "i18next-http-backend": "^4.0.3", @@ -89,6 +89,9 @@ "react-map-gl": "8.1.3", "react-qrcode-logo": "^4.1.0", "rfc4648": "^1.5.4", + "sqlocal": "^0.18.0", + "tslog": "^5.2.0", + "vaul": "^1.1.2", "vite": "^8.3.4", "vite-plugin-html": "^3.2.2", "vite-plugin-pwa": "^2.0.0", @@ -106,6 +109,7 @@ "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", "@types/serviceworker": "^0.0.203", + "@types/sql.js": "^1.4.11", "@types/w3c-web-serial": "^1.0.8", "@vitejs/plugin-basic-ssl": "^2.3.0", "@vitejs/plugin-react": "^6.1.2", @@ -114,10 +118,12 @@ "happy-dom": "^21.0.1", "oxfmt": "^0.73.0", "oxlint": "^1.88.0", + "sql.js": "^1.15.0", "tailwind-merge": "^3.7.0", "tailwindcss": "^4.3.3", "tailwindcss-animate": "^1.0.7", "tar": "^7.5.22", + "tslog": "^5.2.0", "typescript": "^7.0.2", "vitest": "^5.0.4" } diff --git a/apps/web/public/i18n/locales/en/connections.json b/apps/web/public/i18n/locales/en/connections.json index f26f64d55..cdabe2577 100644 --- a/apps/web/public/i18n/locales/en/connections.json +++ b/apps/web/public/i18n/locales/en/connections.json @@ -1,4 +1,12 @@ { + "drawer": { + "title": "Connections", + "close": "Close connections", + "back": "Back to connections", + "addConnection": "Add connection", + "resize": "Resize connections drawer", + "deleteConfirm": "Delete {{name}}?" + }, "page": { "title": "Connect to a Meshtastic device", "description": "Add a device connection via HTTP, Bluetooth, or Serial. Your saved connections will be saved in your browser." @@ -37,8 +45,6 @@ }, "toasts": { "connected": "Connected", - "nowDisconnected": "{{name}} is now disconnected", - "disconnected": "Disconnected", "failed": "Failed to connect", "checkConnection": "Check your device or settings and try again", "defaultSet": "Default set", @@ -65,6 +71,7 @@ }, "phase": { "connecting": "Opening transport…", + "reconnecting": "Reconnect attempt {{attempt}} of {{max}}…", "configuring": "Streaming configuration…" }, "chip": { @@ -76,12 +83,20 @@ "stuckHint": "Taking longer than usual. The device may be in CLI / bootloader mode, or the firmware isn't responding to config requests.", "cancel": "Cancel" }, + "status": { + "reconnecting": "reconnecting {{attempt}}/{{max}}" + }, "errors": { "certNotTrusted": "Self-signed certificate not trusted. Open {{url}} in a new tab, accept the security warning, then return here and try again.", "httpsNotReachable": "HTTPS endpoint not reachable. Check that the device is online.", "httpNotReachable": "HTTP endpoint not reachable (may be blocked by CORS or a network issue)", "openInNewTab": "Open in new tab →", - "firmwareTooOld": "Firmware {{version}} is too old for the web client. Update the radio to {{minimum}} or newer." + "firmwareTooOld": "Firmware {{version}} is too old for the web client. Update the radio to {{minimum}} or newer.", + "localNetworkDenied": "Chrome blocked local network access for this site. Click the site-info icon in the address bar, allow Local network, then Connect.", + "localNetworkPrompt": "Chrome needs your permission to reach the local network. Click Connect to allow it.", + "handshakeTimeout": "The radio stopped responding during the handshake. It may be in CLI or bootloader mode, or its firmware isn't answering config requests.", + "reconnectFailed": "Could not reconnect after {{attempts}} attempts.", + "connectionLost": "The connection to the radio was lost." }, "httpTest": { "certNotTrusted": "Certificate not trusted. <0>Open in new tab and accept the warning, then test again." diff --git a/apps/web/public/i18n/locales/en/ui.json b/apps/web/public/i18n/locales/en/ui.json index 802a113e8..9892da8e8 100644 --- a/apps/web/public/i18n/locales/en/ui.json +++ b/apps/web/public/i18n/locales/en/ui.json @@ -368,5 +368,11 @@ "copyright": "Meshtastic® Copyright Meshtastic LLC", "licenseNotice": "Free software under the GNU General Public License v3, with no warranty. You may redistribute it under the same license." } + }, + "tabLock": { + "title": "Meshtastic is open in another tab", + "description": "Only one tab can use your radio and saved data at a time. Use it here to move Meshtastic to this tab and disconnect the other one.", + "useHere": "Use here", + "claiming": "Switching to this tab…" } } diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 18f5b9c54..26ad51477 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -2,6 +2,7 @@ import { DeviceWrapper } from "@app/DeviceWrapper.tsx"; import { BeaconOfferNotifier } from "@components/BeaconOfferNotifier.tsx"; import { CommandPalette } from "@components/CommandPalette/index.tsx"; import { ConnectingOverlay } from "@components/ConnectingOverlay.tsx"; +import { ConnectionsDrawer } from "@components/ConnectionsDrawer/ConnectionsDrawer.tsx"; import { DialogManager } from "@components/Dialog/DialogManager.tsx"; import { LockdownGate } from "@components/Dialog/LockdownDialog/LockdownDialog.tsx"; import { RegionSetupReminder } from "@components/RegionSetupReminder.tsx"; @@ -11,8 +12,7 @@ import Footer from "@components/UI/Footer.tsx"; import { useTheme } from "@core/hooks/useTheme.ts"; import { cn } from "@core/utils/cn.ts"; import { SidebarProvider, useAppStore, useDeviceStore } from "@core/stores"; -import { useTotalUnread } from "@meshtastic/sdk-react"; -import { Connections } from "@pages/Connections/index.tsx"; +import { useTotalUnread } from "@core/kmp/hooks"; import { Outlet } from "@tanstack/react-router"; import { TanStackRouterDevtools } from "@tanstack/react-router-devtools"; import { useEffect, useRef } from "react"; @@ -50,6 +50,9 @@ export function App() { during a first-time connect from the Connections screen as well as reconnects from inside the app. */} + {/* The Connections drawer overlays whatever page is showing. With no + device it is forced open and replaces the old full-page screen. */} +
) : ( - <> - -