Skip to content

Conversation

@haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Mar 11, 2025

What

This pull request introduces the integration of Tauri into the project, along with some configuration and dependency updates.

How

The most important changes include

  • adding new scripts and dependencies to package.json
  • creating Tauri-specific configuration files
  • updating build settings in vite.config.js.
  • added DockerFile so developers can use the same environment (needs testing)
  • See DOCKER.MD

Why

  • Tau-ri is preferred over Electron (as Electron would basically be the counterpart of NW.js)
  • Focus is on adding serial, DFU, TCP (MDNS) on Android
  • IMO desktop support would only be useful for SITL

Todo

  • implement serial connection, raw tcp for Android at first
  • update YAML for CI
  • update comments below

References

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:

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

    • Add Tauri desktop support: dev/build scripts, runtime integration, and environment detection for desktop.
    • Desktop window defaults and shell capability enabled for opening external resources.
  • Chores

    • Add Tauri configuration, manifest, build integration, and capability descriptor for bundling (deb/AppImage).
    • Update project build output directory and module aliasing; ignore Tauri build artifacts.

@haslinghuis haslinghuis added the dependencies Pull requests that update a dependency file label Mar 11, 2025
@haslinghuis haslinghuis added this to the 11.0 milestone Mar 11, 2025
@haslinghuis haslinghuis self-assigned this Mar 11, 2025
@netlify
Copy link

netlify bot commented Mar 11, 2025

Deploy Preview for origin-betaflight-app ready!

Name Link
🔨 Latest commit 6e96780
🔍 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.

@haslinghuis haslinghuis moved this to App in 2025.12.0 Mar 11, 2025
@McGiverGim
Copy link
Member

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?

@haslinghuis
Copy link
Member Author

For now this is for evaluation purpose

@hcws
Copy link

hcws commented Mar 23, 2025

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.

@sonarqubecloud
Copy link

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

Adds Tauri 2.0 desktop integration: new src-tauri Rust app and config, Tauri npm scripts and dependencies, frontend Tauri detection, Vite output/alias adjustments, and .gitignore entries for Tauri artifacts.

Changes

Cohort / File(s) Change Summary
Ignore rules
/.gitignore
Added ignore entries for Tauri build artifacts: src-tauri/target/, src-tauri/gen/.
NPM scripts & deps
package.json
Added tauri:dev and tauri:build scripts; added @tauri-apps/api and @tauri-apps/cli dependencies; minor formatting tweak.
Tauri Rust project
src-tauri/Cargo.toml, src-tauri/build.rs, src-tauri/src/main.rs
New Cargo manifest with package metadata, build/runtime deps and features; minimal build.rs calling tauri_build::build(); main.rs builds/runs a Tauri app and registers tauri_plugin_shell.
Tauri config & capabilities
src-tauri/tauri.conf.json, src-tauri/capabilities/default.json
Added Tauri config (product metadata, build/dev commands, bundle targets, window settings, plugin allowlist) and a default capability descriptor granting core:default and shell:allow-open.
Frontend runtime detection
src/js/utils/checkBrowserCompatibility.js
Added exported isTauri() (checks window["__TAURI_INTERNALS__"]) and included it in native-platform detection (`Capacitor.isNativePlatform()
Build config
vite.config.js
Set outDir to dist, enabled emptyOutDir, and added alias @src.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TauriRust as Tauri (Rust)
    participant Frontend as Frontend (JS)
    participant OS

    User->>TauriRust: launch desktop app
    TauriRust->>Frontend: load frontend in webview
    Frontend->>Frontend: checkBrowserCompatibility()
    alt running in Tauri
        Frontend->>Frontend: isTauri() == true
        Frontend->>TauriRust: invoke @tauri-apps/api / plugin calls
        TauriRust->>OS: perform native operations (plugins)
        OS-->>TauriRust: native responses
        TauriRust-->>Frontend: return results
    else running in browser
        Frontend->>Frontend: continue browser/web flow
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Suggested labels

RN: BUILD SYSTEM

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 title "Add initial Tauri v2 support" is clear, concise, and directly describes the primary change in this pull request. It accurately reflects the main objective—integrating Tauri v2 framework into the project—as evidenced by the comprehensive additions across multiple files (Cargo.toml, main.rs, tauri.conf.json, package.json dependencies, etc.). The title is specific enough that someone reviewing the commit history would immediately understand this introduces Tauri framework support.
Description Check ✅ Passed The PR description provides comprehensive coverage of the changes being introduced, with clear "What," "How," and "Why" sections that explain the Tauri integration, associated setup requirements, and the rationale for preferring Tauri over Electron. The description includes detailed information about system requirements, Docker configuration, specific files changed, and references to relevant documentation. However, the description does not include issue references in the form "Fixes #" and does not explicitly acknowledge adherence to coding style guidelines as mentioned in the template. These omissions are relatively minor given the overall quality and completeness of the description provided.
✨ 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]
coderabbitai bot previously requested changes Jun 3, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src-tauri/src/main.rs (1)

6-11: Consider improving error handling for production use.

The main function structure is correct and follows Tauri best practices. However, using .expect() will cause the application to panic on startup errors.

For production use, consider implementing more graceful error handling:

fn main() {
-    tauri::Builder::default()
-        .plugin(tauri_plugin_shell::init())
-        .run(tauri::generate_context!())
-        .expect("error while running tauri application");
+    if let Err(e) = tauri::Builder::default()
+        .plugin(tauri_plugin_shell::init())
+        .run(tauri::generate_context!()) {
+        eprintln!("Failed to start application: {}", e);
+        std::process::exit(1);
+    }
}

Given this is experimental/evaluation code, the current approach is acceptable for now.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1809bb8 and 31e7be6.

⛔ Files ignored due to path filters (3)
  • src-tauri/Cargo.lock is excluded by !**/*.lock
  • src-tauri/icons/bf_icon_128.png is excluded by !**/*.png
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • .gitignore (1 hunks)
  • package.json (2 hunks)
  • src-tauri/Cargo.toml (1 hunks)
  • src-tauri/build.rs (1 hunks)
  • src-tauri/src/main.rs (1 hunks)
  • src-tauri/tauri.conf.json (1 hunks)
  • src/js/utils/checkBrowserCompatibility.js (1 hunks)
  • vite.config.js (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src-tauri/src/main.rs (1)
src-tauri/build.rs (1)
  • main (1-3)
src-tauri/build.rs (1)
src-tauri/src/main.rs (1)
  • main (6-11)
🔇 Additional comments (16)
.gitignore (1)

45-47: LGTM! Standard Tauri ignore patterns added.

The added entries correctly exclude Tauri build artifacts:

  • src-tauri/target/ for Rust/Cargo compilation artifacts
  • src-tauri/gen/ for Tauri-generated code

These are essential for keeping build outputs out of version control.

src-tauri/build.rs (1)

1-3: LGTM! Standard minimal Tauri build script.

This is the correct minimal implementation for a Tauri build script. The tauri_build::build() call handles all necessary Tauri-specific build steps during compilation.

vite.config.js (2)

59-60: LGTM! Build configuration aligned with Tauri requirements.

The explicit outDir: "dist" and emptyOutDir: true settings ensure that the frontend build outputs are correctly placed and cleaned for Tauri consumption.


120-120: LGTM! Convenient alias for source directory.

The "@": resolve(__dirname, "src") alias provides a clean way to reference the source directory in imports, which is a common pattern in Vue.js projects.

src-tauri/src/main.rs (1)

1-4: LGTM! Correct Windows subsystem configuration.

The conditional compilation attribute properly suppresses the console window on Windows in release builds, which is appropriate for a desktop GUI application.

src/js/utils/checkBrowserCompatibility.js (2)

63-65: LGTM! Standard Tauri detection implementation.

The function correctly uses the __TAURI_INTERNALS__ global variable to detect when running in a Tauri environment, which is the recommended approach according to Tauri documentation.


73-73: Good integration with existing platform detection.

Correctly treats Tauri as a native platform alongside Capacitor, which makes sense since both provide native desktop/mobile app capabilities that don't require web browser APIs like WebSerial or WebUSB.

src-tauri/tauri.conf.json (3)

25-28:

❓ Verification inconclusive

Bundle targets are Linux-focused - confirm platform strategy.

The bundle configuration only targets Linux packages (deb, appimage). Given that the PR mentions this is for evaluation purposes, confirm whether Windows and macOS targets will be added later or if Linux-only distribution is intentional.


🌐 Web query:

What are the recommended bundle targets for Tauri v2 cross-platform desktop applications?

💡 Result:

In Tauri v2, when configuring your cross-platform desktop application, you can specify the bundle targets in the tauri.conf.json configuration file under the bundle section. The targets property defines the formats in which your application will be bundled. By default, this is set to "all", which includes all available targets. You can customize this to include specific targets as needed.

The available bundle targets are:

  • Windows:

    • "nsis": NSIS installer (.exe)
    • "msi": Microsoft Installer (.msi)
    • "app": Windows application bundle (.app)
    • "dmg": Apple Disk Image (.dmg)
  • macOS:

    • "app": macOS application bundle (.app)
    • "dmg": Apple Disk Image (.dmg)
  • Linux:

    • "deb": Debian package (.deb)
    • "rpm": RPM package (.rpm)
    • "appimage": AppImage bundle (.appimage)
  • Cross-Platform:

    • "all": Bundles all available targets

To specify the bundle targets in your tauri.conf.json file, you can set the targets property under the bundle section. For example, to bundle your application for Windows and macOS, you would configure it as follows:

{
  "bundle": {
    "targets": ["nsis", "app", "dmg"]
  }
}

This configuration will generate installers for Windows (.exe), and application bundles for macOS (.app and .dmg). For a comprehensive list of all available bundle targets and their configurations, refer to the Tauri documentation. (tauri.app)

Citations:


Clarify cross-platform bundle targets

Currently in src-tauri/tauri.conf.json (around lines 25–28) your bundle targets are set to:

"bundle": {
  "active": true,
  "targets": ["deb", "appimage"],
  "icon": ["icons/bf_icon_128.png"]
}

– those are Linux-only formats. Tauri v2 also supports Windows ("nsis", "msi", "app", "dmg") and macOS ("app", "dmg") bundles, or a single "all" target to cover everything.

Please confirm whether you intend to ship Linux-only (for evaluation) or if you’ll add Windows/macOS targets (or switch to "all") before release.


5-9:

✅ Verification successful

Verify build commands consistency.

The build commands reference yarn dev and yarn build scripts. Ensure these correspond to the scripts defined in package.json and that the development server runs on the configured port (8000).


🏁 Script executed:

#!/bin/bash
# Verify that the referenced yarn scripts exist in package.json
echo "Checking for yarn scripts referenced in tauri.conf.json..."
jq -r '.scripts | keys[]' package.json | grep -E "^(dev|build)$" || echo "Missing required scripts"

# Check if dev script uses port 8000
echo "Checking dev script configuration..."
jq -r '.scripts.dev' package.json

Length of output: 325


🏁 Script executed:

#!/bin/bash
# Locate any Vite config files in the repo
echo "Locating vite config files..."
vite_configs=$(fd -t f -H "vite.config.*")
if [ -z "$vite_configs" ]; then
  echo "No vite.config.* files found."
else
  for cfg in $vite_configs; do
    echo "Inspecting $cfg for server port settings:"
    grep -R "server" -n "$cfg" -A3 || echo "No 'server' block in $cfg"
    grep -R "port" -n "$cfg" || echo "No explicit port setting in $cfg"
  done
fi

Length of output: 1222


Build commands and devUrl verified

  • Both dev and build scripts exist in package.json.
  • The Vite dev server is explicitly configured with
    server: {
      port: 8000,
      strictPort: true,
    }
    which matches "devUrl": "http://localhost:8000" in tauri.conf.json.
  • The frontend build output defaults to dist, so "frontendDist": "../dist" is correct.

No changes required.


30-34:

❓ Verification inconclusive

Shell plugin enabled - verify security implications.

The shell plugin with open: true allows the application to execute system commands and open files/URLs. Ensure this is necessary for the application's functionality and that proper input validation is implemented wherever this plugin is used.


🏁 Script executed:

#!/bin/bash
# Search for usage of Tauri shell plugin in the codebase
echo "Searching for shell plugin usage..."
rg -A 3 -B 3 "shell|invoke.*shell|@tauri-apps.*shell" --type js

Length of output: 146


This will confirm whether the shell plugin is actually referenced in your Rust code.


🏁 Script executed:

#!/bin/bash
echo "Searching for shell plugin usage in Rust code..."
# Look for direct imports of the shell plugin
rg -n "use .*shell" --type rs
# Look for any references to the plugin namespace
rg -n "tauri_plugin_shell" --type rs
# Look for any invocation or initialization calls
rg -A3 -B3 "shell::" --type rs

Length of output: 287


🏁 Script executed:

#!/bin/bash
echo "Locating Cargo.toml files..."
find . -maxdepth 4 -type f -name Cargo.toml

echo
echo "Checking for tauri-plugin-shell in Cargo.toml dependencies..."
rg -n "tauri-plugin-shell" -g "*.toml"

echo
echo "Searching Rust source for plugin initialization or references..."
rg -n "tauri_plugin_shell" -g "*.rs"
rg -n "shell::init" -g "*.rs"
rg -n "plugin(" -g "*.rs" | grep shell || true

echo
echo "Searching front-end code for shell plugin invocations..."
rg -n "plugin:shell" -g "*.js" -g "*.ts" -g "*.tsx"

Length of output: 1014


Verify Shell Plugin Necessity and Usage

The Tauri Shell plugin is enabled in your configuration and initialized in the Rust backend, but we didn’t find any front-end invocations. Please confirm whether you actually need this plugin, and if so, ensure every call is properly validated to avoid command injection or unintended file/URL access.

• src-tauri/tauri.conf.json (lines 30–34): "plugins": { "shell": { "open": true } }
• src-tauri/Cargo.toml (line 15): tauri-plugin-shell = "2.0.0"
• src-tauri/src/main.rs (line 8): .plugin(tauri_plugin_shell::init())

If the shell plugin isn’t used, remove it to reduce your attack surface. Otherwise, audit all places where you call into the shell API and enforce strict input validation.

package.json (2)

26-27: LGTM! Standard Tauri script integration.

The script names follow Tauri conventions and integrate well with the existing build workflow. These scripts correspond to the build commands configured in tauri.conf.json.


25-25: Minor modification to prepare script looks correct.

The husky install preparation remains intact, which is good for maintaining git hooks functionality.

src-tauri/Cargo.toml (4)

1-8: Excellent version consistency across the project.

The package metadata properly matches the version (11.0.0) and project details from package.json and tauri.conf.json, ensuring consistency across the Tauri integration.


13-17: Standard and appropriate Tauri dependencies.

The dependency selection is correct for a basic Tauri v2 application:

  • Core Tauri framework
  • Shell plugin for system interactions
  • Serde for JSON serialization (standard for Tauri apps)

19-21: Custom protocol feature is a good security practice.

Enabling the custom-protocol feature is recommended for production Tauri applications as it provides better security than the default localhost-based approach during development.


10-11:

✅ Verification successful

Verify Tauri build dependency version compatibility.

Let's ensure the tauri-build version is compatible with the runtime tauri dependency version (both should be from the same major.minor release).


🌐 Web query:

Are tauri-build 2.0.6 and tauri 2.0.6 compatible versions for Tauri v2 applications?

💡 Result:

Yes, tauri-build 2.0.6 and tauri 2.0.6 are compatible versions for Tauri v2 applications. The Tauri framework follows semantic versioning principles where the major version number is incremented for breaking changes, and minor or patch updates are backward compatible within the same major version. This means you should always be able to safely upgrade to the latest minor or patch versions without compatibility issues between related crates like tauri and tauri-build[2][8].

Specifically, at version 2.0.6, tauri and tauri-build are aligned as part of the Tauri 2.x stable release series, ensuring compatibility for building and running Tauri v2 applications[1][6]. It is recommended to keep the versions of the Tauri core crates (like tauri and tauri-build) in sync, generally using the exact same version number, to avoid any subtle incompatibilities[8].

Therefore, using tauri 2.0.6 together with tauri-build 2.0.6 is the correct approach for Tauri v2 apps.

Citations:


Tauri build dependency version compatibility confirmed

The tauri-build entry in src-tauri/Cargo.toml is already at version 2.0.6, matching the runtime tauri = "2.0.6" release. Since Tauri follows semantic versioning within the 2.x series, these versions are fully compatible—no changes needed.

@haslinghuis haslinghuis force-pushed the tauri branch 2 times, most recently from 2da39ae to 7455b58 Compare June 7, 2025 23:27
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 7, 2025

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27990a4 and 42aeeec.

⛔ Files ignored due to path filters (3)
  • src-tauri/Cargo.lock is excluded by !**/*.lock
  • src-tauri/icons/bf_icon_128.png is excluded by !**/*.png
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • .gitignore (1 hunks)
  • package.json (2 hunks)
  • src-tauri/Cargo.toml (1 hunks)
  • src-tauri/build.rs (1 hunks)
  • src-tauri/capabilities/default.json (1 hunks)
  • src-tauri/src/main.rs (1 hunks)
  • src-tauri/tauri.conf.json (1 hunks)
  • src/js/utils/checkBrowserCompatibility.js (1 hunks)
  • vite.config.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • package.json
  • vite.config.js
  • .gitignore
  • src-tauri/src/main.rs
  • src-tauri/tauri.conf.json
  • src/js/utils/checkBrowserCompatibility.js
🧰 Additional context used
🧬 Code graph analysis (1)
src-tauri/build.rs (1)
src-tauri/src/main.rs (1)
  • main (6-11)
🔇 Additional comments (3)
src-tauri/build.rs (1)

1-3: LGTM! Standard Tauri build script pattern.

This minimal build script is the idiomatic pattern for Tauri applications. Cargo's build system automatically handles any errors from tauri_build::build(), so explicit error handling is not required here.

src-tauri/Cargo.toml (1)

10-21: Update Tauri dependencies to current stable versions.

Current versions (tauri 2.0.6, tauri-build 2.0.6, tauri-plugin-shell 2.0.0) are not affected by any known security advisories, but are significantly outdated. Update to: tauri 2.9.1, tauri-build 2.5.1, tauri-plugin-shell 2.3.1.

src-tauri/capabilities/default.json (1)

6-9: Remove shell:allow-open permission or confirm it is required for future functionality.

The "shell:allow-open" permission is declared in the capabilities but appears to be unused throughout the codebase. The shell plugin is initialized in src-tauri/src/main.rs but no code invokes shell operations—neither in the Rust backend nor the frontend. Granting unused capabilities increases the attack surface unnecessarily. Either remove this permission to harden security, or if it's intended for future functionality, add the necessary invocation code and input validation. If retained, ensure all paths/URLs passed to shell operations are validated and sanitized to prevent shell injection attacks.

@sonarqubecloud
Copy link

@github-actions
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

Status: App

Development

Successfully merging this pull request may close these issues.

3 participants