From e5ed1d3c9f9229a38494bf30a546a8087f64d9b5 Mon Sep 17 00:00:00 2001 From: Devon Bontrager Date: Mon, 8 Jun 2026 11:19:48 -0400 Subject: [PATCH] Add lightweight Tauri shell, vendor offline libs, fix bugs and race conditions - Add tauri/ subfolder: a Tauri-based desktop shell that loads the same index.html as the Electron app, producing a ~2MB installer (vs ~71MB for Electron) by using the OS WebView2 instead of bundled Chromium. Includes sync-frontend.js to keep tauri/dist/ in sync with the canonical index.html and vendor/ at build time (no UI duplication/drift). - Vendor lucide, jsPDF, and jspdf-autotable locally under vendor/ instead of loading from CDNs, so the app works fully offline in both shells. - Fix server.js path traversal vulnerability (sanitize/contain request paths). - Fix exportPDF() using stale/edited piece data that could produce Infinity/NaN in generated PDFs; add a recalculate guard. - Fix race conditions: overlapping copy/save-defaults button revert timers, and FileReader callbacks for logo/CSV import that could apply out of order. - Minor cleanups: explicit array index parsing, hasResult() helper, consistent event binding for NMFC search results, cached DOM lookups. - Document the dual-shell architecture and vendoring conventions in CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 --- .claude/launch.json | 11 + CLAUDE.md | 62 + index.html | 66 +- server.js | 11 +- tauri/.gitignore | 7 + tauri/package.json | 16 + tauri/src-tauri/.gitignore | 4 + tauri/src-tauri/Cargo.lock | 4941 +++++ tauri/src-tauri/Cargo.toml | 25 + tauri/src-tauri/build.rs | 3 + tauri/src-tauri/capabilities/default.json | 11 + tauri/src-tauri/icons/128x128.png | Bin 0 -> 4876 bytes tauri/src-tauri/icons/128x128@2x.png | Bin 0 -> 8857 bytes tauri/src-tauri/icons/32x32.png | Bin 0 -> 1521 bytes tauri/src-tauri/icons/icon.icns | Bin 0 -> 108419 bytes tauri/src-tauri/icons/icon.ico | Bin 0 -> 20329 bytes tauri/src-tauri/icons/icon.png | Bin 0 -> 9965 bytes tauri/src-tauri/src/lib.rs | 16 + tauri/src-tauri/src/main.rs | 6 + tauri/src-tauri/tauri.conf.json | 36 + tauri/sync-frontend.js | 27 + vendor/jspdf.plugin.autotable.min.js | 10 + vendor/jspdf.umd.min.js | 398 + vendor/lucide.js | 19522 ++++++++++++++++++++ 24 files changed, 25160 insertions(+), 12 deletions(-) create mode 100644 .claude/launch.json create mode 100644 CLAUDE.md create mode 100644 tauri/.gitignore create mode 100644 tauri/package.json create mode 100644 tauri/src-tauri/.gitignore create mode 100644 tauri/src-tauri/Cargo.lock create mode 100644 tauri/src-tauri/Cargo.toml create mode 100644 tauri/src-tauri/build.rs create mode 100644 tauri/src-tauri/capabilities/default.json create mode 100644 tauri/src-tauri/icons/128x128.png create mode 100644 tauri/src-tauri/icons/128x128@2x.png create mode 100644 tauri/src-tauri/icons/32x32.png create mode 100644 tauri/src-tauri/icons/icon.icns create mode 100644 tauri/src-tauri/icons/icon.ico create mode 100644 tauri/src-tauri/icons/icon.png create mode 100644 tauri/src-tauri/src/lib.rs create mode 100644 tauri/src-tauri/src/main.rs create mode 100644 tauri/src-tauri/tauri.conf.json create mode 100644 tauri/sync-frontend.js create mode 100644 vendor/jspdf.plugin.autotable.min.js create mode 100644 vendor/jspdf.umd.min.js create mode 100644 vendor/lucide.js diff --git a/.claude/launch.json b/.claude/launch.json new file mode 100644 index 0000000..fe11af8 --- /dev/null +++ b/.claude/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.0.1", + "configurations": [ + { + "name": "freight-calculator", + "runtimeExecutable": "node", + "runtimeArgs": ["server.js"], + "port": 3010 + } + ] +} diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..0472e6d --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,62 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Two desktop shells — same frontend + +This repo ships **two interchangeable desktop shells** that both load the exact same `index.html`: + +1. **Electron** (original, root of repo) — heavier (~70MB installer) but mature/familiar +2. **Tauri** (`tauri/` subfolder) — much lighter (~2MB installer, ~8MB exe) using the OS's built-in WebView2 instead of bundled Chromium + +`index.html` (plus `vendor/`) is the **single source of truth** for the UI — never duplicate or fork it. The Tauri shell's `tauri/dist/` is a *generated* copy (gitignored, rebuilt by `tauri/sync-frontend.js` before each `dev`/`build`run) — edit `index.html` at the repo root, never inside `tauri/dist/`. + +### Electron commands (run from repo root) +- `npm start` — run the app as an Electron desktop window (loads `index.html` via `main.js`) +- `npm run serve` — run a plain Node HTTP server (`server.js`) at http://localhost:3010, serving the same `index.html` for browser-based testing +- `npm run build` — package the Windows installer via `electron-builder` (NSIS, output goes to `dist/`) + +### Tauri commands (run from `tauri/`) +- `npm run dev` — sync the frontend into `tauri/dist/` and launch the Tauri dev shell +- `npm run build` — sync the frontend and produce MSI + NSIS installers (output in `tauri/src-tauri/target/release/bundle/`) +- `npm run serve` — same static server as the Electron side, for browser-based testing +- Requires the Rust toolchain (`rustup`/`cargo`) plus MSVC Build Tools and WebView2 (Tauri prerequisites) — see https://tauri.app/start/prerequisites/ + +There is no test suite, linter, or build step for the app code itself — `index.html` is loaded directly (as a file in Electron/Tauri, or statically served). To verify a change, just reload the app/page in whichever shell you're using. + +## Architecture + +This is a single-page Electron desktop app (also runnable as a static page) for calculating NMFC freight class from shipment dimensions and weight. Almost all logic lives in one file: + +- **`index.html`** — contains everything: markup, CSS (`