feat: bug fixes
This commit is contained in:
1 parent
20331a774e
commit
97e90e1526
15 files changed
+822
-307
No files matched your search
@@ -3,7 +3,13 @@
|
|||||||
"allow": [
|
"allow": [
|
||||||
"Bash(./gradlew assembleDebug)",
|
"Bash(./gradlew assembleDebug)",
|
||||||
"Bash(JAVA_HOME=\"/c/Program Files/Android/Android Studio/jbr\" ./gradlew assembleDebug)",
|
"Bash(JAVA_HOME=\"/c/Program Files/Android/Android Studio/jbr\" ./gradlew assembleDebug)",
|
||||||
"Bash(xargs sed:*)"
|
"Bash(xargs sed:*)",
|
||||||
|
"Bash(JAVA_HOME=\"C:/Program Files/Android/Android Studio/jbr\" ./gradlew assembleDebug)",
|
||||||
|
"WebFetch(domain:composables.com)",
|
||||||
|
"WebFetch(domain:cs.android.com)",
|
||||||
|
"WebSearch",
|
||||||
|
"WebFetch(domain:maven.google.com)",
|
||||||
|
"Bash(find /c/Users/hxmelander/.gradle/caches -name material3-android-1.4.0*)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,8 +70,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.compose.ui)
|
implementation(libs.androidx.compose.ui)
|
||||||
implementation(libs.androidx.compose.ui.graphics)
|
implementation(libs.androidx.compose.ui.graphics)
|
||||||
implementation(libs.androidx.compose.ui.tooling.preview)
|
implementation(libs.androidx.compose.ui.tooling.preview)
|
||||||
// Явно пиним M3 1.4.0-alpha10+ для WavyProgressIndicator и ExperimentalMaterial3ExpressiveApi
|
implementation(libs.androidx.compose.material3)
|
||||||
implementation("androidx.compose.material3:material3:1.4.0-alpha10")
|
|
||||||
implementation(libs.androidx.compose.material.icons.extended)
|
implementation(libs.androidx.compose.material.icons.extended)
|
||||||
|
|
||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.FOREGROUND_SERVICE"
|
android:name="android.permission.FOREGROUND_SERVICE"
|
||||||
tools:ignore="ForegroundServicesPolicy"
|
tools:ignore="ForegroundServicesPolicy"
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
package com.freeturn.app
|
package com.freeturn.app
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.freeturn.app.ui.navigation.AppNavigation
|
import com.freeturn.app.ui.navigation.AppNavigation
|
||||||
import com.freeturn.app.ui.theme.FreeTurnTheme
|
import com.freeturn.app.ui.theme.FreeTurnTheme
|
||||||
import com.freeturn.app.viewmodel.MainViewModel
|
import com.freeturn.app.viewmodel.MainViewModel
|
||||||
@@ -22,17 +17,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
private val viewModel: MainViewModel by viewModels()
|
private val viewModel: MainViewModel by viewModels()
|
||||||
|
|
||||||
private val notificationPermissionLauncher =
|
|
||||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { /* no-op */ }
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
// Включаем отображение от края до края (Edge-to-Edge)
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
requestNotificationPermissionIfNeeded()
|
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
FreeTurnTheme {
|
FreeTurnTheme {
|
||||||
Surface(
|
Surface(
|
||||||
@@ -44,15 +31,4 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestNotificationPermissionIfNeeded() {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
if (ContextCompat.checkSelfPermission(
|
|
||||||
this, Manifest.permission.POST_NOTIFICATIONS
|
|
||||||
) != PackageManager.PERMISSION_GRANTED
|
|
||||||
) {
|
|
||||||
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,21 +5,28 @@ import android.app.NotificationManager
|
|||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.Network
|
||||||
|
import android.os.Handler
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.os.Looper
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class ProxyService : Service() {
|
class ProxyService : Service() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val MAX_RESTARTS = 8
|
||||||
var isRunning = false
|
var isRunning = false
|
||||||
|
var restartCount = 0
|
||||||
val logBuffer = mutableListOf<String>()
|
val logBuffer = mutableListOf<String>()
|
||||||
var onLogReceived: ((String) -> Unit)? = null
|
var onLogReceived: ((String) -> Unit)? = null
|
||||||
|
var onProxyFailed: (() -> Unit)? = null
|
||||||
|
|
||||||
fun addLog(msg: String) {
|
fun addLog(msg: String) {
|
||||||
if (logBuffer.size > 200) logBuffer.removeAt(0)
|
if (logBuffer.size > 200) logBuffer.removeAt(0)
|
||||||
@@ -29,17 +36,21 @@ class ProxyService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
private var process: Process? = null
|
@Volatile private var process: Process? = null
|
||||||
|
@Volatile private var userStopped = false
|
||||||
|
@Volatile private var sessionKillScheduled = false
|
||||||
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
private var networkCallback: ConnectivityManager.NetworkCallback? = null
|
||||||
|
// Игнорируем первый onAvailable (текущая сеть при регистрации)
|
||||||
|
@Volatile private var networkInitialized = false
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? = null
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
val channel = NotificationChannel("ProxyChannel", "Proxy", NotificationManager.IMPORTANCE_LOW)
|
val channel = NotificationChannel("ProxyChannel", "Proxy", NotificationManager.IMPORTANCE_LOW)
|
||||||
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
|
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
if (isRunning) return START_STICKY
|
if (isRunning) return START_STICKY
|
||||||
@@ -50,23 +61,27 @@ class ProxyService : Service() {
|
|||||||
.setSmallIcon(android.R.drawable.ic_menu_preferences)
|
.setSmallIcon(android.R.drawable.ic_menu_preferences)
|
||||||
.build()
|
.build()
|
||||||
startForeground(1, notification)
|
startForeground(1, notification)
|
||||||
|
|
||||||
isRunning = true
|
isRunning = true
|
||||||
|
userStopped = false
|
||||||
|
restartCount = 0
|
||||||
|
|
||||||
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
|
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VkTurn::BgLock")
|
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VkTurn::BgLock")
|
||||||
wakeLock?.acquire()
|
wakeLock?.acquire()
|
||||||
|
|
||||||
|
registerNetworkCallback()
|
||||||
|
|
||||||
addLog("=== ЗАПУСК ПРОКСИ ===")
|
addLog("=== ЗАПУСК ПРОКСИ ===")
|
||||||
startBinary()
|
thread { startBinaryProcess() }
|
||||||
|
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startBinary() {
|
private fun startBinaryProcess() {
|
||||||
val prefs = getSharedPreferences("ProxyPrefs", Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences("ProxyPrefs", Context.MODE_PRIVATE)
|
||||||
val isRaw = prefs.getBoolean("isRaw", false)
|
val isRaw = prefs.getBoolean("isRaw", false)
|
||||||
|
|
||||||
// Ищем обновленный пользователем файл, если его нет - берем вшитый в APK
|
|
||||||
val customBin = File(filesDir, "custom_vkturn")
|
val customBin = File(filesDir, "custom_vkturn")
|
||||||
val executable = if (customBin.exists()) {
|
val executable = if (customBin.exists()) {
|
||||||
addLog("Используется кастомное ядро из памяти телефона")
|
addLog("Используется кастомное ядро из памяти телефона")
|
||||||
@@ -80,12 +95,9 @@ class ProxyService : Service() {
|
|||||||
|
|
||||||
if (isRaw) {
|
if (isRaw) {
|
||||||
val rawCmd = prefs.getString("rawCmd", "") ?: ""
|
val rawCmd = prefs.getString("rawCmd", "") ?: ""
|
||||||
// Разбиваем строку по пробелам
|
|
||||||
val parts = rawCmd.trim().split("\\s+".toRegex())
|
val parts = rawCmd.trim().split("\\s+".toRegex())
|
||||||
cmdArgs.add(executable) // Подменяем вызов "./client" на реальный путь
|
cmdArgs.add(executable)
|
||||||
if (parts.size > 1) {
|
if (parts.size > 1) cmdArgs.addAll(parts.subList(1, parts.size))
|
||||||
cmdArgs.addAll(parts.subList(1, parts.size))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
val peer = prefs.getString("peer", "") ?: ""
|
val peer = prefs.getString("peer", "") ?: ""
|
||||||
val link = prefs.getString("link", "") ?: ""
|
val link = prefs.getString("link", "") ?: ""
|
||||||
@@ -93,47 +105,140 @@ class ProxyService : Service() {
|
|||||||
val listen = prefs.getString("listen", "127.0.0.1:9000") ?: ""
|
val listen = prefs.getString("listen", "127.0.0.1:9000") ?: ""
|
||||||
|
|
||||||
cmdArgs.add(executable)
|
cmdArgs.add(executable)
|
||||||
cmdArgs.add("-peer")
|
cmdArgs.add("-peer"); cmdArgs.add(peer)
|
||||||
cmdArgs.add(peer)
|
|
||||||
cmdArgs.add(if (link.contains("yandex")) "-yandex-link" else "-vk-link")
|
cmdArgs.add(if (link.contains("yandex")) "-yandex-link" else "-vk-link")
|
||||||
cmdArgs.add(link)
|
cmdArgs.add(link)
|
||||||
cmdArgs.add("-listen")
|
cmdArgs.add("-listen"); cmdArgs.add(listen)
|
||||||
cmdArgs.add(listen)
|
if (n.isNotEmpty()) { cmdArgs.add("-n"); cmdArgs.add(n) }
|
||||||
|
|
||||||
if (n.isNotEmpty()) {
|
|
||||||
cmdArgs.add("-n")
|
|
||||||
cmdArgs.add(n)
|
|
||||||
}
|
|
||||||
if (prefs.getBoolean("udp", false)) cmdArgs.add("-udp")
|
if (prefs.getBoolean("udp", false)) cmdArgs.add("-udp")
|
||||||
if (prefs.getBoolean("noDtls", false)) cmdArgs.add("-no-dtls")
|
if (prefs.getBoolean("noDtls", false)) cmdArgs.add("-no-dtls")
|
||||||
}
|
}
|
||||||
|
|
||||||
thread {
|
var exitCode = -1
|
||||||
|
val startedAt = System.currentTimeMillis()
|
||||||
try {
|
try {
|
||||||
addLog("Команда: ${cmdArgs.joinToString(" ")}")
|
addLog("Команда: ${cmdArgs.joinToString(" ")}")
|
||||||
|
|
||||||
process = ProcessBuilder(cmdArgs)
|
val proc = ProcessBuilder(cmdArgs)
|
||||||
.redirectErrorStream(true)
|
.redirectErrorStream(true)
|
||||||
.start()
|
.start()
|
||||||
|
process = proc
|
||||||
|
|
||||||
val reader = BufferedReader(InputStreamReader(process?.inputStream))
|
val reader = BufferedReader(InputStreamReader(proc.inputStream))
|
||||||
var line: String?
|
var line: String?
|
||||||
while (reader.readLine().also { line = it } != null) {
|
while (reader.readLine().also { line = it } != null) {
|
||||||
addLog(line ?: "")
|
val l = line ?: continue
|
||||||
|
addLog(l)
|
||||||
|
|
||||||
|
// Session Killer: обнаружение ошибки квоты → сброс сессии
|
||||||
|
if (!sessionKillScheduled && isQuotaError(l)) {
|
||||||
|
sessionKillScheduled = true
|
||||||
|
addLog(">>> QUOTA ERROR — сброс сессии через 2с")
|
||||||
|
handler.postDelayed({
|
||||||
|
sessionKillScheduled = false
|
||||||
|
if (!userStopped) {
|
||||||
|
restartCount = 0 // сброс бэкоффа — квота не краш
|
||||||
|
process?.destroy()
|
||||||
|
}
|
||||||
|
}, 2_000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Если процесс завершился, выводим код
|
exitCode = proc.waitFor()
|
||||||
val exitCode = process?.waitFor()
|
|
||||||
addLog("=== ПРОЦЕСС ОСТАНОВЛЕН (Код: $exitCode) ===")
|
addLog("=== ПРОЦЕСС ОСТАНОВЛЕН (Код: $exitCode) ===")
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
addLog("КРИТИЧЕСКАЯ ОШИБКА: ${e.message}")
|
addLog("КРИТИЧЕСКАЯ ОШИБКА: ${e.message}")
|
||||||
|
} finally {
|
||||||
|
process = null
|
||||||
|
when {
|
||||||
|
userStopped -> {
|
||||||
|
isRunning = false
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
exitCode == 0 -> {
|
||||||
|
val uptime = System.currentTimeMillis() - startedAt
|
||||||
|
if (uptime < 5_000L) {
|
||||||
|
// Мгновенный выход — скорее всего истекла ссылка или неверные аргументы
|
||||||
|
addLog("=== Быстрый выход (${uptime}мс) — проверьте VK-ссылку и настройки ===")
|
||||||
|
} else {
|
||||||
|
addLog("=== Сессия завершена нормально ===")
|
||||||
|
}
|
||||||
|
isRunning = false
|
||||||
|
onProxyFailed?.invoke()
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
else -> scheduleWatchdogRestart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Watchdog ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
private fun scheduleWatchdogRestart() {
|
||||||
|
restartCount++
|
||||||
|
if (restartCount > MAX_RESTARTS) {
|
||||||
|
addLog("=== WATCHDOG: превышен лимит попыток ($MAX_RESTARTS), остановка ===")
|
||||||
|
isRunning = false
|
||||||
|
onProxyFailed?.invoke()
|
||||||
|
stopSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val baseDelay = minOf(1_000L * restartCount, 30_000L)
|
||||||
|
val jitter = Random.nextLong(0, 500)
|
||||||
|
val delay = baseDelay + jitter
|
||||||
|
addLog("=== WATCHDOG: перезапуск через ${delay}мс (попытка $restartCount/$MAX_RESTARTS) ===")
|
||||||
|
handler.postDelayed({
|
||||||
|
if (!userStopped) thread { startBinaryProcess() }
|
||||||
|
}, delay)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Network Handover ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
private fun registerNetworkCallback() {
|
||||||
|
networkInitialized = false
|
||||||
|
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val cb = object : ConnectivityManager.NetworkCallback() {
|
||||||
|
override fun onAvailable(network: Network) {
|
||||||
|
if (!networkInitialized) {
|
||||||
|
// Первый вызов — текущая сеть при регистрации, игнорируем
|
||||||
|
networkInitialized = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!userStopped && process != null) {
|
||||||
|
addLog("=== СМЕНА СЕТИ — ПЕРЕЗАПУСК ===")
|
||||||
|
restartCount = 0 // сброс бэкоффа — не краш
|
||||||
|
process?.destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
networkCallback = cb
|
||||||
|
cm.registerDefaultNetworkCallback(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun unregisterNetworkCallback() {
|
||||||
|
networkCallback?.let { cb ->
|
||||||
|
try {
|
||||||
|
(getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
|
||||||
|
.unregisterNetworkCallback(cb)
|
||||||
|
} catch (_: Exception) {}
|
||||||
|
}
|
||||||
|
networkCallback = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
private fun isQuotaError(line: String): Boolean {
|
||||||
|
val l = line.lowercase()
|
||||||
|
return l.contains("486") || l.contains("quota") || l.contains("allocation quota")
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
userStopped = true
|
||||||
isRunning = false
|
isRunning = false
|
||||||
|
handler.removeCallbacksAndMessages(null)
|
||||||
|
unregisterNetworkCallback()
|
||||||
addLog("=== ОСТАНОВКА ИЗ ИНТЕРФЕЙСА ===")
|
addLog("=== ОСТАНОВКА ИЗ ИНТЕРФЕЙСА ===")
|
||||||
process?.destroy()
|
process?.destroy()
|
||||||
if (wakeLock?.isHeld == true) wakeLock?.release()
|
if (wakeLock?.isHeld == true) wakeLock?.release()
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.freeturn.app.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.VibrationEffect
|
||||||
|
import android.os.Vibrator
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apple-like haptic patterns for a tactile, musical feel.
|
||||||
|
* Each pattern mimics iPhone Taptic Engine characteristics:
|
||||||
|
* short snappy pulses, harmonic cascades, ascending/descending amplitudes.
|
||||||
|
*/
|
||||||
|
object HapticUtil {
|
||||||
|
|
||||||
|
enum class Pattern {
|
||||||
|
/** Мягкое касание — смена выбора, тап по вкладке */
|
||||||
|
SELECTION,
|
||||||
|
/** Обычный клик — кнопки, действия */
|
||||||
|
CLICK,
|
||||||
|
/** Включение — тяжёлый удар + послезвук */
|
||||||
|
TOGGLE_ON,
|
||||||
|
/** Выключение — средний удар */
|
||||||
|
TOGGLE_OFF,
|
||||||
|
/** Успех — тройной каскад (восходящий) */
|
||||||
|
SUCCESS,
|
||||||
|
/** Ошибка — двойной тяжёлый buzz */
|
||||||
|
ERROR,
|
||||||
|
/** Старт приложения — двойной мягкий удар */
|
||||||
|
LAUNCH,
|
||||||
|
}
|
||||||
|
|
||||||
|
fun perform(context: Context, pattern: Pattern) {
|
||||||
|
val vibrator = context.getSystemService(Vibrator::class.java) ?: return
|
||||||
|
val effect = when (pattern) {
|
||||||
|
Pattern.SELECTION -> VibrationEffect.createOneShot(11, 58)
|
||||||
|
|
||||||
|
Pattern.CLICK -> VibrationEffect.createOneShot(18, 100)
|
||||||
|
|
||||||
|
Pattern.TOGGLE_ON -> VibrationEffect.createWaveform(
|
||||||
|
longArrayOf(0L, 24L, 60L, 15L),
|
||||||
|
intArrayOf(0, 138, 0, 72),
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
|
||||||
|
Pattern.TOGGLE_OFF -> VibrationEffect.createWaveform(
|
||||||
|
longArrayOf(0L, 19L, 55L, 11L),
|
||||||
|
intArrayOf(0, 88, 0, 44),
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
|
||||||
|
Pattern.SUCCESS -> VibrationEffect.createWaveform(
|
||||||
|
longArrayOf(0L, 16L, 48L, 11L, 48L, 8L),
|
||||||
|
intArrayOf(0, 88, 0, 58, 0, 36),
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
|
||||||
|
Pattern.ERROR -> VibrationEffect.createWaveform(
|
||||||
|
longArrayOf(0L, 32L, 22L, 32L, 22L, 20L),
|
||||||
|
intArrayOf(0, 155, 0, 120, 0, 85),
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
|
||||||
|
Pattern.LAUNCH -> VibrationEffect.createWaveform(
|
||||||
|
longArrayOf(0L, 36L, 88L, 22L),
|
||||||
|
intArrayOf(0, 112, 0, 58),
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
vibrator.vibrate(effect)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package com.freeturn.app.ui.navigation
|
package com.freeturn.app.ui.navigation
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.core.Animatable
|
||||||
|
import androidx.compose.animation.core.Spring
|
||||||
|
import androidx.compose.animation.core.spring
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.slideInVertically
|
import androidx.compose.animation.slideInVertically
|
||||||
import androidx.compose.animation.slideOutVertically
|
import androidx.compose.animation.slideOutVertically
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -17,46 +22,55 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.statusBarsPadding
|
import androidx.compose.foundation.layout.statusBarsPadding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Home
|
import androidx.compose.material.icons.filled.Home
|
||||||
import androidx.compose.material.icons.filled.PhoneAndroid
|
import androidx.compose.material.icons.filled.PhoneAndroid
|
||||||
|
import androidx.compose.material.icons.filled.Security
|
||||||
import androidx.compose.material.icons.filled.Storage
|
import androidx.compose.material.icons.filled.Storage
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
import com.freeturn.app.ui.HapticUtil
|
||||||
import com.freeturn.app.ui.screens.ClientSetupScreen
|
import com.freeturn.app.ui.screens.ClientSetupScreen
|
||||||
import com.freeturn.app.ui.screens.HomeScreen
|
import com.freeturn.app.ui.screens.HomeScreen
|
||||||
import com.freeturn.app.ui.screens.OnboardingScreen
|
import com.freeturn.app.ui.screens.OnboardingScreen
|
||||||
import com.freeturn.app.ui.screens.ServerManagementScreen
|
import com.freeturn.app.ui.screens.ServerManagementScreen
|
||||||
import com.freeturn.app.ui.screens.SshSetupScreen
|
import com.freeturn.app.ui.screens.SshSetupScreen
|
||||||
import com.freeturn.app.viewmodel.MainViewModel
|
import com.freeturn.app.viewmodel.MainViewModel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
object Routes {
|
object Routes {
|
||||||
const val ONBOARDING = "onboarding"
|
const val ONBOARDING = "onboarding"
|
||||||
const val SSH_SETUP = "ssh_setup"
|
const val SSH_SETUP = "ssh_setup" // из настроек/инфо-модалки
|
||||||
|
const val SSH_SETUP_OB = "ssh_setup_ob" // только в мастере онбординга
|
||||||
const val SERVER_MANAGEMENT = "server_management"
|
const val SERVER_MANAGEMENT = "server_management"
|
||||||
|
const val SERVER_MANAGEMENT_OB = "server_management_ob" // только в мастере онбординга
|
||||||
const val CLIENT_SETUP = "client_setup"
|
const val CLIENT_SETUP = "client_setup"
|
||||||
const val HOME = "home"
|
const val HOME = "home"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Нижнее меню видно только в основном потоке, не во время онбординга
|
||||||
private val BOTTOM_NAV_ROUTES = setOf(Routes.HOME, Routes.SERVER_MANAGEMENT, Routes.CLIENT_SETUP)
|
private val BOTTOM_NAV_ROUTES = setOf(Routes.HOME, Routes.SERVER_MANAGEMENT, Routes.CLIENT_SETUP)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -65,9 +79,7 @@ fun AppNavigation(viewModel: MainViewModel) {
|
|||||||
val onboardingDone by viewModel.onboardingDone.collectAsStateWithLifecycle()
|
val onboardingDone by viewModel.onboardingDone.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
if (!isInitialized) {
|
if (!isInitialized) {
|
||||||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
SplashScreen()
|
||||||
CircularProgressIndicator()
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,18 +127,24 @@ fun AppNavigation(viewModel: MainViewModel) {
|
|||||||
modifier = Modifier.statusBarsPadding() // Добавляем отступ для статус-бара сверху
|
modifier = Modifier.statusBarsPadding() // Добавляем отступ для статус-бара сверху
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
// ── Онбординг-мастер (без нижнего меню) ──────────────────────────
|
||||||
|
|
||||||
composable(Routes.ONBOARDING) {
|
composable(Routes.ONBOARDING) {
|
||||||
OnboardingScreen(
|
OnboardingScreen(
|
||||||
onSetupServer = { navController.navigate(Routes.SSH_SETUP) },
|
onSetupServer = { navController.navigate(Routes.SSH_SETUP_OB) },
|
||||||
onSkip = { navController.navigate(Routes.HOME) }
|
onSkip = {
|
||||||
|
viewModel.setOnboardingDone()
|
||||||
|
navController.navigate(Routes.HOME)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(Routes.SSH_SETUP) {
|
composable(Routes.SSH_SETUP_OB) {
|
||||||
SshSetupScreen(
|
SshSetupScreen(
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onConnected = {
|
onConnected = {
|
||||||
navController.navigate(Routes.SERVER_MANAGEMENT) {
|
navController.navigate(Routes.SERVER_MANAGEMENT_OB) {
|
||||||
|
popUpTo(Routes.SSH_SETUP_OB) { inclusive = true }
|
||||||
launchSingleTop = true
|
launchSingleTop = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -134,11 +152,11 @@ fun AppNavigation(viewModel: MainViewModel) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(Routes.SERVER_MANAGEMENT) {
|
composable(Routes.SERVER_MANAGEMENT_OB) {
|
||||||
ServerManagementScreen(
|
ServerManagementScreen(
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onContinue = {
|
onContinue = {
|
||||||
navController.navigate(Routes.CLIENT_SETUP) {
|
navController.navigate(Routes.CLIENT_SETUP + "_onboarding") {
|
||||||
launchSingleTop = true
|
launchSingleTop = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,6 +176,35 @@ fun AppNavigation(viewModel: MainViewModel) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Основной поток (с нижним меню) ───────────────────────────────
|
||||||
|
|
||||||
|
composable(Routes.SSH_SETUP) {
|
||||||
|
SshSetupScreen(
|
||||||
|
viewModel = viewModel,
|
||||||
|
onConnected = {
|
||||||
|
navController.navigate(Routes.SERVER_MANAGEMENT) {
|
||||||
|
popUpTo(Routes.SSH_SETUP) { inclusive = true }
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onBack = { navController.popBackStack() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(Routes.SERVER_MANAGEMENT) {
|
||||||
|
ServerManagementScreen(
|
||||||
|
viewModel = viewModel,
|
||||||
|
onContinue = {
|
||||||
|
navController.navigate(Routes.CLIENT_SETUP) {
|
||||||
|
// Убираем SERVER_MANAGEMENT из back stack,
|
||||||
|
// иначе он остаётся под CLIENT_SETUP и bottom nav ломается
|
||||||
|
popUpTo(Routes.HOME) { inclusive = false; saveState = false }
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
composable(Routes.CLIENT_SETUP) {
|
composable(Routes.CLIENT_SETUP) {
|
||||||
ClientSetupScreen(
|
ClientSetupScreen(
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
@@ -168,7 +215,8 @@ fun AppNavigation(viewModel: MainViewModel) {
|
|||||||
composable(Routes.HOME) {
|
composable(Routes.HOME) {
|
||||||
HomeScreen(
|
HomeScreen(
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateToSshSetup = { navController.navigate(Routes.SSH_SETUP) }
|
onNavigateToSshSetup = { navController.navigate(Routes.SSH_SETUP) },
|
||||||
|
onNavigateToClientSetup = { navController.navigate(Routes.CLIENT_SETUP) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,6 +224,69 @@ fun AppNavigation(viewModel: MainViewModel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SplashScreen() {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val scale = remember { Animatable(0.72f) }
|
||||||
|
val alpha = remember { Animatable(0f) }
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.LAUNCH)
|
||||||
|
launch {
|
||||||
|
scale.animateTo(
|
||||||
|
1f,
|
||||||
|
animationSpec = spring(
|
||||||
|
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||||
|
stiffness = Spring.StiffnessMediumLow
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
alpha.animateTo(1f, animationSpec = tween(380))
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(Color(0xFF00416A)),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = Modifier.graphicsLayer {
|
||||||
|
this.alpha = alpha.value
|
||||||
|
scaleX = scale.value
|
||||||
|
scaleY = scale.value
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(112.dp)
|
||||||
|
.background(Color.White.copy(alpha = 0.15f), CircleShape),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Filled.Security,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(60.dp),
|
||||||
|
tint = Color.White
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(Modifier.height(20.dp))
|
||||||
|
Text(
|
||||||
|
"FreeTurn",
|
||||||
|
style = MaterialTheme.typography.displaySmall,
|
||||||
|
color = Color.White
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(6.dp))
|
||||||
|
Text(
|
||||||
|
"VK TURN Proxy",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = Color.White.copy(alpha = 0.6f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun FloatingNavBar(
|
private fun FloatingNavBar(
|
||||||
currentRoute: String?,
|
currentRoute: String?,
|
||||||
@@ -228,11 +339,15 @@ private fun FloatingNavItem(
|
|||||||
onNavigate: (String) -> Unit
|
onNavigate: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val selected = currentRoute == route
|
val selected = currentRoute == route
|
||||||
|
val context = LocalContext.current
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clip(RoundedCornerShape(20.dp))
|
.clip(RoundedCornerShape(20.dp))
|
||||||
.clickable { onNavigate(route) }
|
.clickable {
|
||||||
|
if (!selected) HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||||
|
onNavigate(route)
|
||||||
|
}
|
||||||
.padding(horizontal = 20.dp, vertical = 6.dp)
|
.padding(horizontal = 20.dp, vertical = 6.dp)
|
||||||
) {
|
) {
|
||||||
Surface(
|
Surface(
|
||||||
|
|||||||
@@ -2,14 +2,18 @@
|
|||||||
|
|
||||||
package com.freeturn.app.ui.screens
|
package com.freeturn.app.ui.screens
|
||||||
|
|
||||||
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.imePadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
@@ -18,11 +22,14 @@ import androidx.compose.material.icons.Icons
|
|||||||
import androidx.compose.material.icons.filled.ExpandLess
|
import androidx.compose.material.icons.filled.ExpandLess
|
||||||
import androidx.compose.material.icons.filled.ExpandMore
|
import androidx.compose.material.icons.filled.ExpandMore
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.Divider
|
import androidx.compose.material3.DividerDefaults
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Slider
|
import androidx.compose.material3.Slider
|
||||||
@@ -56,6 +63,13 @@ fun ClientSetupScreen(
|
|||||||
onFinish: (() -> Unit)? = null
|
onFinish: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
val saved by viewModel.clientConfig.collectAsStateWithLifecycle()
|
val saved by viewModel.clientConfig.collectAsStateWithLifecycle()
|
||||||
|
val sshConfig by viewModel.sshConfig.collectAsStateWithLifecycle()
|
||||||
|
val proxyListen by viewModel.proxyListen.collectAsStateWithLifecycle()
|
||||||
|
val customKernelExists by viewModel.customKernelExists.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
val kernelPickerLauncher = rememberLauncherForActivityResult(
|
||||||
|
ActivityResultContracts.OpenDocument()
|
||||||
|
) { uri -> uri?.let { viewModel.setCustomKernel(it) } }
|
||||||
|
|
||||||
var serverAddress by rememberSaveable(saved.serverAddress) { mutableStateOf(saved.serverAddress) }
|
var serverAddress by rememberSaveable(saved.serverAddress) { mutableStateOf(saved.serverAddress) }
|
||||||
var vkLink by rememberSaveable(saved.vkLink) { mutableStateOf(saved.vkLink) }
|
var vkLink by rememberSaveable(saved.vkLink) { mutableStateOf(saved.vkLink) }
|
||||||
@@ -65,6 +79,14 @@ fun ClientSetupScreen(
|
|||||||
var localPort by rememberSaveable(saved.localPort) { mutableStateOf(saved.localPort) }
|
var localPort by rememberSaveable(saved.localPort) { mutableStateOf(saved.localPort) }
|
||||||
var showAdvanced by rememberSaveable { mutableStateOf(false) }
|
var showAdvanced by rememberSaveable { mutableStateOf(false) }
|
||||||
|
|
||||||
|
// Автозаполнение адреса сервера из SSH-конфига если поле пустое
|
||||||
|
LaunchedEffect(sshConfig.ip, proxyListen) {
|
||||||
|
if (serverAddress.isBlank() && sshConfig.ip.isNotBlank()) {
|
||||||
|
val port = proxyListen.substringAfterLast(":", "56000")
|
||||||
|
serverAddress = "${sshConfig.ip}:$port"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Авто-сохранение с дебаунсом 600 мс на каждое изменение поля.
|
// Авто-сохранение с дебаунсом 600 мс на каждое изменение поля.
|
||||||
// Работает в обоих режимах — и при онбординге, и как вкладка.
|
// Работает в обоих режимах — и при онбординге, и как вкладка.
|
||||||
LaunchedEffect(serverAddress, vkLink, threads, useUdp, noDtls, localPort) {
|
LaunchedEffect(serverAddress, vkLink, threads, useUdp, noDtls, localPort) {
|
||||||
@@ -84,12 +106,14 @@ fun ClientSetupScreen(
|
|||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(title = { Text("Клиент") })
|
TopAppBar(title = { Text("Клиент") })
|
||||||
}
|
},
|
||||||
|
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||||
) { padding ->
|
) { padding ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
|
.imePadding()
|
||||||
.padding(horizontal = 24.dp)
|
.padding(horizontal = 24.dp)
|
||||||
.verticalScroll(rememberScrollState()),
|
.verticalScroll(rememberScrollState()),
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
@@ -120,7 +144,7 @@ fun ClientSetupScreen(
|
|||||||
supportingText = { Text("VK: Звонки → Создать → Скопировать ссылку (не нажимайте «Завершить»)") }
|
supportingText = { Text("VK: Звонки → Создать → Скопировать ссылку (не нажимайте «Завершить»)") }
|
||||||
)
|
)
|
||||||
|
|
||||||
Divider()
|
HorizontalDivider(Modifier, DividerDefaults.Thickness, DividerDefaults.color)
|
||||||
|
|
||||||
// ── Параметры ─────────────────────────────────────────────────
|
// ── Параметры ─────────────────────────────────────────────────
|
||||||
Text("Параметры", style = MaterialTheme.typography.titleMedium)
|
Text("Параметры", style = MaterialTheme.typography.titleMedium)
|
||||||
@@ -162,7 +186,7 @@ fun ClientSetupScreen(
|
|||||||
onCheckedChange = { noDtls = it }
|
onCheckedChange = { noDtls = it }
|
||||||
)
|
)
|
||||||
|
|
||||||
Divider()
|
HorizontalDivider(Modifier, DividerDefaults.Thickness, DividerDefaults.color)
|
||||||
|
|
||||||
// ── Дополнительно (сворачиваемый) ─────────────────────────────
|
// ── Дополнительно (сворачиваемый) ─────────────────────────────
|
||||||
Card(
|
Card(
|
||||||
@@ -202,6 +226,55 @@ fun ClientSetupScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HorizontalDivider(Modifier, DividerDefaults.Thickness, DividerDefaults.color)
|
||||||
|
|
||||||
|
// ── Ядро ──────────────────────────────────────────────────────
|
||||||
|
Text("Ядро", style = MaterialTheme.typography.titleMedium)
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = if (customKernelExists)
|
||||||
|
MaterialTheme.colorScheme.secondaryContainer
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(
|
||||||
|
if (customKernelExists) "Кастомное ядро" else "Встроенное ядро",
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
if (customKernelExists) "Загружено из памяти устройства"
|
||||||
|
else "Из APK (libvkturn.so)",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.55f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
if (customKernelExists) {
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { viewModel.clearCustomKernel() },
|
||||||
|
colors = ButtonDefaults.outlinedButtonColors(
|
||||||
|
contentColor = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
) { Text("Сбросить") }
|
||||||
|
}
|
||||||
|
Button(onClick = { kernelPickerLauncher.launch(arrayOf("*/*")) }) {
|
||||||
|
Text("Загрузить")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Кнопка «Завершить» — только в онбординг-флоу
|
// Кнопка «Завершить» — только в онбординг-флоу
|
||||||
if (showFinishButton && onFinish != null) {
|
if (showFinishButton && onFinish != null) {
|
||||||
Spacer(Modifier.height(8.dp))
|
Spacer(Modifier.height(8.dp))
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
@file:OptIn(
|
@file:OptIn(androidx.compose.material3.ExperimentalMaterial3Api::class)
|
||||||
androidx.compose.material3.ExperimentalMaterial3Api::class,
|
|
||||||
androidx.compose.material3.ExperimentalMaterial3ExpressiveApi::class
|
|
||||||
)
|
|
||||||
|
|
||||||
package com.freeturn.app.ui.screens
|
package com.freeturn.app.ui.screens
|
||||||
|
|
||||||
@@ -11,6 +8,7 @@ import androidx.compose.animation.core.animateFloatAsState
|
|||||||
import androidx.compose.animation.core.spring
|
import androidx.compose.animation.core.spring
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -26,29 +24,22 @@ import androidx.compose.foundation.rememberScrollState
|
|||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.Launch
|
||||||
import androidx.compose.material.icons.filled.CheckCircle
|
import androidx.compose.material.icons.filled.CheckCircle
|
||||||
import androidx.compose.material.icons.filled.CloudDownload
|
import androidx.compose.material.icons.filled.ContentCopy
|
||||||
import androidx.compose.material.icons.filled.Error
|
import androidx.compose.material.icons.filled.Error
|
||||||
import androidx.compose.material.icons.filled.Info
|
import androidx.compose.material.icons.filled.Info
|
||||||
import androidx.compose.material.icons.filled.PlayArrow
|
import androidx.compose.material.icons.filled.PlayArrow
|
||||||
import androidx.compose.material.icons.filled.Refresh
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
import androidx.compose.material.icons.filled.Settings
|
|
||||||
import androidx.compose.material.icons.filled.Stop
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.ButtonDefaults
|
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.CircularWavyProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Divider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.FilledTonalButton
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
|
||||||
import androidx.compose.material3.LinearWavyProgressIndicator
|
|
||||||
import androidx.compose.material3.ListItem
|
import androidx.compose.material3.ListItem
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.OutlinedButton
|
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.SnackbarHost
|
import androidx.compose.material3.SnackbarHost
|
||||||
import androidx.compose.material3.SnackbarHostState
|
import androidx.compose.material3.SnackbarHostState
|
||||||
@@ -57,7 +48,20 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.PowerManager
|
||||||
|
import android.provider.Settings
|
||||||
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -67,43 +71,88 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import com.freeturn.app.ui.HapticUtil
|
||||||
import com.freeturn.app.ui.theme.StatusGreen
|
import com.freeturn.app.ui.theme.StatusGreen
|
||||||
import com.freeturn.app.ui.theme.StatusGreenDark
|
import com.freeturn.app.ui.theme.StatusGreenDark
|
||||||
import com.freeturn.app.ui.theme.StatusRed
|
|
||||||
import com.freeturn.app.viewmodel.MainViewModel
|
import com.freeturn.app.viewmodel.MainViewModel
|
||||||
import com.freeturn.app.viewmodel.ProxyState
|
import com.freeturn.app.viewmodel.ProxyState
|
||||||
import com.freeturn.app.viewmodel.ServerState
|
|
||||||
import com.freeturn.app.viewmodel.SshConnectionState
|
import com.freeturn.app.viewmodel.SshConnectionState
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
|
||||||
|
@SuppressLint("BatteryLife")
|
||||||
@Composable
|
@Composable
|
||||||
fun HomeScreen(
|
fun HomeScreen(
|
||||||
viewModel: MainViewModel,
|
viewModel: MainViewModel,
|
||||||
onNavigateToSshSetup: () -> Unit
|
onNavigateToSshSetup: () -> Unit,
|
||||||
|
onNavigateToClientSetup: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val proxyState by viewModel.proxyState.collectAsStateWithLifecycle()
|
val proxyState by viewModel.proxyState.collectAsStateWithLifecycle()
|
||||||
val sshState by viewModel.sshState.collectAsStateWithLifecycle()
|
val sshState by viewModel.sshState.collectAsStateWithLifecycle()
|
||||||
val serverState by viewModel.serverState.collectAsStateWithLifecycle()
|
|
||||||
val clientConfig by viewModel.clientConfig.collectAsStateWithLifecycle()
|
val clientConfig by viewModel.clientConfig.collectAsStateWithLifecycle()
|
||||||
val logs by viewModel.logs.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
var showBottomSheet by rememberSaveable { mutableStateOf(false) }
|
// ── Запрос разрешений при первом открытии главного экрана ─────────────
|
||||||
|
val batteryOptLauncher = rememberLauncherForActivityResult(
|
||||||
|
ActivityResultContracts.StartActivityForResult()
|
||||||
|
) { /* пользователь закрыл диалог батареи — результат нас не интересует */ }
|
||||||
|
|
||||||
|
val notificationLauncher = rememberLauncherForActivityResult(
|
||||||
|
ActivityResultContracts.RequestPermission()
|
||||||
|
) { _ ->
|
||||||
|
// После диалога уведомлений — запрашиваем исключение из оптимизации батареи
|
||||||
|
val pm = context.getSystemService(PowerManager::class.java)
|
||||||
|
if (!pm.isIgnoringBatteryOptimizations(context.packageName)) {
|
||||||
|
batteryOptLauncher.launch(
|
||||||
|
Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
||||||
|
data = "package:${context.packageName}".toUri()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
delay(400) // даём экрану отрисоваться
|
||||||
|
val needsNotification = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
|
||||||
|
ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) !=
|
||||||
|
PackageManager.PERMISSION_GRANTED
|
||||||
|
|
||||||
|
if (needsNotification) {
|
||||||
|
// Запрашиваем нотификации; батарею запросим в callback выше
|
||||||
|
notificationLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||||
|
} else {
|
||||||
|
// Нотификации уже есть — сразу проверяем батарею
|
||||||
|
val pm = context.getSystemService(PowerManager::class.java)
|
||||||
|
if (!pm.isIgnoringBatteryOptimizations(context.packageName)) {
|
||||||
|
batteryOptLauncher.launch(
|
||||||
|
Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
||||||
|
data = "package:${context.packageName}".toUri()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val showBottomSheet = rememberSaveable { mutableStateOf(false) }
|
||||||
val bottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
val bottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||||
val snackbarHostState = remember { SnackbarHostState() }
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = { Text("VK TURN Proxy") },
|
title = { Text("Turn Proxy") },
|
||||||
actions = {
|
actions = {
|
||||||
// Кнопка «Детали и логи» через иконку — без ••• меню
|
IconButton(onClick = {
|
||||||
IconButton(onClick = { showBottomSheet = true }) {
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
Icon(Icons.Filled.Info, contentDescription = "Детали")
|
showBottomSheet.value = true
|
||||||
|
}) {
|
||||||
|
Icon(Icons.Filled.Info, contentDescription = "Информация")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -119,13 +168,18 @@ fun HomeScreen(
|
|||||||
) {
|
) {
|
||||||
Spacer(Modifier.height(40.dp))
|
Spacer(Modifier.height(40.dp))
|
||||||
|
|
||||||
// Big power button
|
|
||||||
ProxyToggleButton(
|
ProxyToggleButton(
|
||||||
state = proxyState,
|
state = proxyState,
|
||||||
onClick = {
|
onClick = {
|
||||||
when (proxyState) {
|
when (proxyState) {
|
||||||
is ProxyState.Idle, is ProxyState.Error -> viewModel.startProxy(context)
|
is ProxyState.Idle, is ProxyState.Error -> {
|
||||||
is ProxyState.Running -> viewModel.stopProxy(context)
|
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
||||||
|
viewModel.startProxy(context)
|
||||||
|
}
|
||||||
|
is ProxyState.Running -> {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_OFF)
|
||||||
|
viewModel.stopProxy(context)
|
||||||
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +187,6 @@ fun HomeScreen(
|
|||||||
|
|
||||||
Spacer(Modifier.height(24.dp))
|
Spacer(Modifier.height(24.dp))
|
||||||
|
|
||||||
// State label
|
|
||||||
Text(
|
Text(
|
||||||
text = when (proxyState) {
|
text = when (proxyState) {
|
||||||
is ProxyState.Running -> "Прокси активен"
|
is ProxyState.Running -> "Прокси активен"
|
||||||
@@ -152,28 +205,14 @@ fun HomeScreen(
|
|||||||
|
|
||||||
Spacer(Modifier.height(40.dp))
|
Spacer(Modifier.height(40.dp))
|
||||||
|
|
||||||
// Config summary card
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 24.dp),
|
.padding(horizontal = 24.dp),
|
||||||
onClick = { showBottomSheet = true },
|
|
||||||
elevation = CardDefaults.cardElevation(2.dp)
|
elevation = CardDefaults.cardElevation(2.dp)
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(20.dp)) {
|
Column(modifier = Modifier.padding(20.dp)) {
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
Text("Текущие настройки", style = MaterialTheme.typography.titleSmall)
|
Text("Текущие настройки", style = MaterialTheme.typography.titleSmall)
|
||||||
Icon(
|
|
||||||
Icons.Filled.Settings,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(18.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Spacer(Modifier.height(12.dp))
|
Spacer(Modifier.height(12.dp))
|
||||||
if (clientConfig.serverAddress.isNotBlank()) {
|
if (clientConfig.serverAddress.isNotBlank()) {
|
||||||
ConfigRow("Сервер", clientConfig.serverAddress)
|
ConfigRow("Сервер", clientConfig.serverAddress)
|
||||||
@@ -182,7 +221,7 @@ fun HomeScreen(
|
|||||||
ConfigRow("Локальный порт", clientConfig.localPort)
|
ConfigRow("Локальный порт", clientConfig.localPort)
|
||||||
} else {
|
} else {
|
||||||
Text(
|
Text(
|
||||||
"Не настроено. Нажмите для настройки.",
|
"Не настроено. Перейдите в раздел «Клиент».",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f)
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f)
|
||||||
)
|
)
|
||||||
@@ -192,7 +231,6 @@ fun HomeScreen(
|
|||||||
|
|
||||||
Spacer(Modifier.height(16.dp))
|
Spacer(Modifier.height(16.dp))
|
||||||
|
|
||||||
// SSH status row
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -221,7 +259,13 @@ fun HomeScreen(
|
|||||||
)
|
)
|
||||||
if (sshState !is SshConnectionState.Connected) {
|
if (sshState !is SshConnectionState.Connected) {
|
||||||
Spacer(Modifier.width(8.dp))
|
Spacer(Modifier.width(8.dp))
|
||||||
TextButton(onClick = { viewModel.reconnectSsh() }, modifier = Modifier.height(28.dp)) {
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
|
viewModel.reconnectSsh()
|
||||||
|
},
|
||||||
|
modifier = Modifier.height(28.dp)
|
||||||
|
) {
|
||||||
Text("Переподключить", style = MaterialTheme.typography.labelSmall)
|
Text("Переподключить", style = MaterialTheme.typography.labelSmall)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,16 +275,17 @@ fun HomeScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottom sheet with all settings
|
if (showBottomSheet.value) {
|
||||||
if (showBottomSheet) {
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = { showBottomSheet = false },
|
onDismissRequest = { showBottomSheet.value = false },
|
||||||
sheetState = bottomSheetState
|
sheetState = bottomSheetState
|
||||||
) {
|
) {
|
||||||
SettingsBottomSheet(
|
InfoBottomSheet(
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateToSshSetup = { showBottomSheet = false; onNavigateToSshSetup() },
|
onNavigateToSshSetup = {
|
||||||
onDismiss = { showBottomSheet = false }
|
showBottomSheet.value = false
|
||||||
|
onNavigateToSshSetup()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,7 +335,7 @@ private fun ProxyToggleButton(state: ProxyState, onClick: () -> Unit) {
|
|||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center
|
||||||
) {
|
) {
|
||||||
when (state) {
|
when (state) {
|
||||||
is ProxyState.Starting -> CircularWavyProgressIndicator(color = contentColor)
|
is ProxyState.Starting -> CircularProgressIndicator(color = contentColor)
|
||||||
is ProxyState.Running -> Icon(
|
is ProxyState.Running -> Icon(
|
||||||
Icons.Filled.CheckCircle, null,
|
Icons.Filled.CheckCircle, null,
|
||||||
Modifier.size(52.dp), tint = contentColor
|
Modifier.size(52.dp), tint = contentColor
|
||||||
@@ -309,153 +354,93 @@ private fun ProxyToggleButton(state: ProxyState, onClick: () -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun SettingsBottomSheet(
|
private fun InfoBottomSheet(
|
||||||
viewModel: MainViewModel,
|
viewModel: MainViewModel,
|
||||||
onNavigateToSshSetup: () -> Unit,
|
onNavigateToSshSetup: () -> Unit
|
||||||
onDismiss: () -> Unit
|
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val uriHandler = LocalUriHandler.current
|
||||||
val sshState by viewModel.sshState.collectAsStateWithLifecycle()
|
val sshState by viewModel.sshState.collectAsStateWithLifecycle()
|
||||||
val serverState by viewModel.serverState.collectAsStateWithLifecycle()
|
|
||||||
val clientConfig by viewModel.clientConfig.collectAsStateWithLifecycle()
|
|
||||||
val logs by viewModel.logs.collectAsStateWithLifecycle()
|
val logs by viewModel.logs.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val isConnected = sshState is SshConnectionState.Connected
|
|
||||||
val isWorking = serverState is ServerState.Working || serverState is ServerState.Checking
|
|
||||||
val serverKnown = serverState as? ServerState.Known
|
|
||||||
var showLogs by rememberSaveable { mutableStateOf(false) }
|
var showLogs by rememberSaveable { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val appVersion = remember {
|
||||||
|
try { context.packageManager.getPackageInfo(context.packageName, 0).versionName ?: "—" }
|
||||||
|
catch (_: Exception) { "—" }
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(bottom = 32.dp)
|
.padding(bottom = 16.dp)
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
) {
|
) {
|
||||||
// ── Сервер ────────────────────────────────────────────────────────
|
// ── SSH ────────────────────────────────────────────────────────────
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text("Сервер", style = MaterialTheme.typography.titleSmall) },
|
headlineContent = { Text("Соединение", style = MaterialTheme.typography.titleSmall) },
|
||||||
trailingContent = {
|
trailingContent = {
|
||||||
TextButton(onClick = onNavigateToSshSetup) { Text("Изменить") }
|
TextButton(onClick = {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
|
onNavigateToSshSetup()
|
||||||
|
}) { Text("Настроить") }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Divider()
|
HorizontalDivider()
|
||||||
|
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text("SSH-соединение") },
|
headlineContent = { Text("SSH-статус") },
|
||||||
supportingContent = {
|
supportingContent = {
|
||||||
Text(
|
Text(
|
||||||
when (sshState) {
|
when (sshState) {
|
||||||
is SshConnectionState.Connected -> "Подключено: ${(sshState as SshConnectionState.Connected).ip}"
|
is SshConnectionState.Connected ->
|
||||||
is SshConnectionState.Connecting -> "Подключение..."
|
"Подключено: ${(sshState as SshConnectionState.Connected).ip}"
|
||||||
is SshConnectionState.Error -> "Ошибка: ${(sshState as SshConnectionState.Error).message}"
|
is SshConnectionState.Connecting ->
|
||||||
|
(sshState as SshConnectionState.Connecting).step
|
||||||
|
is SshConnectionState.Error ->
|
||||||
|
"Ошибка: ${(sshState as SshConnectionState.Error).message}"
|
||||||
else -> "Не подключено"
|
else -> "Не подключено"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
trailingContent = {
|
trailingContent = {
|
||||||
if (sshState !is SshConnectionState.Connected) {
|
if (sshState is SshConnectionState.Connected) {
|
||||||
IconButton(onClick = { viewModel.reconnectSsh() }) {
|
|
||||||
Icon(Icons.Filled.Refresh, null)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Box(Modifier.size(10.dp).background(StatusGreen, CircleShape))
|
Box(Modifier.size(10.dp).background(StatusGreen, CircleShape))
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
ListItem(
|
|
||||||
headlineContent = { Text("vk-turn-proxy") },
|
|
||||||
supportingContent = {
|
|
||||||
Text(
|
|
||||||
when {
|
|
||||||
serverKnown?.running == true -> "Запущен"
|
|
||||||
serverKnown?.installed == true -> "Установлен, не запущен"
|
|
||||||
serverKnown?.installed == false -> "Не установлен"
|
|
||||||
isWorking -> (serverState as? ServerState.Working)?.action ?: "Проверка..."
|
|
||||||
else -> "Статус неизвестен"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (isWorking) {
|
|
||||||
LinearProgressIndicator(modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp))
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
FilledTonalButton(
|
|
||||||
onClick = { viewModel.installServer() },
|
|
||||||
enabled = isConnected && !isWorking,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Filled.CloudDownload, null, Modifier.size(16.dp))
|
|
||||||
Spacer(Modifier.width(4.dp))
|
|
||||||
Text("Обновить", style = MaterialTheme.typography.labelSmall)
|
|
||||||
}
|
|
||||||
Button(
|
|
||||||
onClick = { viewModel.startServer() },
|
|
||||||
enabled = isConnected && !isWorking && serverKnown?.installed == true && serverKnown?.running == false,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Filled.PlayArrow, null, Modifier.size(16.dp))
|
|
||||||
Spacer(Modifier.width(4.dp))
|
|
||||||
Text("Запустить", style = MaterialTheme.typography.labelSmall)
|
|
||||||
}
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = { viewModel.stopServer() },
|
|
||||||
enabled = isConnected && !isWorking && serverKnown?.running == true,
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
colors = ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.colorScheme.error)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Filled.Stop, null, Modifier.size(16.dp))
|
|
||||||
Spacer(Modifier.width(4.dp))
|
|
||||||
Text("Стоп", style = MaterialTheme.typography.labelSmall)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Divider()
|
|
||||||
|
|
||||||
// ── Клиент ────────────────────────────────────────────────────────
|
|
||||||
ListItem(
|
|
||||||
headlineContent = { Text("Клиент", style = MaterialTheme.typography.titleSmall) }
|
|
||||||
)
|
|
||||||
Divider()
|
|
||||||
|
|
||||||
if (clientConfig.serverAddress.isNotBlank()) {
|
|
||||||
ListItem(headlineContent = { Text("Сервер") },
|
|
||||||
supportingContent = { Text(clientConfig.serverAddress) })
|
|
||||||
ListItem(headlineContent = { Text("Ссылка VK/Yandex") },
|
|
||||||
supportingContent = {
|
|
||||||
Text(
|
|
||||||
clientConfig.vkLink.take(60) + if (clientConfig.vkLink.length > 60) "..." else "",
|
|
||||||
maxLines = 2
|
|
||||||
)
|
|
||||||
})
|
|
||||||
ListItem(headlineContent = { Text("Потоки / UDP / DTLS") },
|
|
||||||
supportingContent = {
|
|
||||||
Text("${clientConfig.threads} потоков · UDP: ${if (clientConfig.useUdp) "вкл" else "выкл"} · DTLS: ${if (clientConfig.noDtls) "выкл" else "вкл"}")
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
ListItem(
|
IconButton(onClick = {
|
||||||
headlineContent = { Text("Не настроено") },
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
supportingContent = { Text("Нажмите «Изменить» для настройки клиента") }
|
viewModel.reconnectSsh()
|
||||||
)
|
}) {
|
||||||
|
Icon(Icons.Filled.Refresh, contentDescription = "Переподключить")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
Divider()
|
HorizontalDivider()
|
||||||
|
|
||||||
// ── Логи ─────────────────────────────────────────────────────────
|
// ── Логи ──────────────────────────────────────────────────────────
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text("Логи", style = MaterialTheme.typography.titleSmall) },
|
headlineContent = { Text("Логи", style = MaterialTheme.typography.titleSmall) },
|
||||||
trailingContent = {
|
trailingContent = {
|
||||||
Row {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
TextButton(onClick = { viewModel.clearLogs() }) { Text("Очистить") }
|
IconButton(
|
||||||
TextButton(onClick = { showLogs = !showLogs }) {
|
onClick = {
|
||||||
|
val cm = context.getSystemService(ClipboardManager::class.java)
|
||||||
|
cm.setPrimaryClip(ClipData.newPlainText("proxy_logs", logs.joinToString("\n")))
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.SUCCESS)
|
||||||
|
},
|
||||||
|
enabled = logs.isNotEmpty()
|
||||||
|
) {
|
||||||
|
Icon(Icons.Filled.ContentCopy, contentDescription = "Копировать логи", modifier = Modifier.size(18.dp))
|
||||||
|
}
|
||||||
|
TextButton(onClick = {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||||
|
viewModel.clearLogs()
|
||||||
|
}) { Text("Очистить") }
|
||||||
|
TextButton(onClick = {
|
||||||
|
HapticUtil.perform(context, HapticUtil.Pattern.SELECTION)
|
||||||
|
showLogs = !showLogs
|
||||||
|
}) {
|
||||||
Text(if (showLogs) "Скрыть" else "Показать")
|
Text(if (showLogs) "Скрыть" else "Показать")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -463,38 +448,151 @@ private fun SettingsBottomSheet(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (showLogs) {
|
if (showLogs) {
|
||||||
val recentLogs = logs.takeLast(30)
|
LogsPanel(
|
||||||
Card(
|
logs = logs,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 16.dp, vertical = 4.dp),
|
.padding(horizontal = 16.dp, vertical = 4.dp)
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.padding(12.dp)) {
|
|
||||||
if (recentLogs.isEmpty()) {
|
|
||||||
Text(
|
|
||||||
"Нет логов",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
recentLogs.forEach { line ->
|
|
||||||
Text(
|
|
||||||
line,
|
|
||||||
style = MaterialTheme.typography.bodySmall.copy(
|
|
||||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace
|
|
||||||
),
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(Modifier.height(8.dp))
|
HorizontalDivider()
|
||||||
|
|
||||||
|
// ── О приложении ───────────────────────────────────────────────────
|
||||||
|
ListItem(
|
||||||
|
headlineContent = { Text("О приложении", style = MaterialTheme.typography.titleSmall) }
|
||||||
|
)
|
||||||
|
|
||||||
|
ListItem(
|
||||||
|
headlineContent = { Text("FreeTurn") },
|
||||||
|
supportingContent = { Text("Версия $appVersion") }
|
||||||
|
)
|
||||||
|
|
||||||
|
RepoLinkItem(
|
||||||
|
title = "Android-клиент",
|
||||||
|
subtitle = "Fork MYSOREZ/vk-turn-proxy-android",
|
||||||
|
url = "https://github.com/MYSOREZ/vk-turn-proxy-android",
|
||||||
|
onHaptic = { HapticUtil.perform(context, HapticUtil.Pattern.SELECTION) },
|
||||||
|
onOpen = { uriHandler.openUri(it) }
|
||||||
|
)
|
||||||
|
|
||||||
|
RepoLinkItem(
|
||||||
|
title = "Прокси-ядро",
|
||||||
|
subtitle = "cacggghp/vk-turn-proxy",
|
||||||
|
url = "https://github.com/cacggghp/vk-turn-proxy",
|
||||||
|
onHaptic = { HapticUtil.perform(context, HapticUtil.Pattern.SELECTION) },
|
||||||
|
onOpen = { uriHandler.openUri(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RepoLinkItem(
|
||||||
|
title: String,
|
||||||
|
subtitle: String,
|
||||||
|
url: String,
|
||||||
|
onHaptic: () -> Unit,
|
||||||
|
onOpen: (String) -> Unit
|
||||||
|
) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = { Text(title) },
|
||||||
|
supportingContent = {
|
||||||
|
Text(
|
||||||
|
subtitle,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
},
|
||||||
|
trailingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.Launch,
|
||||||
|
contentDescription = "Открыть",
|
||||||
|
modifier = Modifier.size(18.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
onHaptic()
|
||||||
|
onOpen(url)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun LogsPanel(logs: List<String>, modifier: Modifier = Modifier) {
|
||||||
|
Card(
|
||||||
|
modifier = modifier,
|
||||||
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant)
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.padding(vertical = 8.dp)) {
|
||||||
|
if (logs.isEmpty()) {
|
||||||
|
Text(
|
||||||
|
"Нет логов",
|
||||||
|
modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.4f)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
logs.takeLast(50).forEachIndexed { index, line ->
|
||||||
|
LogLine(line = line, isEven = index % 2 == 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun LogLine(line: String, isEven: Boolean) {
|
||||||
|
val lower = line.lowercase()
|
||||||
|
val isHeader = line.startsWith("===")
|
||||||
|
val isError = lower.contains("ошибка") || lower.contains("error") ||
|
||||||
|
lower.contains("критическая") || lower.contains("failed") ||
|
||||||
|
lower.contains("fatal") || lower.contains("panic")
|
||||||
|
val isWarning = lower.contains("watchdog") || lower.contains("перезапуск") ||
|
||||||
|
lower.contains("quota") || lower.contains("warn") ||
|
||||||
|
lower.contains(">>>")
|
||||||
|
val isSuccess = lower.contains("запущен") || lower.contains("подключен") ||
|
||||||
|
lower.contains("success") || lower.contains("started") ||
|
||||||
|
lower.contains("ok")
|
||||||
|
|
||||||
|
val textColor = when {
|
||||||
|
isError -> MaterialTheme.colorScheme.error
|
||||||
|
isWarning -> androidx.compose.ui.graphics.Color(0xFFE67E22)
|
||||||
|
isSuccess -> StatusGreen
|
||||||
|
isHeader -> MaterialTheme.colorScheme.primary
|
||||||
|
else -> MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
}
|
||||||
|
val bgColor = if (isEven)
|
||||||
|
MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.6f)
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(bgColor)
|
||||||
|
.padding(horizontal = 12.dp, vertical = 3.dp),
|
||||||
|
verticalAlignment = Alignment.Top
|
||||||
|
) {
|
||||||
|
if (isHeader || isError || isWarning || isSuccess) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(top = 5.dp, end = 6.dp)
|
||||||
|
.size(5.dp)
|
||||||
|
.background(textColor, CircleShape)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Spacer(Modifier.width(11.dp))
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = line.removePrefix("=== ").removeSuffix(" ==="),
|
||||||
|
style = MaterialTheme.typography.bodySmall.copy(
|
||||||
|
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
|
||||||
|
fontWeight = if (isHeader) androidx.compose.ui.text.font.FontWeight.SemiBold
|
||||||
|
else androidx.compose.ui.text.font.FontWeight.Normal
|
||||||
|
),
|
||||||
|
color = textColor
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,8 +602,11 @@ private fun ConfigRow(label: String, value: String) {
|
|||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(label, style = MaterialTheme.typography.bodySmall,
|
Text(
|
||||||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f))
|
label,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
|
||||||
|
)
|
||||||
Text(value, style = MaterialTheme.typography.bodySmall)
|
Text(value, style = MaterialTheme.typography.bodySmall)
|
||||||
}
|
}
|
||||||
Spacer(Modifier.height(4.dp))
|
Spacer(Modifier.height(4.dp))
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.width
|
|||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Security
|
import androidx.compose.material.icons.filled.Security
|
||||||
|
import androidx.compose.material.icons.filled.Sensors
|
||||||
import androidx.compose.material.icons.filled.Wifi
|
import androidx.compose.material.icons.filled.Wifi
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
@@ -86,7 +87,7 @@ fun OnboardingScreen(
|
|||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Filled.Security,
|
imageVector = Icons.Filled.Sensors,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(80.dp),
|
modifier = Modifier.size(80.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
@@ -96,7 +97,7 @@ fun OnboardingScreen(
|
|||||||
Spacer(Modifier.height(40.dp))
|
Spacer(Modifier.height(40.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "VK TURN Proxy",
|
text = "Turn Proxy",
|
||||||
style = MaterialTheme.typography.displaySmall,
|
style = MaterialTheme.typography.displaySmall,
|
||||||
color = MaterialTheme.colorScheme.onBackground,
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
@file:OptIn(
|
|
||||||
androidx.compose.material3.ExperimentalMaterial3Api::class,
|
|
||||||
androidx.compose.material3.ExperimentalMaterial3ExpressiveApi::class
|
|
||||||
)
|
|
||||||
|
|
||||||
package com.freeturn.app.ui.screens
|
package com.freeturn.app.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
@@ -11,9 +6,11 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.imePadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
@@ -28,11 +25,10 @@ import androidx.compose.material.icons.filled.Stop
|
|||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.FilledTonalButton
|
import androidx.compose.material3.FilledTonalButton
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.LinearWavyProgressIndicator
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
@@ -42,7 +38,6 @@ import androidx.compose.material3.SnackbarHostState
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -50,7 +45,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.freeturn.app.ui.theme.StatusGreen
|
import com.freeturn.app.ui.theme.StatusGreen
|
||||||
@@ -58,6 +52,7 @@ import com.freeturn.app.viewmodel.MainViewModel
|
|||||||
import com.freeturn.app.viewmodel.ServerState
|
import com.freeturn.app.viewmodel.ServerState
|
||||||
import com.freeturn.app.viewmodel.SshConnectionState
|
import com.freeturn.app.viewmodel.SshConnectionState
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ServerManagementScreen(
|
fun ServerManagementScreen(
|
||||||
viewModel: MainViewModel,
|
viewModel: MainViewModel,
|
||||||
@@ -86,12 +81,14 @@ fun ServerManagementScreen(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
snackbarHost = { SnackbarHost(snackbarHostState) }
|
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||||
|
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||||
) { padding ->
|
) { padding ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
|
.imePadding()
|
||||||
.padding(horizontal = 24.dp)
|
.padding(horizontal = 24.dp)
|
||||||
.verticalScroll(rememberScrollState()),
|
.verticalScroll(rememberScrollState()),
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
@@ -120,7 +117,7 @@ fun ServerManagementScreen(
|
|||||||
color = MaterialTheme.colorScheme.secondary
|
color = MaterialTheme.colorScheme.secondary
|
||||||
)
|
)
|
||||||
Spacer(Modifier.height(6.dp))
|
Spacer(Modifier.height(6.dp))
|
||||||
LinearWavyProgressIndicator(modifier = Modifier.fillMaxWidth())
|
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||||
}
|
}
|
||||||
is ServerState.Error -> {
|
is ServerState.Error -> {
|
||||||
Spacer(Modifier.height(12.dp))
|
Spacer(Modifier.height(12.dp))
|
||||||
@@ -172,7 +169,7 @@ fun ServerManagementScreen(
|
|||||||
) {
|
) {
|
||||||
Icon(Icons.Filled.CloudDownload, null)
|
Icon(Icons.Filled.CloudDownload, null)
|
||||||
Spacer(Modifier.width(8.dp))
|
Spacer(Modifier.width(8.dp))
|
||||||
Text("Установить / Обновить")
|
Text(if (serverKnown?.installed == true) "Обновить" else "Установить")
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
@file:OptIn(
|
|
||||||
androidx.compose.material3.ExperimentalMaterial3Api::class,
|
|
||||||
androidx.compose.material3.ExperimentalMaterial3ExpressiveApi::class
|
|
||||||
)
|
|
||||||
|
|
||||||
package com.freeturn.app.ui.screens
|
package com.freeturn.app.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.imePadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
@@ -19,7 +16,7 @@ import androidx.compose.foundation.rememberScrollState
|
|||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material.icons.filled.CheckCircle
|
import androidx.compose.material.icons.filled.CheckCircle
|
||||||
import androidx.compose.material.icons.filled.Error
|
import androidx.compose.material.icons.filled.Error
|
||||||
import androidx.compose.material.icons.filled.RadioButtonChecked
|
import androidx.compose.material.icons.filled.RadioButtonChecked
|
||||||
@@ -30,17 +27,17 @@ import androidx.compose.material3.Button
|
|||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.LinearWavyProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.MenuAnchorType
|
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
@@ -61,6 +58,7 @@ import com.freeturn.app.data.SshConfig
|
|||||||
import com.freeturn.app.viewmodel.MainViewModel
|
import com.freeturn.app.viewmodel.MainViewModel
|
||||||
import com.freeturn.app.viewmodel.SshConnectionState
|
import com.freeturn.app.viewmodel.SshConnectionState
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun SshSetupScreen(
|
fun SshSetupScreen(
|
||||||
viewModel: MainViewModel,
|
viewModel: MainViewModel,
|
||||||
@@ -91,16 +89,18 @@ fun SshSetupScreen(
|
|||||||
title = { Text("Подключение к серверу") },
|
title = { Text("Подключение к серверу") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = onBack) {
|
IconButton(onClick = onBack) {
|
||||||
Icon(Icons.Filled.ArrowBack, contentDescription = "Назад")
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Назад")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||||
) { padding ->
|
) { padding ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
|
.imePadding()
|
||||||
.padding(horizontal = 24.dp)
|
.padding(horizontal = 24.dp)
|
||||||
.verticalScroll(rememberScrollState()),
|
.verticalScroll(rememberScrollState()),
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
@@ -142,6 +142,7 @@ fun SshSetupScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun FormSection(
|
private fun FormSection(
|
||||||
ip: String, onIpChange: (String) -> Unit,
|
ip: String, onIpChange: (String) -> Unit,
|
||||||
@@ -197,7 +198,7 @@ private fun FormSection(
|
|||||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = authDropdownExpanded) },
|
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = authDropdownExpanded) },
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.menuAnchor(MenuAnchorType.PrimaryNotEditable)
|
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||||
)
|
)
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
expanded = authDropdownExpanded,
|
expanded = authDropdownExpanded,
|
||||||
@@ -290,7 +291,7 @@ private fun ConnectionProgressCard(step: String) {
|
|||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(20.dp)
|
verticalArrangement = Arrangement.spacedBy(20.dp)
|
||||||
) {
|
) {
|
||||||
LinearWavyProgressIndicator(modifier = Modifier.fillMaxWidth())
|
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = step,
|
text = step,
|
||||||
|
|||||||
@@ -3,20 +3,27 @@ package com.freeturn.app.viewmodel
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import androidx.lifecycle.AndroidViewModel
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.freeturn.app.ProxyService
|
import com.freeturn.app.ProxyService
|
||||||
import com.freeturn.app.SSHManager
|
import com.freeturn.app.SSHManager
|
||||||
import com.freeturn.app.data.AppPreferences
|
import com.freeturn.app.data.AppPreferences
|
||||||
|
import com.freeturn.app.ui.HapticUtil
|
||||||
import com.freeturn.app.data.ClientConfig
|
import com.freeturn.app.data.ClientConfig
|
||||||
import com.freeturn.app.data.SshConfig
|
import com.freeturn.app.data.SshConfig
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
// ── SSH connection states ──────────────────────────────────────────────────
|
// ── SSH connection states ──────────────────────────────────────────────────
|
||||||
sealed class SshConnectionState {
|
sealed class SshConnectionState {
|
||||||
@@ -54,6 +61,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
private val _serverState = MutableStateFlow<ServerState>(ServerState.Unknown)
|
private val _serverState = MutableStateFlow<ServerState>(ServerState.Unknown)
|
||||||
val serverState: StateFlow<ServerState> = _serverState.asStateFlow()
|
val serverState: StateFlow<ServerState> = _serverState.asStateFlow()
|
||||||
|
|
||||||
|
private val _serverVersion = MutableStateFlow<String?>(null)
|
||||||
|
val serverVersion: StateFlow<String?> = _serverVersion.asStateFlow()
|
||||||
|
|
||||||
private val _proxyState = MutableStateFlow<ProxyState>(ProxyState.Idle)
|
private val _proxyState = MutableStateFlow<ProxyState>(ProxyState.Idle)
|
||||||
val proxyState: StateFlow<ProxyState> = _proxyState.asStateFlow()
|
val proxyState: StateFlow<ProxyState> = _proxyState.asStateFlow()
|
||||||
|
|
||||||
@@ -63,6 +73,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
private val _isInitialized = MutableStateFlow(false)
|
private val _isInitialized = MutableStateFlow(false)
|
||||||
val isInitialized: StateFlow<Boolean> = _isInitialized.asStateFlow()
|
val isInitialized: StateFlow<Boolean> = _isInitialized.asStateFlow()
|
||||||
|
|
||||||
|
private val _customKernelExists = MutableStateFlow(false)
|
||||||
|
val customKernelExists: StateFlow<Boolean> = _customKernelExists.asStateFlow()
|
||||||
|
|
||||||
val sshConfig: StateFlow<SshConfig> = prefs.sshConfigFlow
|
val sshConfig: StateFlow<SshConfig> = prefs.sshConfigFlow
|
||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), SshConfig())
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), SshConfig())
|
||||||
|
|
||||||
@@ -80,16 +93,23 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// Wait for first real emit from DataStore before showing UI
|
// Wait for first real DataStore read before showing UI
|
||||||
onboardingDone.collect { _isInitialized.value = true }
|
prefs.onboardingDoneFlow.first()
|
||||||
|
_isInitialized.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
ProxyService.onLogReceived = { msg ->
|
ProxyService.onLogReceived = { msg ->
|
||||||
_logs.value = (_logs.value + msg).takeLast(200)
|
_logs.value = (_logs.value + msg).takeLast(200)
|
||||||
}
|
}
|
||||||
|
ProxyService.onProxyFailed = {
|
||||||
|
setErrorWithAutoReset("Прокси упал ${ProxyService.MAX_RESTARTS} раз — проверьте настройки")
|
||||||
|
}
|
||||||
_logs.value = ProxyService.logBuffer.toList()
|
_logs.value = ProxyService.logBuffer.toList()
|
||||||
|
|
||||||
if (ProxyService.isRunning) _proxyState.value = ProxyState.Running
|
if (ProxyService.isRunning) _proxyState.value = ProxyState.Running
|
||||||
|
|
||||||
|
_customKernelExists.value =
|
||||||
|
File(getApplication<Application>().filesDir, "custom_vkturn").exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── SSH ────────────────────────────────────────────────────────────────
|
// ── SSH ────────────────────────────────────────────────────────────────
|
||||||
@@ -111,9 +131,11 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
config.ip, config.port, config.username, config.password, "echo OK"
|
config.ip, config.port, config.username, config.password, "echo OK"
|
||||||
)
|
)
|
||||||
if (result.trim() == "OK") {
|
if (result.trim() == "OK") {
|
||||||
|
HapticUtil.perform(getApplication(), HapticUtil.Pattern.SUCCESS)
|
||||||
_sshState.value = SshConnectionState.Connected(config.ip)
|
_sshState.value = SshConnectionState.Connected(config.ip)
|
||||||
checkServerState(config)
|
checkServerState(config)
|
||||||
} else {
|
} else {
|
||||||
|
HapticUtil.perform(getApplication(), HapticUtil.Pattern.ERROR)
|
||||||
_sshState.value = SshConnectionState.Error(result.removePrefix("ERROR: "))
|
_sshState.value = SshConnectionState.Error(result.removePrefix("ERROR: "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,14 +163,31 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
_serverState.value = if (result.startsWith("ERROR")) {
|
_serverState.value = if (result.startsWith("ERROR")) {
|
||||||
ServerState.Error(result.removePrefix("ERROR: "))
|
ServerState.Error(result.removePrefix("ERROR: "))
|
||||||
} else {
|
} else {
|
||||||
ServerState.Known(
|
val known = ServerState.Known(
|
||||||
installed = result.contains("INSTALLED:YES"),
|
installed = result.contains("INSTALLED:YES"),
|
||||||
running = result.contains("RUNNING:YES")
|
running = result.contains("RUNNING:YES")
|
||||||
)
|
)
|
||||||
|
if (known.installed) fetchServerVersion(cfg)
|
||||||
|
known
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun fetchServerVersion(config: SshConfig? = null) {
|
||||||
|
val cfg = config ?: sshConfig.value
|
||||||
|
if (cfg.ip.isEmpty()) return
|
||||||
|
val cmd = """
|
||||||
|
cd /opt/vk-turn 2>/dev/null &&
|
||||||
|
ARCH=${'$'}(uname -m);
|
||||||
|
if [ "${'$'}ARCH" = "x86_64" ]; then BIN="./server-linux-amd64"; else BIN="./server-linux-arm64"; fi;
|
||||||
|
timeout 2 ${'$'}BIN -version 2>&1 | head -1
|
||||||
|
""".trimIndent()
|
||||||
|
viewModelScope.launch {
|
||||||
|
val out = sshManager.executeSilentCommand(cfg.ip, cfg.port, cfg.username, cfg.password, cmd)
|
||||||
|
_serverVersion.value = out.trim().takeIf { it.isNotEmpty() && !it.startsWith("ERROR") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun installServer() {
|
fun installServer() {
|
||||||
val cfg = sshConfig.value
|
val cfg = sshConfig.value
|
||||||
if (cfg.ip.isEmpty()) return
|
if (cfg.ip.isEmpty()) return
|
||||||
@@ -234,7 +273,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// Write to legacy SharedPreferences so ProxyService can read them
|
// Write to legacy SharedPreferences so ProxyService can read them
|
||||||
context.getSharedPreferences("ProxyPrefs", Context.MODE_PRIVATE).edit().apply {
|
context.getSharedPreferences("ProxyPrefs", Context.MODE_PRIVATE).edit {
|
||||||
putString("peer", cfg.serverAddress)
|
putString("peer", cfg.serverAddress)
|
||||||
putString("link", cfg.vkLink)
|
putString("link", cfg.vkLink)
|
||||||
putString("n", cfg.threads.toString())
|
putString("n", cfg.threads.toString())
|
||||||
@@ -243,7 +282,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
putString("listen", cfg.localPort)
|
putString("listen", cfg.localPort)
|
||||||
putBoolean("isRaw", cfg.isRawMode)
|
putBoolean("isRaw", cfg.isRawMode)
|
||||||
putString("rawCmd", cfg.rawCommand)
|
putString("rawCmd", cfg.rawCommand)
|
||||||
}.apply()
|
}
|
||||||
|
|
||||||
ProxyService.logBuffer.clear()
|
ProxyService.logBuffer.clear()
|
||||||
context.startForegroundService(Intent(context, ProxyService::class.java))
|
context.startForegroundService(Intent(context, ProxyService::class.java))
|
||||||
@@ -254,8 +293,11 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
when {
|
when {
|
||||||
!ProxyService.isRunning ->
|
!ProxyService.isRunning ->
|
||||||
setErrorWithAutoReset("Прокси не запустился")
|
setErrorWithAutoReset("Прокси не запустился")
|
||||||
logText.contains("ошибка") || logText.contains("error") || logText.contains("fatal") ->
|
logText.contains("panic") || logText.contains("fatal") ||
|
||||||
|
logText.contains("rate limit") || logText.contains("критическая") -> {
|
||||||
|
context.stopService(Intent(context, ProxyService::class.java))
|
||||||
setErrorWithAutoReset("Ошибка запуска — проверьте настройки")
|
setErrorWithAutoReset("Ошибка запуска — проверьте настройки")
|
||||||
|
}
|
||||||
else ->
|
else ->
|
||||||
_proxyState.value = ProxyState.Running
|
_proxyState.value = ProxyState.Running
|
||||||
}
|
}
|
||||||
@@ -263,6 +305,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setErrorWithAutoReset(message: String) {
|
private fun setErrorWithAutoReset(message: String) {
|
||||||
|
HapticUtil.perform(getApplication(), HapticUtil.Pattern.ERROR)
|
||||||
_proxyState.value = ProxyState.Error(message)
|
_proxyState.value = ProxyState.Error(message)
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
delay(3500)
|
delay(3500)
|
||||||
@@ -294,9 +337,35 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
_logs.value = emptyList()
|
_logs.value = emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Custom kernel ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
fun setCustomKernel(uri: Uri) {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
val app = getApplication<Application>()
|
||||||
|
val dest = File(app.filesDir, "custom_vkturn")
|
||||||
|
app.contentResolver.openInputStream(uri)?.use { input ->
|
||||||
|
dest.outputStream().use { output -> input.copyTo(output) }
|
||||||
|
}
|
||||||
|
dest.setExecutable(true)
|
||||||
|
withContext(Dispatchers.Main) { _customKernelExists.value = true }
|
||||||
|
ProxyService.addLog("Кастомное ядро установлено: ${dest.length() / 1024} KB")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
ProxyService.addLog("Ошибка установки ядра: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearCustomKernel() {
|
||||||
|
File(getApplication<Application>().filesDir, "custom_vkturn").delete()
|
||||||
|
_customKernelExists.value = false
|
||||||
|
ProxyService.addLog("Кастомное ядро удалено, используется встроенное")
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
ProxyService.onLogReceived = null
|
ProxyService.onLogReceived = null
|
||||||
|
ProxyService.onProxyFailed = null
|
||||||
sshManager.disconnect()
|
sshManager.disconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -1,16 +1,16 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "9.1.0"
|
agp = "9.1.0"
|
||||||
kotlin = "2.2.10"
|
kotlin = "2.3.20"
|
||||||
coreKtx = "1.17.0"
|
coreKtx = "1.18.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
junitVersion = "1.3.0"
|
junitVersion = "1.3.0"
|
||||||
espressoCore = "3.7.0"
|
espressoCore = "3.7.0"
|
||||||
appcompat = "1.7.1"
|
appcompat = "1.7.1"
|
||||||
activity = "1.12.1"
|
activity = "1.13.0"
|
||||||
composeBom = "2025.04.01"
|
composeBom = "2026.03.01"
|
||||||
navigationCompose = "2.8.9"
|
navigationCompose = "2.9.7"
|
||||||
datastorePreferences = "1.1.2"
|
datastorePreferences = "1.2.1"
|
||||||
lifecycleViewmodelCompose = "2.8.7"
|
lifecycleViewmodelCompose = "2.10.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
|
|||||||
Reference in new issue
Block a user