betaflight-configurator icon indicating copy to clipboard operation
betaflight-configurator copied to clipboard

Add initial Tauri v2 support

Open haslinghuis opened this issue 8 months ago โ€ข 8 comments

This pull request introduces the integration of Tauri into the project, along with some configuration and dependency updates. The most important changes include adding new scripts and dependencies to package.json, creating Tauri-specific configuration files, and updating build settings in vite.config.js.

  • Tauri is preferred over Electron
  • Both Electron as Tauri 2.x do not support mobile
  • Keep Capacitor implementation for now

Requirements

# Update your system
sudo apt update && sudo apt upgrade -y

sudo apt install pkg-config
sudo apt install libwebkit2gtk-4.1-dev build-essential curl wget file libssl-dev libgtk-3-dev
sudo apt install libayatana-appindicator3-dev librsvg2-dev

# Install rust and cargo

# Remove snap rust if present
sudo snap remove rust

# Install via rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

# Start development
yarn && yarn tauri:dev

Docker

echo 'FROM rust:latest
WORKDIR /app
RUN apt-get update && apt-get install -y libwebkit2gtk-4.1-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y nodejs
RUN npm install -g yarn
COPY . .
RUN yarn install
CMD ["yarn", "tauri:dev"]' > Dockerfile

# Build and run the Docker container
docker build -t betaflight-dev .
docker run -it betaflight-dev

Tauri Integration:

  • package.json: Added new scripts for Tauri development and build, and included Tauri dependencies (@tauri-apps/api and @tauri-apps/cli). [1] [2]
  • src-tauri/Cargo.toml: Created a new Cargo configuration file for the Tauri application.
  • src-tauri/build.rs: Added a build script for Tauri.
  • src-tauri/src/main.rs: Set up the main entry point for the Tauri application.
  • src-tauri/tauri.conf.json: Created a Tauri configuration file with application settings and build commands.

Build Configuration:

  • vite.config.js: Updated the build output directory and added an alias for the src directory. [1] [2]

Summary by CodeRabbit

  • New Features

    • Added support for building and running the application as a Tauri-based desktop app, including new scripts and dependencies.
    • Introduced detection for Tauri environments to improve native compatibility checks.
  • Chores

    • Updated configuration files and build settings to support Tauri, including new manifest and config files.
    • Enhanced .gitignore to exclude Tauri build artifacts.
    • Improved build output directory management and module aliasing in the build configuration.

haslinghuis avatar Mar 11 '25 19:03 haslinghuis

Deploy Preview for origin-betaflight-app ready!

Name Link
Latest commit 6e96780ddf62be70379e208dea14a4723eb5aba6
Latest deploy log https://app.netlify.com/sites/origin-betaflight-app/deploys/67eb037d01c55000084a875e
Deploy Preview https://deploy-preview-4379.dev.app.betaflight.com
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Mar 11 '25 19:03 netlify[bot]

I haven't tested it, but two questions or confirmations:

  • the instructions to build are for Linux. I suppose we can use other OS like windows for example to develop.
  • if we merge this, we need to revert all the capacitor code. I suppose that this is only a test and for this reason it does not do that

I'm right?

McGiverGim avatar Mar 12 '25 08:03 McGiverGim

For now this is for evaluation purpose

haslinghuis avatar Mar 12 '25 14:03 haslinghuis

I'm new to PWA , I want use tauri to communite with mavsdk , I want to base this project, I have no idea with this PWA , I don't know how to add tauri callback in this PWA,Can you give me some ideas.

hcws avatar Mar 23 '25 08:03 hcws

Walkthrough

Adds Tauri desktop/mobile integration and native Tauri serial transport, updates frontend runtime detection and serial wiring, introduces Android/Tauri npm scripts and dependencies, adds Docker and Android build tooling and docs, adjusts Vite/ESLint/.gitignore, and restructures CI/release GitHub Actions.

Changes

Cohort / File(s) Summary
Tauri core & manifests
src-tauri/Cargo.toml, src-tauri/build.rs, src-tauri/src/main.rs, src-tauri/src/lib.rs, src-tauri/tauri.conf.json, src-tauri/capabilities/default.json
Add Tauri Rust manifest, build script, desktop and mobile entry points, tauri config and capability descriptor; register plugins (shell, conditional serialplugin) and declare features/permissions.
Native serial transport & frontend wiring
src/js/protocols/TauriSerial.js, src/js/serial.js, src/js/port_handler.js, src/js/utils/checkBrowserCompatibility.js
Add TauriSerial protocol file; detect isTauri() at runtime; load/prioritize tauriserial; add Serial.init and event-forwarding helper; add PortHandler.serialProtocol and update permission/device flows.
NPM scripts, deps & config
package.json, vite.config.js, eslint.config.js, .gitignore
Add Android emulator/ADB and Tauri npm scripts; add @tauri-apps/api and @tauri-apps/cli deps; set Vite build/HMR/server options; expand ESLint ignores and Vue plugin wiring; ignore src-tauri build artifacts.
Android & Docker tooling + docs
Dockerfile, android-env.sh, ANDROID.md, DOCKER.md
Add Debian-based Dockerfile with Rust/Android/Node toolchains; Android SDK/NDK env script; comprehensive Android and Docker developer guides.
CI / GitHub Actions
.github/workflows/ci.yml, .github/workflows/ci-test.yml, .github/workflows/release.yml, .github/workflows/artifact-links.yml
Make Docker build optional via run_docker_build input; rename main job to node-ci; add optional docker-build job with Dockerfile detection/artifact export; add ci-test wrapper; restructure release workflow into desktop/android/publish jobs; adjust triggers and artifact handling.
Frontend runtime & packaging tweaks
vite.config.js, .gitignore, eslint.config.js
Add Vite outDir/emptyOutDir, dev HMR/server host settings; expand ESLint ignores to include dist paths; update .gitignore to exclude src-tauri/target/ and src-tauri/gen/.

Sequence Diagram(s)

sequenceDiagram
    participant App as Betaflight App (UI)
    participant PortHandler as PortHandler
    participant Serial as Serial Manager
    participant Protocol as Protocol (TauriSerial / WebSerial)
    participant Backend as Backend (Tauri / Browser)

    App->>PortHandler: initialize()
    PortHandler->>PortHandler: detect runtime (isTauri)
    PortHandler->>Serial: selectProtocol()

    alt Tauri runtime
        Serial->>Serial: async load TauriSerial
        Serial->>Protocol: instantiate TauriSerial
        Protocol->>Backend: queryAvailablePorts()
    else Web runtime
        Serial->>Protocol: use WebSerial
        Protocol->>Backend: requestPort()/enumerate()
    end

    Serial->>Serial: setup event forwarding
    Protocol-->>Serial: emit addedDevice/removedDevice/connect/receive
    Serial-->>App: forward device/events (include protocolType)

    App->>PortHandler: connect(port)
    PortHandler->>Serial: connect(port)
    Serial->>Protocol: connect(path, options)
    Protocol->>Backend: openPort(path, baudRate)
    Protocol->>Protocol: startReadLoop()

    loop Data reception
        Protocol->>Backend: poll/read data
        Backend-->>Protocol: data (Uint8Array)
        Protocol->>Serial: emit receive(data)
        Serial-->>App: forward data
    end

    App->>PortHandler: send(data)
    PortHandler->>Serial: send(data)
    Serial->>Protocol: write(data)
    Protocol->>Backend: writePort(data)

Estimated code review effort

๐ŸŽฏ 4 (Complex) | โฑ๏ธ ~60 minutes

Areas needing extra attention:

  • src/js/protocols/TauriSerial.js โ€” read loop, batching, error handling, device detection and monitoring.
  • src/js/serial.js & src/js/port_handler.js โ€” async init sequencing, event-forwarding helper, protocol prioritization/fallback behavior.
  • src-tauri/* โ€” Cargo manifest features, plugin registration, capability permissions and platform guards.
  • Dockerfile / android-env.sh โ€” SDK/NDK installation steps, environment variables and permissions.
  • .github/workflows/* โ€” conditional Docker detection, artifact creation/publishing across jobs.

Possibly related issues

  • betaflight/betaflight-configurator#4499 โ€” Implements Tauri 2.0 support and tauri-plugin-serial integration; aligns with this PRโ€™s Tauri manifests and tauriserial wiring.

Pre-merge checks and finishing touches

โŒ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
โœ… Passed checks (2 passed)
Check name Status Explanation
Title Check โœ… Passed The pull request title "Add native support for desktop and android (Tauri)" accurately and comprehensively summarizes the main changes in the changeset. The PR introduces a complete Tauri v2 integration with desktop support (main.rs, Cargo.toml, tauri.conf.json, Windows subsystem configuration) and Android support (mobile entry point in lib.rs, Android emulator management scripts, ANDROID.md documentation), plus supporting infrastructure (Docker build environment, updated package.json scripts and dependencies, protocol implementation for TauriSerial, and CI/CD workflow updates). The title is concise, specific (naming both platforms and the framework), and clearly communicates the primary scope without vague terminology or noise.
Description Check โœ… Passed The pull request description provides a comprehensive overview of the Tauri v2 integration effort, including a clear summary of changes, rationale (Tauri preference over Electron), relevant documentation references, and detailed setup instructions for both system requirements and Docker environments. The template text has been properly removed, and the description includes substantive file-by-file details with links to specific changes. However, the description lacks an explicit issue reference in the form "Fixes #" that would automatically link to and close related issues upon merge, and the organization could be more streamlined for easier review.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jun 03 '25 14:06 coderabbitai[bot]

First linux debian artifact: https://github.com/betaflight/betaflight-configurator/actions/runs/18810125440/artifacts/4372439098

haslinghuis avatar Oct 26 '25 00:10 haslinghuis

Quality Gate Failed Quality Gate failed

Failed conditions
4 Security Hotspots

See analysis details on SonarQube Cloud

sonarqubecloud[bot] avatar Oct 26 '25 01:10 sonarqubecloud[bot]

Preview URL: https://pr4379.betaflight-app-preview.pages.dev

github-actions[bot] avatar Oct 26 '25 01:10 github-actions[bot]