mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
feat(dual-screen): Chat & voice page on the bottom screen
Mic on/off for the session and game volume buttons (no Android volume panel over the game), plus Steam's web chat, loaded only when opened and kept to Steam's own sites. Keyboard keys typed on the dashboard stay on the bottom screen; controller buttons still go to the game.
This commit is contained in:
1 parent
ee8911a382
commit
125e39ea9c
5 files changed
+157
-1
No files matched your search
@@ -0,0 +1,124 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.media.AudioManager
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebSettings
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
|
||||
private const val STEAM_CHAT = "https://steamcommunity.com/chat"
|
||||
private val STEAM_HOSTS = listOf("steamcommunity.com", "steampowered.com", "steamstatic.com", "steamcontent.com")
|
||||
|
||||
/** Steam chat stays on Steam's own sites; anything else is not opened on the bottom screen. */
|
||||
internal fun steamChatAllows(host: String?): Boolean =
|
||||
host != null && STEAM_HOSTS.any { host == it || host.endsWith(".$it") }
|
||||
|
||||
/** The desktop chat fits the bottom panel better than the phone site; keep WebView's Chrome version. */
|
||||
internal fun desktopUserAgent(webView: String?): String {
|
||||
val chrome = webView?.let { Regex("Chrome/[\\d.]+").find(it)?.value } ?: "Chrome/127.0.6533.103"
|
||||
return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) $chrome Safari/537.36"
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BottomChatPage() {
|
||||
val context = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
var chatOpen by remember { mutableStateOf(false) }
|
||||
Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
VoiceRow(context)
|
||||
if (!chatOpen) {
|
||||
Column(Modifier.weight(1f).fillMaxWidth().padding(24.dp), horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically)) {
|
||||
Text(stringResource(R.string.bottom_chat_why), fontSize = 15.sp, color = colors.onBackground, textAlign = TextAlign.Center)
|
||||
BottomPillButton(stringResource(R.string.bottom_chat_open), "bottom-chat-open") { chatOpen = true }
|
||||
}
|
||||
} else {
|
||||
Box(Modifier.weight(1f).fillMaxWidth().clip(RoundedCornerShape(14.dp))) { SteamChatView() }
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
BottomPillButton(stringResource(R.string.bottom_chat_close), "bottom-chat-close") { chatOpen = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun VoiceRow(context: Context) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val audio = remember { context.getSystemService(Context.AUDIO_SERVICE) as AudioManager }
|
||||
val max = remember { audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC).coerceAtLeast(1) }
|
||||
var volume by remember { mutableIntStateOf(audio.getStreamVolume(AudioManager.STREAM_MUSIC)) }
|
||||
fun step(direction: Int) {
|
||||
// No flags: Android's volume panel would cover the game on the main screen.
|
||||
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, 0)
|
||||
volume = audio.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||
}
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (SessionState.micAvailable) {
|
||||
val on = SessionState.micEnabled
|
||||
BottomPillButton(stringResource(if (on) R.string.bottom_chat_mic_on else R.string.bottom_chat_mic_off), "bottom-chat-mic") {
|
||||
SessionService.setMicEnabled(context, !on)
|
||||
}
|
||||
}
|
||||
Text(stringResource(R.string.bottom_chat_volume, volume * 100 / max), fontSize = 14.sp, color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.weight(1f), textAlign = TextAlign.End)
|
||||
BottomPillButton("−", "bottom-chat-volume-down") { step(AudioManager.ADJUST_LOWER) }
|
||||
BottomPillButton("+", "bottom-chat-volume-up") { step(AudioManager.ADJUST_RAISE) }
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Composable
|
||||
private fun SteamChatView() {
|
||||
AndroidView(factory = { ctx ->
|
||||
WebView(ctx).apply {
|
||||
setBackgroundColor(0xFF0A0B0D.toInt())
|
||||
settings.javaScriptEnabled = true
|
||||
settings.domStorageEnabled = true
|
||||
settings.allowFileAccess = false
|
||||
settings.allowContentAccess = false
|
||||
settings.useWideViewPort = true
|
||||
settings.loadWithOverviewMode = true
|
||||
settings.userAgentString = desktopUserAgent(runCatching { WebSettings.getDefaultUserAgent(ctx) }.getOrNull())
|
||||
CookieManager.getInstance().setAcceptCookie(true)
|
||||
webViewClient = object : WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean =
|
||||
!steamChatAllows(request.url.host)
|
||||
}
|
||||
loadUrl(STEAM_CHAT)
|
||||
}
|
||||
}, modifier = Modifier.fillMaxSize(), onRelease = { view ->
|
||||
CookieManager.getInstance().flush()
|
||||
view.destroy()
|
||||
})
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Download
|
||||
import androidx.compose.material.icons.outlined.Forum
|
||||
import androidx.compose.material.icons.outlined.Notifications
|
||||
import androidx.compose.material.icons.outlined.PhotoLibrary
|
||||
import com.droiddeck.launcher.R
|
||||
@@ -16,4 +17,5 @@ fun sessionBottomPages(actions: BottomPageActions): List<BottomPage> = listOf(
|
||||
BottomPage("downloads", R.string.bottom_page_downloads, Icons.Outlined.Download) { BottomDownloadsPage() },
|
||||
BottomPage("notifications", R.string.bottom_page_notifications, Icons.Outlined.Notifications) { BottomNotificationsPage() },
|
||||
BottomPage("screenshots", R.string.bottom_page_screenshots, Icons.Outlined.PhotoLibrary) { BottomScreenshotsPage(actions.takeScreenshot) },
|
||||
BottomPage("chat", R.string.bottom_page_chat, Icons.Outlined.Forum) { BottomChatPage() },
|
||||
)
|
||||
@@ -199,7 +199,8 @@ class SecondScreenPresentation(
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
val forward = menuShown || currentMode != SecondScreenMode.TERMINAL || PadBridge.isControllerKeyEvent(event)
|
||||
val ownKeys = currentMode == SecondScreenMode.TERMINAL || currentMode == SecondScreenMode.DASHBOARD
|
||||
val forward = menuShown || !ownKeys || PadBridge.isControllerKeyEvent(event)
|
||||
if (forward && sessionActivity.dispatchKeyEvent(event)) return true
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
@@ -1896,6 +1896,13 @@
|
||||
<string name="bottom_shots_saved">Screenshot saved.</string>
|
||||
<string name="bottom_shots_failed">Could not take a screenshot.</string>
|
||||
<string name="bottom_shots_none">No screenshots yet.</string>
|
||||
<string name="bottom_page_chat">Chat & voice</string>
|
||||
<string name="bottom_chat_why">Read and answer Steam chat here while the game keeps running on the main screen. Sign in to Steam once; DroidDeck keeps you signed in.</string>
|
||||
<string name="bottom_chat_open">Open Steam Chat</string>
|
||||
<string name="bottom_chat_close">Close chat</string>
|
||||
<string name="bottom_chat_mic_on">Mic on</string>
|
||||
<string name="bottom_chat_mic_off">Mic off</string>
|
||||
<string name="bottom_chat_volume">Volume %1$d%%</string>
|
||||
|
||||
<string name="rtinst_removing">Removing Linux runtime</string>
|
||||
<plurals name="rtinst_removing_entries">
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class BottomChatPageTest {
|
||||
@Test fun steamSitesOpenOthersDoNot() {
|
||||
assertTrue(steamChatAllows("steamcommunity.com"))
|
||||
assertTrue(steamChatAllows("login.steampowered.com"))
|
||||
assertTrue(steamChatAllows("community.cloudflare.steamstatic.com"))
|
||||
assertFalse(steamChatAllows("steamcommunity.com.example.net"))
|
||||
assertFalse(steamChatAllows("evilsteamcommunity.com"))
|
||||
assertFalse(steamChatAllows(null))
|
||||
}
|
||||
|
||||
@Test fun desktopAgentKeepsTheWebViewChromeVersion() {
|
||||
val ua = desktopUserAgent("Mozilla/5.0 (Linux; Android 15; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/141.0.7390.122 Mobile Safari/537.36")
|
||||
assertEquals("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.7390.122 Safari/537.36", ua)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user