feat: allow volume button t control sliders on mobile
This commit is contained in:
@@ -1,11 +1,47 @@
|
||||
package com.lucas.thomann_dsp_app
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
|
||||
class MainActivity : TauriActivity() {
|
||||
private var webView: WebView? = null
|
||||
@Volatile private var interceptVolume = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onWebViewCreate(webView: WebView) {
|
||||
super.onWebViewCreate(webView)
|
||||
this.webView = webView
|
||||
webView.addJavascriptInterface(object {
|
||||
@JavascriptInterface
|
||||
fun setIntercept(enabled: Boolean) {
|
||||
interceptVolume = enabled
|
||||
}
|
||||
}, "VolumeBridge")
|
||||
}
|
||||
|
||||
private fun isVolumeKey(keyCode: Int) =
|
||||
keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (interceptVolume && isVolumeKey(keyCode)) {
|
||||
val name = if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) "volumeupbutton" else "volumedownbutton"
|
||||
webView?.post {
|
||||
webView?.evaluateJavascript("document.dispatchEvent(new Event('$name'))", null)
|
||||
}
|
||||
return true // consumed, so the system volume doesn't change
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
||||
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (interceptVolume && isVolumeKey(keyCode)) return true
|
||||
return super.onKeyUp(keyCode, event)
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
C:/Users/Lucas/Desktop/Projects/thomann-dsp-app/src-tauri/target/aarch64-linux-android/release/libthomann_dsp_app_lib.so
|
||||
C:/Users/lsdg/OneDrive - ETS ROBERT SAS 49/Bureau/Projects/dsp-thomann-interface/src-tauri/target/aarch64-linux-android/release/libthomann_dsp_app_lib.so
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
include ':tauri-android'
|
||||
project(':tauri-android').projectDir = new File("C:\\Users\\Lucas\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\tauri-2.12.4\\mobile\\android")
|
||||
project(':tauri-android').projectDir = new File("C:\\Users\\lsdg\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\tauri-2.12.4\\mobile\\android")
|
||||
include ':tauri-plugin-opener'
|
||||
project(':tauri-plugin-opener').projectDir = new File("C:\\Users\\Lucas\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\tauri-plugin-opener-2.7.2\\android")
|
||||
project(':tauri-plugin-opener').projectDir = new File("C:\\Users\\lsdg\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\tauri-plugin-opener-2.7.2\\android")
|
||||
|
||||
Reference in New Issue
Block a user