forked from agentic-review-benchmarks/tauri
-
Notifications
You must be signed in to change notification settings - Fork 0
Code Review Bench PR #14133 - feat(core): back button event on Android, closes #8142 #6
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
Closed
ketkarameya
wants to merge
2
commits into
base_pr_14133_20260125_4253
from
corrupted_pr_14133_20260125_4253
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "tauri": minor:feat | ||
| --- | ||
|
|
||
| Added mobile app plugin to support exit and back button press event. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@tauri-apps/api": minor:feat | ||
| --- | ||
|
|
||
| Added `app > onBackButtonPress` for Android back button handling. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright 2019-2024 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package app.tauri | ||
|
|
||
| import android.app.Activity | ||
| import android.webkit.WebView | ||
| import androidx.activity.OnBackPressedCallback | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import app.tauri.annotation.Command | ||
| import app.tauri.annotation.TauriPlugin | ||
| import app.tauri.plugin.Plugin | ||
| import app.tauri.plugin.Invoke | ||
| import app.tauri.plugin.JSObject | ||
|
|
||
| @TauriPlugin | ||
| class AppPlugin(private val activity: Activity): Plugin(activity) { | ||
| private val BACK_BUTTON_EVENT = "back-button" | ||
|
|
||
| private var webView: WebView? = null | ||
|
|
||
| override fun load(webView: WebView) { | ||
| this.webView = webView | ||
| } | ||
|
|
||
| init { | ||
| val callback = object : OnBackPressedCallback(true) { | ||
| override fun handleOnBackPressed() { | ||
| if (!hasListener(BACK_BUTTON_EVENT)) { | ||
| if (this@AppPlugin.webView?.canGoBack() == true) { | ||
| this@AppPlugin.webView!!.goBack() | ||
| } else { | ||
| this.isEnabled = false | ||
| this@AppPlugin.activity.onBackPressed() | ||
| this.isEnabled = true | ||
| } | ||
| } else { | ||
| val data = JSObject().apply { | ||
| put("canGoBack", this@AppPlugin.webView?.canGoBack() ?: false) | ||
| } | ||
| trigger(BACK_BUTTON_EVENT, data) | ||
| } | ||
| } | ||
| } | ||
| (activity as AppCompatActivity).onBackPressedDispatcher.addCallback(activity, callback) | ||
| } | ||
|
|
||
| @Command | ||
| fun exit(invoke: Invoke) { | ||
| activity.finish() | ||
| invoke.resolve() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The code at lines 139-140 creates a shared reference to
handlethen attempts to dereference it with*handle_ref:PluginHandle<R>implementsClonebut notCopy(confirmed inplugin.rs), so*handle_refattempts to move out of a shared reference, which is a compile error: "cannot move out of*handle_refwhich is behind a shared reference".This code is behind
#[cfg(target_os = "android")]so it only fails when compiling for Android targets, which may explain why it passed CI on other platforms.The fix is to simply move
handledirectly, matching the existing pattern used inpath/plugin.rs:Was this helpful? React with 👍 / 👎