fix: исправление потенциальных проблем
This commit is contained in:
1 parent
9f1352ce3e
commit
abe549d994
4 files changed
+51
-31
No files matched your search
@@ -9,7 +9,28 @@
|
||||
"WebFetch(domain:cs.android.com)",
|
||||
"WebSearch",
|
||||
"WebFetch(domain:maven.google.com)",
|
||||
"Bash(find /c/Users/hxmelander/.gradle/caches -name material3-android-1.4.0*)"
|
||||
"Bash(find /c/Users/hxmelander/.gradle/caches -name material3-android-1.4.0*)",
|
||||
"Bash(wc:*)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/bottom-sheets/guidelines)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/bottom-sheets/specs)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/lists/guidelines)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/lists/specs)",
|
||||
"WebFetch(domain:m3.material.io)",
|
||||
"WebFetch(domain:m2.material.io)",
|
||||
"WebFetch(domain:medium.com)",
|
||||
"WebFetch(domain:www.boltuix.com)",
|
||||
"WebFetch(domain:github.com)",
|
||||
"WebFetch(domain:androidx.tech)",
|
||||
"WebFetch(domain:supercharge.design)",
|
||||
"Bash(for f:*)",
|
||||
"Bash(do echo:*)",
|
||||
"Read(//c/Users/hxmelander/StudioProjects/vk-turn-proxy-android/**)",
|
||||
"Bash(done)",
|
||||
"Bash(curl -s \"https://dl.google.com/dl/android/maven2/androidx/compose/material3/material3-expressive/maven-metadata.xml\")",
|
||||
"Bash(curl -s \"https://dl.google.com/dl/android/maven2/androidx/compose/material3/material3/maven-metadata.xml\")",
|
||||
"Bash(curl -s \"https://dl.google.com/dl/android/maven2/androidx/compose/compose-bom/2026.03.01/compose-bom-2026.03.01.pom\")",
|
||||
"Bash(git add:*)",
|
||||
"Bash(git commit:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,9 @@ import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
sealed class StartupResult {
|
||||
data object Success : StartupResult()
|
||||
@@ -45,22 +47,15 @@ class ProxyService : Service() {
|
||||
val proxyFailed = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
||||
val startupResult = MutableStateFlow<StartupResult?>(null)
|
||||
|
||||
// P3-3: ArrayDeque — O(1) addLast/removeFirst вместо O(n) list concatenation
|
||||
private val logBuffer = ArrayDeque<String>(MAX_LOG_LINES)
|
||||
|
||||
fun addLog(msg: String) {
|
||||
synchronized(logBuffer) {
|
||||
logBuffer.addLast(msg)
|
||||
while (logBuffer.size > MAX_LOG_LINES) logBuffer.removeFirst()
|
||||
logs.value = logBuffer.toList()
|
||||
logs.update { current ->
|
||||
val next = current + msg
|
||||
if (next.size > MAX_LOG_LINES) next.drop(next.size - MAX_LOG_LINES) else next
|
||||
}
|
||||
}
|
||||
|
||||
fun clearLogs() {
|
||||
synchronized(logBuffer) {
|
||||
logBuffer.clear()
|
||||
logs.value = emptyList()
|
||||
}
|
||||
logs.value = emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,9 +159,11 @@ class ProxyService : Service() {
|
||||
try {
|
||||
addLog("Команда: ${cmdArgs.joinToString(" ")}")
|
||||
|
||||
val proc = ProcessBuilder(cmdArgs)
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
val proc = withContext(Dispatchers.IO) {
|
||||
ProcessBuilder(cmdArgs)
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
}
|
||||
process.set(proc)
|
||||
|
||||
BufferedReader(InputStreamReader(proc.inputStream)).use { reader ->
|
||||
@@ -205,7 +202,9 @@ class ProxyService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
exitCode = if (proc.waitFor(5, TimeUnit.MINUTES)) proc.exitValue() else -1
|
||||
exitCode = if (withContext(Dispatchers.IO) {
|
||||
proc.waitFor(5, TimeUnit.MINUTES)
|
||||
}) proc.exitValue() else -1
|
||||
addLog("=== ПРОЦЕСС ОСТАНОВЛЕН (Код: $exitCode) ===")
|
||||
if (!startupEmitted) {
|
||||
startupResult.value = StartupResult.Failed(
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.freeturn.app.ui
|
||||
import android.content.Context
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Apple-like haptic patterns for a tactile, musical feel.
|
||||
@@ -28,6 +32,7 @@ object HapticUtil {
|
||||
LAUNCH,
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun perform(context: Context, pattern: Pattern) {
|
||||
val vibrator = context.getSystemService(Vibrator::class.java) ?: return
|
||||
val effect = when (pattern) {
|
||||
@@ -82,6 +87,8 @@ object HapticUtil {
|
||||
-1
|
||||
)
|
||||
}
|
||||
vibrator.vibrate(effect)
|
||||
GlobalScope.launch(Dispatchers.Default) {
|
||||
try { vibrator.vibrate(effect) } catch(_: Exception) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
@@ -86,13 +87,11 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val _sshLog = MutableStateFlow<List<String>>(emptyList())
|
||||
val sshLog: StateFlow<List<String>> = _sshLog.asStateFlow()
|
||||
|
||||
// P3-10: ArrayDeque — O(1) вместо O(n) list concatenation
|
||||
private val sshLogBuffer = ArrayDeque<String>(500)
|
||||
private fun appendSshLog(vararg lines: String) {
|
||||
synchronized(sshLogBuffer) {
|
||||
lines.forEach { sshLogBuffer.addLast(it) }
|
||||
while (sshLogBuffer.size > 500) sshLogBuffer.removeFirst()
|
||||
_sshLog.value = sshLogBuffer.toList()
|
||||
_sshLog.update { current ->
|
||||
var next = current + lines
|
||||
if (next.size > 500) next = next.drop(next.size - 500)
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,10 +382,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
|
||||
fun clearSshLog() {
|
||||
synchronized(sshLogBuffer) {
|
||||
sshLogBuffer.clear()
|
||||
_sshLog.value = emptyList()
|
||||
}
|
||||
_sshLog.value = emptyList()
|
||||
}
|
||||
|
||||
// ── Local proxy ────────────────────────────────────────────────────────
|
||||
@@ -502,10 +498,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
_serverState.value = ServerState.Unknown
|
||||
_serverVersion.value = null
|
||||
_serverLogs.value = null
|
||||
synchronized(sshLogBuffer) {
|
||||
sshLogBuffer.clear()
|
||||
_sshLog.value = emptyList()
|
||||
}
|
||||
_sshLog.value = emptyList()
|
||||
_proxyState.value = ProxyState.Idle
|
||||
_customKernelExists.value = false
|
||||
ProxyService.clearLogs()
|
||||
|
||||
Reference in new issue
Block a user