chore: code formatting

This commit is contained in:
Miuzarte
2026-07-12 20:01:39 +08:00
parent b918f18e9e
commit a2937f5fe1
9 changed files with 48 additions and 23 deletions

View File

@@ -140,6 +140,7 @@ class DeviceShortcuts(val devices: List<DeviceShortcut>): List<DeviceShortcut> b
val p = port ?: old.port
listOf("$host:$p")
}
updateById -> old.addresses
newPort != null -> {

View File

@@ -54,8 +54,10 @@ class AnnexBDecoder(
init {
if (!outputSurface.isValid) {
throw DecoderException(mimeType, width, height,
IllegalStateException("Output surface is not valid"))
throw DecoderException(
mimeType, width, height,
IllegalStateException("Output surface is not valid"),
)
}
val format = MediaFormat.createVideoFormat(mimeType, width, height)
if (sps != null) {

View File

@@ -11,7 +11,7 @@ class DecoderException(
val width: Int,
val height: Int,
cause: Throwable? = null,
) : RuntimeException(
): RuntimeException(
"Decoder failed for mime=$mime size=${width}x${height}",
cause,
)

View File

@@ -308,8 +308,7 @@ internal object DirectAdbTransport {
private fun generatePkcs8PrivateKey(der: ByteArray): PrivateKey {
val kf = KeyFactory.getInstance("RSA")
val key = runCatching { kf.generatePrivate(PKCS8EncodedKeySpec(der)) }.getOrNull()
return if (key is RSAPrivateCrtKey) key
else kf.generatePrivate(parsePkcs8PrivateKey(der))
return key as? RSAPrivateCrtKey ?: kf.generatePrivate(parsePkcs8PrivateKey(der))
}
private fun parsePublicKey(content: String): PublicKey {
@@ -366,7 +365,25 @@ internal object DirectAdbTransport {
private data class PemBlock(
val label: String,
val bytes: ByteArray,
)
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as PemBlock
if (label != other.label) return false
if (!bytes.contentEquals(other.bytes)) return false
return true
}
override fun hashCode(): Int {
var result = label.hashCode()
result = 31 * result + bytes.contentHashCode()
return result
}
}
private fun readPem(content: String): PemBlock? {
val begin = Regex("-----BEGIN ([A-Z0-9 ]+)-----").find(content) ?: return null
@@ -661,9 +678,13 @@ internal class DirectAdbConnection(
fun openStream(service: String): AdbSocketStream {
val localId = nextLocalId.getAndIncrement()
val flowControlWindow = Storage.appSettings.bundleState.value.adbFlowControlWindow
val stream = AdbSocketStream(localId, { command, arg0, arg1, data ->
val stream = AdbSocketStream(
localId,
{ command, arg0, arg1, data ->
sendMsg(command, arg0, arg1, data)
}, flowControlWindow)
},
flowControlWindow,
)
streams[localId] = stream
sendMsg(A_OPEN, localId, 0, (service + "\u0000").toByteArray(Charsets.UTF_8))
try {
@@ -979,8 +1000,9 @@ class AdbSocketStream(
private val queue = LinkedBlockingQueue<Any>()
// need notifyAll() / wait()
private val writeLock = java.lang.Object()
@Volatile private var inflightWrites = 0
private val writeLock = Object()
@Volatile
private var inflightWrites = 0
private object EndOfStreamMarker

View File

@@ -54,8 +54,11 @@ internal class FileManagerViewModel: ViewModel() {
private fun longestHistoricalPrefix(current: String): String {
val prefixMatch: (String) -> Boolean =
if (current == ROOT_REMOTE_PATH) { { true } }
else { { hist -> hist == current || hist.startsWith("$current/") } }
if (current == ROOT_REMOTE_PATH) {
{ true }
} else {
{ hist -> hist == current || hist.startsWith("$current/") }
}
var best = current
var bestLen = current.length
pathHistory.forEach { hist ->

View File

@@ -1,6 +1,7 @@
package io.github.miuzarte.scrcpyforandroid.pages
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Typeface
import android.util.Log
import android.view.KeyEvent
@@ -52,10 +53,10 @@ import kotlin.math.max
private const val FONT_SCALE_STEP_THRESHOLD = 1.08f
private const val LOG_TAG = "TerminalScreen"
private fun terminalFontFile(context: android.content.Context) =
private fun terminalFontFile(context: Context) =
File(context.filesDir, "terminal/font.ttf")
private fun loadTerminalTypeface(context: android.content.Context): Typeface? {
private fun loadTerminalTypeface(context: Context): Typeface? {
val file = terminalFontFile(context)
if (!file.exists()) return null
return runCatching { Typeface.createFromFile(file) }.getOrNull()

View File

@@ -1,6 +1,7 @@
package io.github.miuzarte.scrcpyforandroid.storage
import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.stringPreferencesKey
import io.github.miuzarte.scrcpyforandroid.services.AppRuntime
import kotlinx.coroutines.flow.StateFlow
@@ -33,7 +34,7 @@ class ScrcpyProfiles(context: Context): Settings(context, "ScrcpyProfiles") {
val state: StateFlow<State> = createBundleState(::stateFromPreferences)
private fun stateFromPreferences(preferences: androidx.datastore.preferences.core.Preferences): State {
private fun stateFromPreferences(preferences: Preferences): State {
val raw = preferences.read(PROFILES_JSON)
return normalizeState(
runCatching { decodeState(raw) }.getOrNull() ?: State(emptyList()),

View File

@@ -63,14 +63,9 @@ import io.github.miuzarte.scrcpyforandroid.storage.Storage
import io.github.miuzarte.scrcpyforandroid.storage.Storage.scrcpyOptions
import io.github.miuzarte.scrcpyforandroid.ui.confirm
import io.github.miuzarte.scrcpyforandroid.ui.contextClick
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import top.yukonga.miuix.kmp.basic.*
import top.yukonga.miuix.kmp.icon.MiuixIcons
import top.yukonga.miuix.kmp.icon.extended.AddCircle