From 722ded32d33b51821b6fc2ce83c556d445ff993b Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 30 Sep 2023 22:47:53 +0200 Subject: [PATCH] no more than one webxdc start within 500ms it seems, fast tapping may result in starting a webxdc twice on some systems, i cannot reproduce this, but this check may help --- src/org/thoughtcrime/securesms/WebxdcActivity.java | 14 ++++++++------ src/org/thoughtcrime/securesms/util/Util.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index bd99a25f6..0f7c6bbc0 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -63,13 +63,15 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE private boolean internetAccess = false; public static void openWebxdcActivity(Context context, DcMsg instance) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (Prefs.isDeveloperModeEnabled(context)) { - WebView.setWebContentsDebuggingEnabled(true); + if (!Util.isClickedRecently()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Prefs.isDeveloperModeEnabled(context)) { + WebView.setWebContentsDebuggingEnabled(true); + } + context.startActivity(getWebxdcIntent(context, instance.getId())); + } else { + Toast.makeText(context, "At least Android 5.0 (Lollipop) required for Webxdc.", Toast.LENGTH_LONG).show(); } - context.startActivity(getWebxdcIntent(context, instance.getId())); - } else { - Toast.makeText(context, "At least Android 5.0 (Lollipop) required for Webxdc.", Toast.LENGTH_LONG).show(); } } diff --git a/src/org/thoughtcrime/securesms/util/Util.java b/src/org/thoughtcrime/securesms/util/Util.java index 45d90b0ba..2bd35cda5 100644 --- a/src/org/thoughtcrime/securesms/util/Util.java +++ b/src/org/thoughtcrime/securesms/util/Util.java @@ -345,4 +345,15 @@ public class Util { public static int rgbToArgbColor(int rgb) { return Color.argb(0xFF, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } + + private static long lastClickTime = 0; + public static boolean isClickedRecently() { + long now = System.currentTimeMillis(); + if (now - lastClickTime < 500) { + Log.i(TAG, "tap discarded"); + return true; + } + lastClickTime = now; + return false; + } }