Skip to content

fix: update Tauri environment detection for v2 compatibility#459

Merged
rahulharpal1603 merged 3 commits intoAOSSIE-Org:mainfrom
Aditya30ag:fix/tauri-v2-environment-detection
Jul 11, 2025
Merged

fix: update Tauri environment detection for v2 compatibility#459
rahulharpal1603 merged 3 commits intoAOSSIE-Org:mainfrom
Aditya30ag:fix/tauri-v2-environment-detection

Conversation

@Aditya30ag
Copy link
Contributor

@Aditya30ag Aditya30ag commented Jul 11, 2025

Summary

Fixed Tauri environment detection to work correctly with Tauri v2, resolving the issue where the desktop app was incorrectly showing the browser warning.

Problem

The existing isTauriEnvironment() function used the deprecated window.__TAURI__ check, which is no longer available by default in Tauri v2 unless withGlobalTauri: true is explicitly set.

Solution

  • ✅ Added window.isTauri check (official API since Tauri 2.0.0-beta.9)
  • ✅ Added window.__TAURI_INTERNALS__ fallback for Tauri v2 compatibility
  • ✅ Kept window.__TAURI__ as final fallback for backward compatibility
  • ✅ Added TypeScript declarations for better type safety
  • ✅ Added alternative isTauriEnvironmentOfficial() using @tauri-apps/api/core

Testing

  • Desktop app no longer shows browser warning
  • Browser detection still works correctly
  • Build passes without TypeScript errors

References

Summary by CodeRabbit

  • New Features
    • Improved detection of the Tauri environment, increasing reliability across different setups.
    • Added an advanced detection method that uses the official Tauri API when available, with fallback to legacy checks.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

The update enhances Tauri environment detection in the frontend utility by extending the Window interface with Tauri-specific properties and refactoring the isTauriEnvironment function to use multiple detection strategies, replacing the previous stub that always returned true.

Changes

File(s) Change Summary
frontend/src/utils/tauriUtils.ts Extended Window type with optional Tauri properties; refactored isTauriEnvironment from stub to multi-step detection logic using official and fallback checks.

Possibly related PRs

Suggested labels

enhancement

Poem

A bunny hopped through Tauri's den,
Seeking clues with a clever pen.
Now checks abound, both old and new,
With async hops and fallbacks too!
Window’s secrets, now revealed—
The Tauri truth is well-concealed.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fff735 and 9432445.

📒 Files selected for processing (1)
  • frontend/src/utils/tauriUtils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/utils/tauriUtils.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Backend Tests
  • GitHub Check: Tauri Tests
  • GitHub Check: Tauri Build Check (macos-latest, --target aarch64-apple-darwin)
  • GitHub Check: Tauri Build Check (ubuntu-22.04)
  • GitHub Check: Tauri Build Check (windows-latest)
✨ 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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: 0

🧹 Nitpick comments (1)
frontend/src/utils/tauriUtils.ts (1)

15-38: Good detection logic, but optimize the implementation.

The multi-method detection approach correctly addresses Tauri v2 compatibility while maintaining backward compatibility. However, there are optimization opportunities:

  1. The try-catch block around window.isTauri is unnecessary since property access won't throw an error
  2. The typeof window !== 'undefined' check is repeated multiple times

Consider this optimized version:

export const isTauriEnvironment = (): boolean => {
+  // Early return if not in browser environment
+  if (typeof window === 'undefined') {
+    return false;
+  }
+
-  // Method 1: Use official Tauri API (recommended)
-  try {
-    // This is the official way to detect Tauri environment
-    // Available since Tauri 2.0.0-beta.9
-    if (typeof window !== 'undefined' && window.isTauri) {
-      return true;
-    }
-  } catch (error) {
-    // Fallback to manual detection if official API fails
-  }
+  // Method 1: Use official Tauri API (recommended)
+  // Available since Tauri 2.0.0-beta.9
+  if (window.isTauri) {
+    return true;
+  }

-  // Method 2: Check for __TAURI_INTERNALS__ (Tauri v2 manual detection)
-  if (typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window) {
-    return true;
-  }
+  // Method 2: Check for __TAURI_INTERNALS__ (Tauri v2 manual detection)
+  if ('__TAURI_INTERNALS__' in window) {
+    return true;
+  }
  
-  // Method 3: Fallback to __TAURI__ for backward compatibility (requires withGlobalTauri: true)
-  if (typeof window !== 'undefined' && '__TAURI__' in window) {
-    return true;
-  }
+  // Method 3: Fallback to __TAURI__ for backward compatibility (requires withGlobalTauri: true)
+  if ('__TAURI__' in window) {
+    return true;
+  }
  
   return false;
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0e31b5 and a50037e.

📒 Files selected for processing (1)
  • frontend/src/utils/tauriUtils.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Backend Tests
  • GitHub Check: Tauri Build Check (ubuntu-22.04)
  • GitHub Check: Tauri Build Check (macos-latest, --target aarch64-apple-darwin)
  • GitHub Check: Tauri Tests
  • GitHub Check: Tauri Build Check (windows-latest)
🔇 Additional comments (2)
frontend/src/utils/tauriUtils.ts (2)

5-12: LGTM! Well-structured TypeScript declarations.

The global interface extension correctly defines the optional Tauri-specific properties with appropriate types. This provides good type safety for the detection logic.


40-49: Excellent implementation of the official API detection.

The function correctly uses dynamic import for optional dependency loading and provides appropriate fallback handling. This gives users flexibility to choose between manual detection and official API detection.

@Aditya30ag
Copy link
Contributor Author

@rahulharpal1603 i think now it works

@rahulharpal1603 rahulharpal1603 merged commit 8035a05 into AOSSIE-Org:main Jul 11, 2025
8 checks passed
@rahulharpal1603
Copy link
Contributor

@Aditya30ag Thank you for the fix!

@Aditya30ag
Copy link
Contributor Author

Thanks to youu
I can't do this without your help and guidance

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments