Skip to content

Add initial Tauri v2 support #4379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Mar 11, 2025

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:

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 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
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.

@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.

Copy link

Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

This change introduces Tauri 2.0 support to the project. It adds Tauri configuration, build scripts, Rust source files, and updates the JavaScript codebase to detect Tauri as a native platform. The build process and dependencies are adjusted to support building and running the application as a Tauri-based desktop app.

Changes

Files / Groups Change Summary
.gitignore Added ignore rules for Tauri build artifacts (src-tauri/target/ and src-tauri/gen/).
package.json Added Tauri-related scripts and dependencies.
src-tauri/Cargo.toml, src-tauri/build.rs, src-tauri/src/main.rs Introduced Rust manifest, build script, and main entry for Tauri application.
src-tauri/tauri.conf.json Added Tauri application configuration file.
src/js/utils/checkBrowserCompatibility.js Added Tauri detection and updated native platform check logic.
vite.config.js Set build output directory to "dist", enabled output directory cleanup, and added "@" alias for "src".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TauriApp (Rust)
    participant Frontend (JS)
    participant OS

    User->>TauriApp (Rust): Launch application
    TauriApp (Rust)->>Frontend (JS): Initialize webview and load frontend
    Frontend (JS)->>Frontend (JS): checkBrowserCompatibility()
    Frontend (JS)->>Frontend (JS): isTauri() → true
    Frontend (JS)->>TauriApp (Rust): (if needed) Use Tauri API for native features
    TauriApp (Rust)->>OS: Invoke native capabilities (via plugins)
    OS-->>TauriApp (Rust): Respond to native requests
    TauriApp (Rust)-->>Frontend (JS): Return results
Loading

Possibly related issues


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 31e7be6 and 7455b58.

⛔ 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)
🚧 Files skipped from review as they are similar to previous changes (8)
  • src-tauri/build.rs
  • vite.config.js
  • .gitignore
  • src/js/utils/checkBrowserCompatibility.js
  • package.json
  • src-tauri/tauri.conf.json
  • src-tauri/Cargo.toml
  • src-tauri/src/main.rs
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Copy link

sonarqubecloud bot commented Jun 7, 2025

Copy link
Contributor

github-actions bot commented Jun 7, 2025

Preview URL: https://7455b580.betaflight-configurator.pages.dev

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
Development

Successfully merging this pull request may close these issues.

3 participants