Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ jobs:
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: "3.12"
- run: python -m pip install pymodbus==3.16.2
# The serial extra brings pyserial: without it the ASCII serial reference server raises, and
# asyncio.gather stops the TCP servers with it.
- run: python -m pip install "pymodbus[serial]==3.16.2"
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
- uses: Swatinem/rust-cache@e9d7b9f1e587218970671bac74e5511ed9506e6a # v2
with:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ now run on every change, on Linux and Windows.

### Fixed

- Linux: with the C locale (`LANG=C.UTF-8`, common on WSL2, containers and cloud VMs) the window
stayed empty, because the webview reported the language "C" and the chart library refused it.
The webview now gets English when the locale names no language; any other language is kept.
- Dashboards on Modbus TCP or UDP: a block of more than 123 neighbouring registers (3.3.1) was
refused by the master, so its values never updated. Blocks now stop at 123 registers on TCP/UDP
and at 125 on the other links, like the polls.
Expand Down
12 changes: 12 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ data types, byte orders) and backend texts stay in English

## Behavioral rules (apply to every change)

- **READ, THEN PROBE, THEN IMPLEMENT.** No code, CI change or test edit before these steps, in
this order:
1. **Read** the installed source and the documentation of every component involved.
2. **Reproduce** the failure locally, under the conditions where it fails.
3. **Measure** the candidate fix in a throwaway copy (a git worktree outside the repo).

For a CI-only failure, first list how the runner differs from the local run, then try each
difference locally, one at a time: user (root or not), locale (`LANG`), environment variables
exported by setup actions, OS image, library versions. A push is not an experiment: never loop
"add a diagnostic, push, wait for CI". (2026-11-06: six diagnostic pushes went by before the
cause was found locally. The runner is not root and has `LANG=C.UTF-8`; WebKitGTK reported
`navigator.language = "C"` and uPlot threw at load.)
- **NEVER SUPPOSE.** Read code before editing. If uncertain about an API contract, stop and ask.
- **READ THE DOCUMENTATION FIRST — ALWAYS.** Before writing a line against any external system or
library (Tauri, tokio-modbus, serialport, Svelte, the Modbus specification), read its
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ cd src-tauri && cargo fmt --check && cargo clippy --all-targets -- -D warnings &
End-to-end run of the real app against [pymodbus](https://github.com/pymodbus-dev/pymodbus) as an
independent implementation. CI runs it on Linux and Windows (Windows without the serial checks,
which need `socat`). Locally on Linux it needs `tauri-driver`, `WebKitWebDriver`, `socat` and
`pymodbus`:
pymodbus with its serial extra (`pip install "pymodbus[serial]"`):

```sh
npx tauri build --debug --no-bundle
Expand Down
49 changes: 49 additions & 0 deletions docs/superpowers/specs/2026-11-06-linux-locale-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Linux: lingua della webview con locale C

Data: 2026-11-06. Stato: difetto trovato dall'E2E in CI (runner `ubuntu-24.04`, `LANG=C.UTF-8`).

## Il difetto

Con il locale C (`LANG=C.UTF-8`: WSL2, container, VM cloud, runner CI) la finestra resta vuota.
WebKitGTK riporta `navigator.language = "C"`, che non è un tag BCP 47; uPlot 1.6.32 esegue
`new Intl.NumberFormat(nav.language)` quando il suo modulo viene caricato
(`node_modules/uplot/dist/uPlot.esm.js:442`), il bundle lancia
`RangeError: invalid language tag: C` e l'app non si monta.

In locale la suite passava perché girava da root con `LANG` vuoto; da utente non-root con
`LANG=C.UTF-8`, come il runner, il difetto si riproduce.

## Decisioni

| # | Decisione | Fonte |
|---|---|---|
| L1 | Su Linux, nell'hook `setup`, se la prima lingua di `g_get_language_names()` è il locale C o POSIX, la webview riceve `en-US` con `webkit_web_context_set_preferred_languages` | [WebKitGTK](https://webkitgtk.org/reference/webkit2gtk/stable/method.WebContext.set_preferred_languages.html): imposta `navigator.language`, `navigator.languages` e la lingua predefinita di `Intl`. Misura sotto |
| L2 | Con una lingua vera la webview resta com'è | Misura: `en-US` fisso cambiava `it-IT` in `en-US` per un utente italiano |
| L3 | Nessun ritocco di `navigator` nel frontend: il valore si corregge dove nasce | — |

Inventario (versioni installate): wry 0.57.1 e Tauri 2.12.5 non impostano la lingua della webview
né offrono un'opzione per farlo; `webkit2gtk` 2.0.2 (già nell'albero tramite Tauri) espone
`WebContextExt::set_preferred_languages` e ri-esporta `glib` (`language_names`). Tauri crea le
finestre della configurazione e ne avvia il caricamento prima dell'hook `setup`
(`tauri-2.12.5/src/app.rs:2688`): che la chiamata arrivi in tempo andava misurato.

## Misura (2026-11-06, WebKitGTK 2.52.6, Ubuntu 24.04, Xvfb, utente non-root)

`navigator.language`, esito di `Intl.NumberFormat(navigator.language)` e montaggio dell'app,
4 s dopo l'avvio, tramite tauri-driver:

| Ambiente | Prima | Con L1 |
|---|---|---|
| `LANG=C.UTF-8` | `"C"`, `RangeError`, app non montata | `"en-US"`, app montata (3 run su 3) |
| `LANG=POSIX` | `"en-US"`, montata | `"en-US"`, montata |
| `LANG=it_IT.UTF-8` (locale generato) | `"it-IT"`, montata | `"it-IT"`, montata |
| `LANG=en_US.UTF-8` (locale generato) | `"en-US"`, montata | non cambia (L2) |

Suite E2E completa con L1: 88/88 da utente non-root con `LANG=C.UTF-8`, 88/88 da root.

## Cosa NON è dimostrato

- Solo WebKitGTK 2.52.6: altre versioni possono derivare `navigator.language` in altro modo.
- Non provato su WSL2 né su una sessione desktop reale (solo Xvfb).
- Con un locale non installato WebKit ha riportato `"en-US"`: senza i locale `it_IT` ed `en_US`
generati, le misure con quei `LANG` non rappresentavano un utente reale.
28 changes: 28 additions & 0 deletions docs/superpowers/verification/2026-11-06-linux-locale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Verifica: lingua della webview con locale C (Linux)

Data: 2026-11-06. Spec: `docs/superpowers/specs/2026-11-06-linux-locale-design.md`.

## Cosa è stato misurato

- **Riproduzione del difetto**: build debug senza correzione, utente non-root, `LANG=C.UTF-8`,
Xvfb. `navigator.language = "C"`, `Intl.NumberFormat("C")` lancia `RangeError`, `#app` vuoto.
Reimportando il bundle con un parametro diverso, l'errore viene da `NumberFormat` nel codice di
modulo di uPlot.
- **Correzione**: stessa macchina, build debug con `src-tauri/src/webview_locale.rs`.
- `LANG=C.UTF-8` → `"en-US"`, app montata.
- `LANG=POSIX` → `"en-US"`, app montata.
- `LANG=it_IT.UTF-8` → `"it-IT"` invariato, app montata.
- **E2E completo contro pymodbus** (`node e2e/run.mjs`):
- 88/88 da utente non-root con `LANG=C.UTF-8`, le condizioni del runner CI;
- 88/88 da root.
- **Test unitari**: `fallback_language` per C, C.UTF-8, C.utf8, POSIX, C@euro (→ `en-US`) e per
it_IT, en_US, de, ca_ES e una lista vuota (→ nessun cambio).
- **Gate**: `cargo fmt --check`, `cargo clippy -D warnings`, `cargo llvm-cov` al 93,7% delle
righe. `apply()` non è coperta da test unitari, perché richiede una webview; la copre l'E2E.

## Cosa NON dimostra

- Solo WebKitGTK 2.52.6 su Ubuntu 24.04 sotto Xvfb: non WSL2, non una sessione desktop reale.
- `cargo mutants` non eseguito su `webview_locale.rs`: il file non tocca il protocollo, il framing
né le conversioni dei tipi, e la sua unica decisione è coperta dai test qui sopra.
- La CI su questo commit è la prima prova sul runner reale.
4 changes: 2 additions & 2 deletions e2e/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
// npx tauri build --debug --no-bundle && node e2e/run.mjs [screenshot-dir]
//
// Needs: tauri-driver, the platform's WebDriver, python with pymodbus; on Linux also socat (the
// serial checks) and an X display. Windows runs every check but the serial ones.
// Needs: tauri-driver, the platform's WebDriver, python with pymodbus[serial]; on Linux also socat
// (the serial checks) and an X display. Windows runs every check but the serial ones.

import { remote } from "webdriverio";
import { spawn } from "node:child_process";
Expand Down
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ tauri = { version = "2", features = ["test"] }
[target.'cfg(any(target_os = "macos", windows, target_os = "linux"))'.dependencies]
tauri-plugin-process = "2.4"
tauri-plugin-updater = "2.14"

# The webview's language under a C locale (src/webview_locale.rs); the version Tauri already uses.
[target.'cfg(target_os = "linux")'.dependencies]
webkit2gtk = "2.0"
3 changes: 3 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod poller;
pub mod slave;
pub mod slave_server;
pub mod traffic;
pub mod webview_locale;

use tauri::Manager;

Expand All @@ -15,6 +16,8 @@ pub fn run() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init())
.setup(|app| {
#[cfg(target_os = "linux")]
webview_locale::apply(app)?;
#[cfg(desktop)]
{
app.handle()
Expand Down
70 changes: 70 additions & 0 deletions src-tauri/src/webview_locale.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//! The webview's language under a C or POSIX locale, on Linux.
//!
//! With `LANG=C.UTF-8` (WSL2, containers, CI runners) WebKitGTK reports `navigator.language` as
//! "C", which is not a BCP 47 tag: uPlot builds `Intl.NumberFormat(navigator.language)` when its
//! module loads, the bundle throws, and the window stays empty. Measured on WebKitGTK 2.52.6,
//! docs/superpowers/specs/2026-11-06-linux-locale-design.md.

/// The language to give the webview when the user's first language is the C or POSIX locale,
/// which names no language; `None` keeps WebKit's own choice.
pub fn fallback_language<S: AsRef<str>>(language_names: &[S]) -> Option<&'static str> {
let first = language_names.first()?.as_ref();
let locale = first.split(['.', '@']).next().unwrap_or(first);
matches!(locale, "C" | "POSIX").then_some("en-US")
}

/// Sets the main window's preferred language when the locale names none. It runs in `setup`,
/// after Tauri has started loading the page, and still reaches it (measured).
/// <https://webkitgtk.org/reference/webkit2gtk/stable/method.WebContext.set_preferred_languages.html>
#[cfg(target_os = "linux")]
pub fn apply(app: &tauri::App) -> tauri::Result<()> {
use tauri::Manager;
use webkit2gtk::{glib, WebContextExt, WebViewExt};

let names = glib::language_names();
let (Some(language), Some(window)) =
(fallback_language(&names), app.get_webview_window("main"))
else {
return Ok(());
};
window.with_webview(move |webview| {
if let Some(context) = webview.inner().context() {
context.set_preferred_languages(&[language]);
}
})
}

#[cfg(test)]
mod tests {
use super::fallback_language;

#[test]
fn the_c_and_posix_locales_get_english() {
for names in [
&["C.UTF-8", "C"][..],
&["C.utf8", "C"],
&["C"],
&["POSIX"],
&["C@euro", "C"],
] {
assert_eq!(fallback_language(names), Some("en-US"), "{names:?}");
}
}

#[test]
fn a_named_language_is_kept() {
for names in [
&["it_IT.UTF-8", "it_IT", "it.UTF-8", "it", "C"][..],
&["en_US.UTF-8", "en_US", "en", "C"],
&["de", "en_US", "en", "C"],
&["ca_ES.UTF-8", "ca_ES", "ca", "C"],
] {
assert_eq!(fallback_language(names), None, "{names:?}");
}
}

#[test]
fn no_names_keeps_webkit_choice() {
assert_eq!(fallback_language::<&str>(&[]), None);
}
}
Loading