Skip to content

feat(core): back button event on Android, closes #8142#32

Open
tomerqodo wants to merge 2 commits intocoderabbit_full_base_featcore_back_button_event_on_android_closes_8142_pr6from
coderabbit_full_head_featcore_back_button_event_on_android_closes_8142_pr6
Open

feat(core): back button event on Android, closes #8142#32
tomerqodo wants to merge 2 commits intocoderabbit_full_base_featcore_back_button_event_on_android_closes_8142_pr6from
coderabbit_full_head_featcore_back_button_event_on_android_closes_8142_pr6

Conversation

@tomerqodo
Copy link

@tomerqodo tomerqodo commented Jan 29, 2026

Benchmark PR from agentic-review-benchmarks#6

Summary by CodeRabbit

  • New Features

    • Added Android back button press event handling with onBackButtonPress API for detecting back navigation attempts.
    • Introduced app exit command for programmatically closing the application.
    • Added listener registration and removal commands for event management.
  • Dependencies

    • Updated Wry dependency to version 0.53.4.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Walkthrough

This PR introduces Android back button press event handling to Tauri. A new AppPlugin for Android detects back-button presses, emits events to JavaScript, and provides a TypeScript hook. Associated permissions, commands, and dependencies are updated accordingly.

Changes

Cohort / File(s) Summary
Changelog Entries
.changes/android-app-plugin.md, .changes/back-button-press-api.md
New changelog markdown files documenting the mobile app plugin feature and onBackButtonPress API hook.
Dependency Updates
crates/tauri-runtime-wry/Cargo.toml
Bumped wry dependency from 0.53.2 to 0.53.4.
Command & Permission Setup
crates/tauri/build.rs, crates/tauri/permissions/app/autogenerated/reference.md
Added register_listener and remove_listener commands to core:app plugin; documented corresponding allow/deny permissions in reference documentation.
Android Kotlin Implementation
crates/tauri/mobile/android-codegen/TauriActivity.kt, crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt, crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt
Added TauriActivity handleBackNavigation property; introduced new AppPlugin class with back-button event emission and exit command; added hasListener() query method to Plugin base class.
Rust Plugin Integration
crates/tauri/src/app/plugin.rs
Added Android-specific plugin initialization path that registers and manages the native AppPlugin handle during app startup.
TypeScript API
packages/api/src/app.ts
Introduced onBackButtonPress() hook and OnBackButtonPressPayload type for listening to Android back button events from JavaScript.
Cleanup
crates/tauri/src/path/android.rs, crates/tauri/scripts/bundle.global.js
Simplified imports and minor formatting adjustments.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant WebView as WebView
    participant AppPlugin as Android AppPlugin
    participant JSRuntime as JS Runtime
    participant Handler as JS Handler

    User->>WebView: Press back button
    activate AppPlugin
    AppPlugin->>AppPlugin: Check if "back-button" listener exists
    
    alt Listener exists
        AppPlugin->>AppPlugin: Detect canGoBack state
        AppPlugin->>JSRuntime: Emit BACK_BUTTON_EVENT with canGoBack
        JSRuntime->>Handler: Invoke onBackButtonPress callback
        Handler->>Handler: Process event
    else No listener & canGoBack
        AppPlugin->>WebView: Navigate back
        WebView-->>User: Show previous page
    else No listener & cannot go back
        AppPlugin->>AppPlugin: Delegate to system back action
        AppPlugin-->>User: Exit app (system default)
    end
    deactivate AppPlugin
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's ode to the back button hop,
No more shall navigation stop!
Android events now dance with grace,
While listeners jump from place to place,
Exit and press, a feature so fine!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: introducing a back button event feature on Android, with specific issue reference.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7415e5a and 5a010d0.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • .changes/android-app-plugin.md
  • .changes/back-button-press-api.md
  • crates/tauri-runtime-wry/Cargo.toml
  • crates/tauri/build.rs
  • crates/tauri/mobile/android-codegen/TauriActivity.kt
  • crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt
  • crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt
  • crates/tauri/permissions/app/autogenerated/reference.md
  • crates/tauri/scripts/bundle.global.js
  • crates/tauri/src/app/plugin.rs
  • crates/tauri/src/path/android.rs
  • packages/api/src/app.ts
🧰 Additional context used
🧬 Code graph analysis (1)
crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt (1)
crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt (2)
  • hasListener (149-151)
  • trigger (129-137)
🔇 Additional comments (19)
crates/tauri/scripts/bundle.global.js (1)

1-1: Bundled API exposure looks consistent.

Line 1: The bundled app.onBackButtonPress wiring via the app plugin listener matches the intended API surface.

crates/tauri/src/path/android.rs (1)

7-7: Import cleanup is fine.

Line 7: Consolidated std::path imports without behavior change.

crates/tauri/mobile/android-codegen/TauriActivity.kt (1)

15-15: Verify default back behavior when no listener exists.

Line 15: With handleBackNavigation = true, please confirm that apps without JS listeners still follow the previous back-navigation behavior (e.g., WebView history or activity finish), and that no unintended interception occurs.

.changes/back-button-press-api.md (1)

1-5: Changelog entry looks good.

Lines 1-5: The note clearly documents the new app.onBackButtonPress API.

.changes/android-app-plugin.md (1)

1-5: Changelog entry looks good.

Lines 1-5: The entry succinctly captures the new mobile app plugin feature.

crates/tauri-runtime-wry/Cargo.toml (1)

20-25: wry 0.53.4 is a safe patch-level upgrade with one behavioral improvement on Linux.

No API-breaking changes were introduced. On Linux (WebKitGTK), the patch removes a sequential request workaround and enables concurrent request handling, which is a positive change that reduces the risk of deadlocks and improves parallelism. The Android changes are purely additive (optional back-navigation flag). The lockfile will update automatically with cargo update.

crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt (1)

149-151: LGTM — listener presence helper is straightforward.

crates/tauri/permissions/app/autogenerated/reference.md (3)

12-13: Docs update aligns with new listener defaults.


209-230: Register-listener permissions are clearly documented.


261-282: Remove-listener permissions are clearly documented.

crates/tauri/build.rs (1)

167-168: Good to expose listener commands in core:app defaults.

crates/tauri/src/app/plugin.rs (2)

135-143: Android plugin registration is cleanly gated.


147-148: Wrapper type is concise and clear.

crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt (3)

23-25: LGTM — WebView reference stored for back navigation.


27-47: Back-button handling flow looks solid.


49-53: Exit command is minimal and clear.

packages/api/src/app.ts (3)

5-5: Import addition aligns with the new listener API.


255-275: Back-button listener API is clear and well-scoped.


289-291: Exports correctly surface the new API and payload type.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

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.

1 participant