0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

[Kotlin Migration] WebViewDebugging

Package: com.ichi2.utils
This commit is contained in:
codingtosh 2021-11-10 23:47:06 +05:30 committed by Mike Hardy
parent 2e09f32fa8
commit 0de8204f72
2 changed files with 21 additions and 22 deletions

View File

@ -43,7 +43,7 @@ permission notice:
// Example of class name: "/com/ichi2/anki/UIUtils.kt"
// Ensure that it starts with '/' (slash)
def source = Source.MAIN
def className = "/com/ichi2/utils/WebViewDebugging.kt"
def className = ""
enum Source {
MAIN("/src/main/java"),

View File

@ -14,22 +14,19 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ichi2.utils;
package com.ichi2.utils
import android.content.SharedPreferences;
import android.os.Build;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.UiThread;
public class WebViewDebugging {
private static boolean sHasSetDataDirectory = false;
import android.content.SharedPreferences
import android.os.Build
import android.webkit.WebView
import androidx.annotation.RequiresApi
import androidx.annotation.UiThread
object WebViewDebugging {
private var sHasSetDataDirectory = false
@JvmStatic
@UiThread
public static void initializeDebugging(SharedPreferences sharedPrefs) {
fun initializeDebugging(sharedPrefs: SharedPreferences) {
// DEFECT: We might be able to cache this value: check what happens on WebView Renderer crash
// On your desktop use chrome://inspect to connect to emulator WebViews
// Beware: Crash in AnkiDroidApp.onCreate() with:
@ -38,19 +35,21 @@ public class WebViewDebugging {
is not supported. https://crbug.com/558377 : Lock owner com.ichi2.anki:acra at
org.chromium.android_webview.AwDataDirLock.a(PG:26)
*/
boolean enableDebugging = sharedPrefs.getBoolean("html_javascript_debugging", false);
WebView.setWebContentsDebuggingEnabled(enableDebugging);
val enableDebugging = sharedPrefs.getBoolean("html_javascript_debugging", false)
WebView.setWebContentsDebuggingEnabled(enableDebugging)
}
/** Throws IllegalStateException if a WebView has been initialized */
/** Throws IllegalStateException if a WebView has been initialized */
@JvmStatic
@RequiresApi(api = Build.VERSION_CODES.P)
public static void setDataDirectorySuffix(@NonNull String suffix) {
WebView.setDataDirectorySuffix(suffix);
sHasSetDataDirectory = true;
fun setDataDirectorySuffix(suffix: String) {
WebView.setDataDirectorySuffix(suffix)
sHasSetDataDirectory = true
}
public static boolean hasSetDataDirectory() {
@JvmStatic
fun hasSetDataDirectory(): Boolean {
// Implicitly truth requires API >= P
return sHasSetDataDirectory;
return sHasSetDataDirectory
}
}