Allow oob webview to move the execution forward

Stephen Paul Weber created

Change summary

src/main/java/eu/siacs/conversations/entities/Conversation.java | 14 +++
1 file changed, 14 insertions(+)

Detailed changes

src/main/java/eu/siacs/conversations/entities/Conversation.java 🔗

@@ -22,6 +22,7 @@ import android.widget.CompoundButton;
 import android.widget.TextView;
 import android.widget.Toast;
 import android.widget.Spinner;
+import android.webkit.JavascriptInterface;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.webkit.WebChromeClient;
@@ -1713,8 +1714,21 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
                             ConversationPagerAdapter.this.notifyDataSetChanged();
                         }
                     });
+                    binding.webview.addJavascriptInterface(new JsObject(), "xmpp_xep0050");
                     binding.webview.loadUrl(oob.el.findChildContent("url", "jabber:x:oob"));
                 }
+
+                class JsObject {
+                    @JavascriptInterface
+                    public void execute() { execute("execute"); }
+                    public void execute(String action) {
+                        getView().post(() -> {
+                            if(CommandSession.this.execute(action)) {
+                                removeSession(CommandSession.this);
+                            }
+                        });
+                    }
+                }
             }
 
             class ProgressBarViewHolder extends ViewHolder<CommandProgressBarBinding> {