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)",
|
"WebFetch(domain:cs.android.com)",
|
||||||
"WebSearch",
|
"WebSearch",
|
||||||
"WebFetch(domain:maven.google.com)",
|
"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.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
sealed class StartupResult {
|
sealed class StartupResult {
|
||||||
data object Success : StartupResult()
|
data object Success : StartupResult()
|
||||||
@@ -45,22 +47,15 @@ class ProxyService : Service() {
|
|||||||
val proxyFailed = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
val proxyFailed = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
||||||
val startupResult = MutableStateFlow<StartupResult?>(null)
|
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) {
|
fun addLog(msg: String) {
|
||||||
synchronized(logBuffer) {
|
logs.update { current ->
|
||||||
logBuffer.addLast(msg)
|
val next = current + msg
|
||||||
while (logBuffer.size > MAX_LOG_LINES) logBuffer.removeFirst()
|
if (next.size > MAX_LOG_LINES) next.drop(next.size - MAX_LOG_LINES) else next
|
||||||
logs.value = logBuffer.toList()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearLogs() {
|
fun clearLogs() {
|
||||||
synchronized(logBuffer) {
|
logs.value = emptyList()
|
||||||
logBuffer.clear()
|
|
||||||
logs.value = emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +159,11 @@ class ProxyService : Service() {
|
|||||||
try {
|
try {
|
||||||
addLog("Команда: ${cmdArgs.joinToString(" ")}")
|
addLog("Команда: ${cmdArgs.joinToString(" ")}")
|
||||||
|
|
||||||
val proc = ProcessBuilder(cmdArgs)
|
val proc = withContext(Dispatchers.IO) {
|
||||||
.redirectErrorStream(true)
|
ProcessBuilder(cmdArgs)
|
||||||
.start()
|
.redirectErrorStream(true)
|
||||||
|
.start()
|
||||||
|
}
|
||||||
process.set(proc)
|
process.set(proc)
|
||||||
|
|
||||||
BufferedReader(InputStreamReader(proc.inputStream)).use { reader ->
|
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) ===")
|
addLog("=== ПРОЦЕСС ОСТАНОВЛЕН (Код: $exitCode) ===")
|
||||||
if (!startupEmitted) {
|
if (!startupEmitted) {
|
||||||
startupResult.value = StartupResult.Failed(
|
startupResult.value = StartupResult.Failed(
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.freeturn.app.ui
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.VibrationEffect
|
import android.os.VibrationEffect
|
||||||
import android.os.Vibrator
|
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.
|
* Apple-like haptic patterns for a tactile, musical feel.
|
||||||
@@ -28,6 +32,7 @@ object HapticUtil {
|
|||||||
LAUNCH,
|
LAUNCH,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
fun perform(context: Context, pattern: Pattern) {
|
fun perform(context: Context, pattern: Pattern) {
|
||||||
val vibrator = context.getSystemService(Vibrator::class.java) ?: return
|
val vibrator = context.getSystemService(Vibrator::class.java) ?: return
|
||||||
val effect = when (pattern) {
|
val effect = when (pattern) {
|
||||||
@@ -82,6 +87,8 @@ object HapticUtil {
|
|||||||
-1
|
-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.filterNotNull
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
@@ -86,13 +87,11 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
private val _sshLog = MutableStateFlow<List<String>>(emptyList())
|
private val _sshLog = MutableStateFlow<List<String>>(emptyList())
|
||||||
val sshLog: StateFlow<List<String>> = _sshLog.asStateFlow()
|
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) {
|
private fun appendSshLog(vararg lines: String) {
|
||||||
synchronized(sshLogBuffer) {
|
_sshLog.update { current ->
|
||||||
lines.forEach { sshLogBuffer.addLast(it) }
|
var next = current + lines
|
||||||
while (sshLogBuffer.size > 500) sshLogBuffer.removeFirst()
|
if (next.size > 500) next = next.drop(next.size - 500)
|
||||||
_sshLog.value = sshLogBuffer.toList()
|
next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,10 +382,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun clearSshLog() {
|
fun clearSshLog() {
|
||||||
synchronized(sshLogBuffer) {
|
_sshLog.value = emptyList()
|
||||||
sshLogBuffer.clear()
|
|
||||||
_sshLog.value = emptyList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Local proxy ────────────────────────────────────────────────────────
|
// ── Local proxy ────────────────────────────────────────────────────────
|
||||||
@@ -502,10 +498,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
_serverState.value = ServerState.Unknown
|
_serverState.value = ServerState.Unknown
|
||||||
_serverVersion.value = null
|
_serverVersion.value = null
|
||||||
_serverLogs.value = null
|
_serverLogs.value = null
|
||||||
synchronized(sshLogBuffer) {
|
_sshLog.value = emptyList()
|
||||||
sshLogBuffer.clear()
|
|
||||||
_sshLog.value = emptyList()
|
|
||||||
}
|
|
||||||
_proxyState.value = ProxyState.Idle
|
_proxyState.value = ProxyState.Idle
|
||||||
_customKernelExists.value = false
|
_customKernelExists.value = false
|
||||||
ProxyService.clearLogs()
|
ProxyService.clearLogs()
|
||||||
|
|||||||
Reference in new issue
Block a user