diff --git a/.gitignore b/.gitignore index 4108b33..10e5c85 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ dist-ssr *.njsproj *.sln *.sw? +*.jks \ No newline at end of file diff --git a/README.md b/README.md index fb3f374..da5b048 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,13 @@ This template should help get you started developing with Tauri, React and Types - [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) +# Mobile Install +- npm run tauri android build -- --apk +- adb uninstall com.lucas.thomann_dsp_app +- adb install src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk + # TODO - Check end to end behavioour -- Make phone version \ No newline at end of file + diff --git a/src-tauri/.gitignore b/src-tauri/.gitignore index d8769d0..6e79684 100644 --- a/src-tauri/.gitignore +++ b/src-tauri/.gitignore @@ -5,3 +5,5 @@ # Generated by Tauri # will have schema files for capabilities auto-completion /gen/schemas + +/src-tauri/gen/android/keystore.properties \ No newline at end of file diff --git a/src-tauri/gen/android/app/build.gradle.kts b/src-tauri/gen/android/app/build.gradle.kts index e9468cd..2f4706a 100644 --- a/src-tauri/gen/android/app/build.gradle.kts +++ b/src-tauri/gen/android/app/build.gradle.kts @@ -1,3 +1,4 @@ + import java.util.Properties plugins { @@ -13,41 +14,80 @@ val tauriProperties = Properties().apply { } } +// Load signing credentials +val keystoreProperties = Properties().apply { + val keystoreFile = rootProject.file("keystore.properties") + require(keystoreFile.exists()) { + "Missing keystore.properties" + } + keystoreFile.inputStream().use { load(it) } +} + android { compileSdk = 36 namespace = "com.lucas.thomann_dsp_app" + defaultConfig { manifestPlaceholders["usesCleartextTraffic"] = "false" applicationId = "com.lucas.thomann_dsp_app" minSdk = 24 targetSdk = 36 - versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt() - versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0") + versionCode = tauriProperties + .getProperty("tauri.android.versionCode", "1").toInt() + versionName = tauriProperties + .getProperty("tauri.android.versionName", "1.0") } + + signingConfigs { + create("release") { + val keystorePath = keystoreProperties.getProperty("storeFile") + ?: error("Missing storeFile") + + storeFile = rootProject.file(keystorePath) + + storePassword = keystoreProperties.getProperty("storePassword") + ?: error("Missing storePassword") + + keyAlias = keystoreProperties.getProperty("keyAlias") + ?: error("Missing keyAlias") + + keyPassword = keystoreProperties.getProperty("keyPassword") + ?: error("Missing keyPassword") + } + } + buildTypes { getByName("debug") { manifestPlaceholders["usesCleartextTraffic"] = "true" isDebuggable = true isJniDebuggable = true isMinifyEnabled = false - packaging { jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so") + + packaging { + jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so") jniLibs.keepDebugSymbols.add("*/armeabi-v7a/*.so") jniLibs.keepDebugSymbols.add("*/x86/*.so") jniLibs.keepDebugSymbols.add("*/x86_64/*.so") } } + getByName("release") { - isMinifyEnabled = true + isMinifyEnabled = false + signingConfig = signingConfigs.getByName("release") + proguardFiles( *fileTree(".") { include("**/*.pro") } .plus(getDefaultProguardFile("proguard-android-optimize.txt")) - .toList().toTypedArray() + .toList() + .toTypedArray() ) } } + kotlinOptions { jvmTarget = "1.8" } + buildFeatures { buildConfig = true } @@ -63,9 +103,10 @@ dependencies { implementation("androidx.activity:activity-ktx:1.10.1") implementation("com.google.android.material:material:1.12.0") implementation("androidx.lifecycle:lifecycle-process:2.10.0") + testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.4") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0") } -apply(from = "tauri.build.gradle.kts") \ No newline at end of file +apply(from = "tauri.build.gradle.kts") diff --git a/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Ipc.kt b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Ipc.kt new file mode 100644 index 0000000..96c8bec --- /dev/null +++ b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Ipc.kt @@ -0,0 +1,25 @@ +/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */ + +// Copyright 2020-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +@file:Suppress("unused") + +package com.lucas.thomann_dsp_app + +import android.webkit.* + +class Ipc(val webView: RustWebView, val webViewClient: RustWebViewClient) { + @JavascriptInterface + fun postMessage(message: String?) { + message?.let {m -> + // we're not using WebView::getUrl() here because it needs to be executed on the main thread + // and it would slow down the Ipc + // so instead we track the current URL on the webview client + Rust.ipc(webView.id, webViewClient.currentUrl, m) + } + } + + +} diff --git a/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Logger.kt b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Logger.kt new file mode 100644 index 0000000..2891ec3 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Logger.kt @@ -0,0 +1,89 @@ +/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */ + +// Copyright 2020-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +@file:Suppress("unused", "MemberVisibilityCanBePrivate") + +package com.lucas.thomann_dsp_app + +// taken from https://github.com/ionic-team/capacitor/blob/6658bca41e78239347e458175b14ca8bd5c1d6e8/android/capacitor/src/main/java/com/getcapacitor/Logger.java + +import android.text.TextUtils +import android.util.Log + +class Logger { + companion object { + private const val LOG_TAG_CORE = "Tauri" + + fun tags(vararg subtags: String): String { + return if (subtags.isNotEmpty()) { + LOG_TAG_CORE + "/" + TextUtils.join("/", subtags) + } else LOG_TAG_CORE + } + + fun verbose(message: String) { + verbose(LOG_TAG_CORE, message) + } + + private fun verbose(tag: String, message: String) { + if (!shouldLog()) { + return + } + Log.v(tag, message) + } + + fun debug(message: String) { + debug(LOG_TAG_CORE, message) + } + + fun debug(tag: String, message: String) { + if (!shouldLog()) { + return + } + Log.d(tag, message) + } + + fun info(message: String) { + info(LOG_TAG_CORE, message) + } + + fun info(tag: String, message: String) { + if (!shouldLog()) { + return + } + Log.i(tag, message) + } + + fun warn(message: String) { + warn(LOG_TAG_CORE, message) + } + + fun warn(tag: String, message: String) { + if (!shouldLog()) { + return + } + Log.w(tag, message) + } + + fun error(message: String) { + error(LOG_TAG_CORE, message, null) + } + + fun error(message: String, e: Throwable?) { + error(LOG_TAG_CORE, message, e) + } + + fun error(tag: String, message: String, e: Throwable?) { + if (!shouldLog()) { + return + } + Log.e(tag, message, e) + } + + private fun shouldLog(): Boolean { + return BuildConfig.DEBUG + } + } +} diff --git a/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/PermissionHelper.kt b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/PermissionHelper.kt new file mode 100644 index 0000000..dc7f528 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/PermissionHelper.kt @@ -0,0 +1,117 @@ +/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */ + +// Copyright 2020-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +package com.lucas.thomann_dsp_app + +// taken from https://github.com/ionic-team/capacitor/blob/6658bca41e78239347e458175b14ca8bd5c1d6e8/android/capacitor/src/main/java/com/getcapacitor/PermissionHelper.java + +import android.content.Context +import android.content.pm.PackageManager +import android.os.Build +import androidx.core.app.ActivityCompat +import java.util.ArrayList + +object PermissionHelper { + /** + * Checks if a list of given permissions are all granted by the user + * + * @param permissions Permissions to check. + * @return True if all permissions are granted, false if at least one is not. + */ + fun hasPermissions(context: Context?, permissions: Array): Boolean { + for (perm in permissions) { + if (ActivityCompat.checkSelfPermission( + context!!, + perm + ) != PackageManager.PERMISSION_GRANTED + ) { + return false + } + } + return true + } + + /** + * Check whether the given permission has been defined in the AndroidManifest.xml + * + * @param permission A permission to check. + * @return True if the permission has been defined in the Manifest, false if not. + */ + fun hasDefinedPermission(context: Context, permission: String): Boolean { + var hasPermission = false + val requestedPermissions = getManifestPermissions(context) + if (!requestedPermissions.isNullOrEmpty()) { + val requestedPermissionsList = listOf(*requestedPermissions) + val requestedPermissionsArrayList = ArrayList(requestedPermissionsList) + if (requestedPermissionsArrayList.contains(permission)) { + hasPermission = true + } + } + return hasPermission + } + + /** + * Check whether all of the given permissions have been defined in the AndroidManifest.xml + * @param context the app context + * @param permissions a list of permissions + * @return true only if all permissions are defined in the AndroidManifest.xml + */ + fun hasDefinedPermissions(context: Context, permissions: Array): Boolean { + for (permission in permissions) { + if (!hasDefinedPermission(context, permission)) { + return false + } + } + return true + } + + /** + * Get the permissions defined in AndroidManifest.xml + * + * @return The permissions defined in AndroidManifest.xml + */ + private fun getManifestPermissions(context: Context): Array? { + var requestedPermissions: Array? = null + try { + val pm = context.packageManager + val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + pm.getPackageInfo(context.packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong())) + } else { + @Suppress("DEPRECATION") + pm.getPackageInfo(context.packageName, PackageManager.GET_PERMISSIONS) + } + if (packageInfo != null) { + requestedPermissions = packageInfo.requestedPermissions + } + } catch (_: Exception) { + } + return requestedPermissions + } + + /** + * Given a list of permissions, return a new list with the ones not present in AndroidManifest.xml + * + * @param neededPermissions The permissions needed. + * @return The permissions not present in AndroidManifest.xml + */ + fun getUndefinedPermissions(context: Context, neededPermissions: Array): Array { + val undefinedPermissions = ArrayList() + val requestedPermissions = getManifestPermissions(context) + if (!requestedPermissions.isNullOrEmpty()) { + val requestedPermissionsList = listOf(*requestedPermissions) + val requestedPermissionsArrayList = ArrayList(requestedPermissionsList) + for (permission in neededPermissions) { + if (!requestedPermissionsArrayList.contains(permission)) { + undefinedPermissions.add(permission) + } + } + var undefinedPermissionArray = arrayOfNulls(undefinedPermissions.size) + undefinedPermissionArray = undefinedPermissions.toArray(undefinedPermissionArray) + return undefinedPermissionArray + } + return neededPermissions + } +} diff --git a/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Rust.kt b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Rust.kt new file mode 100644 index 0000000..9aa2cfe --- /dev/null +++ b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/Rust.kt @@ -0,0 +1,46 @@ +/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */ + +// Copyright 2020-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +@file:Suppress("unused") + +package com.lucas.thomann_dsp_app + +import android.content.Intent +import android.webkit.WebView +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse + +object Rust { + init { + System.loadLibrary("thomann_dsp_app_lib") + } + + // Tao bindings + @JvmStatic external fun onFirstActivityCreate() + @JvmStatic external fun onCreate(activity: WryActivity) + @JvmStatic external fun onStart(activity: WryActivity) + @JvmStatic external fun onResume(activity: WryActivity) + @JvmStatic external fun onPause(activity: WryActivity) + @JvmStatic external fun onStop(activity: WryActivity) + @JvmStatic external fun onDestroy(activity: WryActivity) + @JvmStatic external fun onWindowFocusChanged(activity: WryActivity, focus: Boolean) + @JvmStatic external fun onLowMemory() + @JvmStatic external fun onNewIntent(intent: Intent) + + @JvmStatic external fun onFirstActivityCreateWry() + @JvmStatic external fun onWebviewDestroy(activity: WryActivity, webviewId: String) + + @JvmStatic external fun ipc(webviewId: String, url: String, message: String) + + @JvmStatic external fun assetLoaderDomain(webviewId: String): String? + @JvmStatic external fun handleRequest(webviewId: String, request: WebResourceRequest, isDocumentStartScriptEnabled: Boolean): WebResourceResponse? + @JvmStatic external fun shouldOverride(webviewId: String, url: String): Boolean + @JvmStatic external fun onPageLoading(webviewId: String, url: String) + @JvmStatic external fun onPageLoaded(webviewId: String, url: String) + @JvmStatic external fun onEval(webviewId: String, id: Int, result: String) + + @JvmStatic external fun handleReceivedTitle(webviewId: String, title: String) +} \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/RustWebChromeClient.kt b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/RustWebChromeClient.kt new file mode 100644 index 0000000..502af08 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/java/com/lucas/thomann_dsp_app/generated/RustWebChromeClient.kt @@ -0,0 +1,519 @@ +/* THIS FILE IS AUTO-GENERATED. DO NOT MODIFY!! */ + +// Copyright 2020-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +@file:Suppress("ObsoleteSdkInt", "RedundantOverride", "QueryPermissionsNeeded", "SimpleDateFormat") + +package com.lucas.thomann_dsp_app + +// taken from https://github.com/ionic-team/capacitor/blob/6658bca41e78239347e458175b14ca8bd5c1d6e8/android/capacitor/src/main/java/com/getcapacitor/BridgeWebChromeClient.java + +import android.Manifest +import android.app.Activity +import android.app.AlertDialog +import android.content.ActivityNotFoundException +import android.content.DialogInterface +import android.content.Intent +import android.graphics.Bitmap +import android.net.Uri +import android.os.Build +import android.os.Environment +import android.provider.MediaStore +import android.view.View +import android.webkit.* +import android.widget.EditText +import androidx.core.content.FileProvider +import java.io.File +import java.io.IOException +import java.text.SimpleDateFormat +import java.util.* + +class RustWebChromeClient(private val activity: WryActivity, private val webViewId: String) : WebChromeClient() { + private companion object { + const val PERMISSION_REQUEST_DEFAULT = 0 + const val PERMISSION_REQUEST_ALLOW = 1 + const val PERMISSION_REQUEST_DENY = 2 + } + + /** + * Render web content in `view`. + * + * Both this method and [.onHideCustomView] are required for + * rendering web content in full screen. + * + * @see [](https://developer.android.com/reference/android/webkit/WebChromeClient.onShowCustomView + ) */ + override fun onShowCustomView(view: View, callback: CustomViewCallback) { + callback.onCustomViewHidden() + super.onShowCustomView(view, callback) + } + + /** + * Render web content in the original Web View again. + * + * Do not remove this method--@see #onShowCustomView(View, CustomViewCallback). + */ + override fun onHideCustomView() { + super.onHideCustomView() + } + + override fun onPermissionRequest(request: PermissionRequest) { + val requestedResources = request.resources + if (requestedResources.isEmpty()) { + request.deny() + return + } + + val allowedResources = ArrayList() + val defaultResources = ArrayList() + + for (resource in requestedResources) { + when (onPermissionRequestNative(webViewId, resource)) { + PERMISSION_REQUEST_DENY -> {} + PERMISSION_REQUEST_ALLOW -> allowedResources.add(resource) + PERMISSION_REQUEST_DEFAULT -> defaultResources.add(resource) + } + } + + val resources = + allowedResources.plus(filterKnownPermissions(defaultResources)).toList().toTypedArray() + grantPermissionRequest(request, resources) + } + + private fun grantPermissionRequest(request: PermissionRequest, resources: Array) { + if (resources.isEmpty()) { + request.deny() + return + } + + val isRequestPermissionRequired = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + val permissionList = androidPermissionsForResources(resources) + if (permissionList.isNotEmpty() && isRequestPermissionRequired) { + val permissions = permissionList.toTypedArray() + activity.requestPermissions(permissions) { isGranted -> + if (isGranted == true) { + request.grant(resources) + } else { + request.deny() + } + } + } else { + request.grant(resources) + } + } + + private fun androidPermissionsForResources(resources: Array): MutableList { + val permissionList: MutableList = ArrayList() + if (resources.contains(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) { + permissionList.add(Manifest.permission.CAMERA) + } + if (resources.contains(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) { + permissionList.add(Manifest.permission.MODIFY_AUDIO_SETTINGS) + permissionList.add(Manifest.permission.RECORD_AUDIO) + } + return permissionList + } + + /** + * @return one of the PERMISSION_REQUEST_* constants. + */ + private external fun onPermissionRequestNative(webviewId: String, resource: String): Int + + override fun getDefaultVideoPoster(): Bitmap { + // Return a transparent bitmap so Chromium doesn't paint its default gray play-button placeholder on