-
-
Notifications
You must be signed in to change notification settings - Fork 998
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for origin-betaflight-app ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
I haven't tested it, but two questions or confirmations:
I'm right? |
For now this is for evaluation purpose |
4ba0507
to
eff5f85
Compare
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. |
|
WalkthroughAdds Tauri 2.0 desktop integration: new Changes
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: call native APIs via @tauri-apps/api
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
✨ Finishing Touches🧪 Generate unit tests
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. Comment |
There was a problem hiding this 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
⛔ 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 artifactssrc-tauri/gen/
for Tauri-generated codeThese 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"
andemptyOutDir: 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 thebundle
section. Thetargets
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 targetsTo specify the bundle targets in your
tauri.conf.json
file, you can set thetargets
property under thebundle
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
andyarn 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.jsonLength 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 fiLength of output: 1222
Build commands and devUrl verified
- Both
dev
andbuild
scripts exist in package.json.- The Vite dev server is explicitly configured with
which matchesserver: { port: 8000, strictPort: true, }"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 jsLength 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 rsLength 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
andtauri.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:
- 1: https://v2.tauri.app/blog/tauri-20/
- 2: https://v2.tauri.app/develop/configuration-files/
- 3: https://github.com/tauri-apps/tauri
- 4: tauri-apps/tauri#8813
- 5: https://v2.tauri.app/distribute/windows-installer/
- 6: https://tauri.app/release/@tauri-apps/cli/v2.0.0-alpha.6/
- 7: tauri-apps/tauri#9039
- 8: https://v2.tauri.app/develop/updating-dependencies/
- 9: tauri-apps/tauri#8563
- 10: https://v2.tauri.app/plugin/updater/
Tauri build dependency version compatibility confirmed
The tauri-build entry in
src-tauri/Cargo.toml
is already at version 2.0.6, matching the runtimetauri = "2.0.6"
release. Since Tauri follows semantic versioning within the 2.x series, these versions are fully compatible—no changes needed.
2da39ae
to
7455b58
Compare
|
There was a problem hiding this 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
♻️ Duplicate comments (1)
src-tauri/tauri.conf.json (1)
12-14
: CSP deliberately disabled — acknowledged.Prior discussion concluded CSP
null
is acceptable given the app only talks to local devices. Keeping as-is is fine; consider revisiting if any remote content is introduced.Refs: Tauri v2 security config and CSP guidance. (v2.tauri.app, tauri.app)
🧹 Nitpick comments (3)
src-tauri/tauri.conf.json (3)
2-4
: Align product naming and versioning.
- Consider using the project’s canonical name (“Betaflight Configurator”) for
productName
to keep bundles and window titles consistent.- Ensure
version
here stays in sync with your JS/Rust package versions to avoid mismatch in update flows.
15-23
: Window UX polish: set minimum size and persist window state.
- Add
minWidth
/minHeight
to prevent unusably small windows.- Optionally adopt the window-state plugin to restore size/position on relaunch.
{ "title": "Betaflight App", "width": 1024, "height": 550, + "minWidth": 900, + "minHeight": 500, "resizable": true, "fullscreen": false }
25-29
: Bundling targets and icons: broaden platform support and supply platform-native icons.
- If you plan Windows/macOS releases, include their targets (e.g.,
nsis
/msi
,dmg
/app
). Alternatively, omittargets
to let Tauri pick the host-OS default.- Provide .ico (Windows) and .icns (macOS) plus multiple PNG sizes for best results.
"bundle": { "active": true, - "targets": ["deb", "appimage"], - "icon": ["icons/bf_icon_128.png"] + "targets": ["deb", "appimage", "nsis", "msi", "dmg", "app"], + "icon": [ + "icons/bf_icon_32.png", + "icons/bf_icon_128.png", + "icons/bf_icon_256.png", + "icons/icon.icns", + "icons/icon.ico" + ] },Refs: Tauri config reference for bundle targets/icons. (tauri.app)
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (2)
src-tauri/Cargo.lock
is excluded by!**/*.lock
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (4)
package.json
(2 hunks)src-tauri/Cargo.toml
(1 hunks)src-tauri/tauri.conf.json
(1 hunks)src/js/utils/checkBrowserCompatibility.js
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- src-tauri/Cargo.toml
- src/js/utils/checkBrowserCompatibility.js
- package.json
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-07T23:27:01.841Z
Learnt from: haslinghuis
PR: betaflight/betaflight-configurator#4379
File: src-tauri/tauri.conf.json:12-14
Timestamp: 2025-06-07T23:27:01.841Z
Learning: Betaflight Configurator only connects with local embedded devices (flight controllers), not external web resources, which affects the security threat model and CSP requirements.
Applied to files:
src-tauri/tauri.conf.json
|
Preview URL: https://27990a45.betaflight-configurator.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src-tauri/capabilities/default.json (2)
5-5
: Scope the capability to the main window instead of all windows.Principle of least privilege; avoid granting shell access to future/aux windows by default.
- "windows": ["*"], + "windows": ["main"],
6-9
: Prefer the Opener plugin over Shell for URL opening and add an allowlist.Opener provides finer-grained URL scoping (e.g., only https or specific hosts). If you adopt it, replace the shell permission and add explicit URL patterns. (tauri.app)
Option B (requires adding tauri-plugin-opener and @tauri-apps/plugin-opener, and initializing the plugin):
"permissions": [ - "core:default", - "shell:allow-open" + "core:default", + { + "identifier": "opener:allow-open-url", + "allow": [ + { "url": "https://*" } + ] + } ]Note: If you stay on Shell,
shell:allow-open
allows opening http(s), tel, and mailto by default; Opener offers more explicit URL scoping. (tauri.app)
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
src-tauri/capabilities/default.json
(1 hunks)src-tauri/tauri.conf.json
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src-tauri/tauri.conf.json
🔇 Additional comments (2)
src-tauri/capabilities/default.json (2)
2-2
: Schema path relies on generated files; confirm dev setup regenerates it.The
$schema
points to../gen/schemas/desktop-schema.json
, which is created by Tauri tooling. Ensure contributors can generate it (e.g., viatauri dev
) and that editor validation won’t break in clean clones. (tauri.app)
6-8
: Verify Tauri core permissions match actual API usage
No imports from @tauri-apps/api or TAURI invocations detected—confirm which core modules (app, event, path, webview, window, etc.) your frontend actually uses and replacecore:default
with only those specific scopes.
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 invite.config.js
.Requirements
Docker
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 thesrc
directory. [1] [2]Summary by CodeRabbit
New Features
Chores