refactor(arch): перенести доменные state-типы из viewmodel в domain
ServerState/ProxyState/UpdateState/SshConnectionState использовались репозиториями — нижний слой зависел от верхнего. ServerHubStatus и serverSettingsAvailable остаются в viewmodel: это презентационный слой.
This commit is contained in:
1 parent
4f6691fddf
commit
101c889d42
18 files changed
+66
-66
No files matched your search
@@ -0,0 +1,52 @@
|
|||||||
|
package com.freeturn.app.domain
|
||||||
|
|
||||||
|
// SSH connection states
|
||||||
|
sealed class SshConnectionState {
|
||||||
|
object Disconnected : SshConnectionState()
|
||||||
|
object Connecting : SshConnectionState()
|
||||||
|
data class Connected(val ip: String) : SshConnectionState()
|
||||||
|
data class Error(val message: String) : SshConnectionState()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remote server states
|
||||||
|
sealed class ServerState {
|
||||||
|
object Unknown : ServerState()
|
||||||
|
object Checking : ServerState()
|
||||||
|
data class Known(
|
||||||
|
val installed: Boolean,
|
||||||
|
val running: Boolean,
|
||||||
|
/** true → сервер запущен с -mode tcp. null если не запущен/неизвестно. */
|
||||||
|
val tcpMode: Boolean? = null,
|
||||||
|
/** Профиль обфускации сервера (none|rtpopus). null если не запущен/неизвестно. */
|
||||||
|
val obfProfile: String? = null,
|
||||||
|
val version: String? = null
|
||||||
|
) : ServerState()
|
||||||
|
data class Working(val action: String) : ServerState()
|
||||||
|
data class Error(val message: String) : ServerState()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local proxy client states
|
||||||
|
sealed class ProxyState {
|
||||||
|
object Idle : ProxyState()
|
||||||
|
// Процесс поднимается, ещё не было ни одной строки, которая подтвердила бы
|
||||||
|
// работу соединения — жёлтый.
|
||||||
|
object Starting : ProxyState()
|
||||||
|
// Процесс работает, но ни один поток/сессия не подключены (active == 0) — жёлтый.
|
||||||
|
// total == 0 означает, что мы пока не знаем целевое число потоков.
|
||||||
|
data class Connecting(val active: Int, val total: Int) : ProxyState()
|
||||||
|
// Хотя бы один поток/сессия подключены — зелёный. active <= total.
|
||||||
|
data class Running(val active: Int, val total: Int) : ProxyState()
|
||||||
|
data class Error(val message: String) : ProxyState()
|
||||||
|
data class CaptchaRequired(val url: String, val sessionId: Long = 0L) : ProxyState()
|
||||||
|
}
|
||||||
|
|
||||||
|
// App update states
|
||||||
|
sealed class UpdateState {
|
||||||
|
object Idle : UpdateState()
|
||||||
|
object Checking : UpdateState()
|
||||||
|
data class Available(val version: String) : UpdateState()
|
||||||
|
object NoUpdate : UpdateState()
|
||||||
|
data class Downloading(val progress: Int) : UpdateState()
|
||||||
|
object ReadyToInstall : UpdateState()
|
||||||
|
data class Error(val message: String) : UpdateState()
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import com.freeturn.app.viewmodel.UpdateState
|
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.freeturn.app.ProxyService
|
|||||||
import com.freeturn.app.ProxyServiceState
|
import com.freeturn.app.ProxyServiceState
|
||||||
import com.freeturn.app.StartupResult
|
import com.freeturn.app.StartupResult
|
||||||
import com.freeturn.app.data.ClientConfig
|
import com.freeturn.app.data.ClientConfig
|
||||||
import com.freeturn.app.viewmodel.ProxyState
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.freeturn.app.ProxyServiceState
|
|||||||
import com.freeturn.app.data.AppPreferences
|
import com.freeturn.app.data.AppPreferences
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import com.freeturn.app.viewmodel.ServerState
|
|
||||||
|
|
||||||
class ProxyOrchestrator(
|
class ProxyOrchestrator(
|
||||||
private val prefs: AppPreferences,
|
private val prefs: AppPreferences,
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import com.freeturn.app.domain.server.CmdResult
|
|||||||
import com.freeturn.app.domain.server.ServerCommand
|
import com.freeturn.app.domain.server.ServerCommand
|
||||||
import com.freeturn.app.domain.server.ServerControl
|
import com.freeturn.app.domain.server.ServerControl
|
||||||
import com.freeturn.app.domain.server.ServerOptions
|
import com.freeturn.app.domain.server.ServerOptions
|
||||||
import com.freeturn.app.viewmodel.ServerState
|
|
||||||
import com.freeturn.app.viewmodel.SshConnectionState
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ import com.freeturn.app.ui.screens.share.QrScannerScreen
|
|||||||
import com.freeturn.app.ui.screens.share.ShareScreen
|
import com.freeturn.app.ui.screens.share.ShareScreen
|
||||||
import com.freeturn.app.ui.screens.SshSetupScreen
|
import com.freeturn.app.ui.screens.SshSetupScreen
|
||||||
import com.freeturn.app.ui.screens.setup.ServerSetupScreen
|
import com.freeturn.app.ui.screens.setup.ServerSetupScreen
|
||||||
import com.freeturn.app.viewmodel.ProxyState
|
import com.freeturn.app.domain.ProxyState
|
||||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||||
import com.freeturn.app.viewmodel.ProxyViewModel
|
import com.freeturn.app.viewmodel.ProxyViewModel
|
||||||
import com.freeturn.app.viewmodel.ServerViewModel
|
import com.freeturn.app.viewmodel.ServerViewModel
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ import com.freeturn.app.ui.components.SettingsRowIcon
|
|||||||
import com.freeturn.app.ui.components.SettingsSwitchRow
|
import com.freeturn.app.ui.components.SettingsSwitchRow
|
||||||
import com.freeturn.app.ui.util.hapticClickable
|
import com.freeturn.app.ui.util.hapticClickable
|
||||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||||
import com.freeturn.app.viewmodel.UpdateState
|
import com.freeturn.app.domain.UpdateState
|
||||||
|
|
||||||
// Экраны «Приложение» и «О проекте» — бывшее содержимое инфо-шита главного экрана,
|
// Экраны «Приложение» и «О проекте» — бывшее содержимое инфо-шита главного экрана,
|
||||||
// разложенное по разделам настроек на общих settings-блоках.
|
// разложенное по разделам настроек на общих settings-блоках.
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ fun ClientSetupScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val serverKnown = serverState as? com.freeturn.app.viewmodel.ServerState.Known
|
val serverKnown = serverState as? com.freeturn.app.domain.ServerState.Known
|
||||||
// TCP-форвард: в sync-режиме у активного сервера берём реальное состояние из probe
|
// TCP-форвард: в sync-режиме у активного сервера берём реальное состояние из probe
|
||||||
// (если запущен), иначе — сохранённое значение клиента. Нужно лишь для показа Bond.
|
// (если запущен), иначе — сохранённое значение клиента. Нужно лишь для показа Bond.
|
||||||
val syncOn = saved.syncServerSwitches
|
val syncOn = saved.syncServerSwitches
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ import com.freeturn.app.ui.components.SettingsFieldSlot
|
|||||||
import com.freeturn.app.ui.components.SettingsRowDivider
|
import com.freeturn.app.ui.components.SettingsRowDivider
|
||||||
import com.freeturn.app.ui.theme.extendedColorScheme
|
import com.freeturn.app.ui.theme.extendedColorScheme
|
||||||
import com.freeturn.app.ui.util.redact
|
import com.freeturn.app.ui.util.redact
|
||||||
import com.freeturn.app.viewmodel.ProxyState
|
import com.freeturn.app.domain.ProxyState
|
||||||
import com.freeturn.app.viewmodel.ProxyViewModel
|
import com.freeturn.app.viewmodel.ProxyViewModel
|
||||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ import com.freeturn.app.ui.components.SettingsFieldSlot
|
|||||||
import com.freeturn.app.ui.components.SettingsRowDivider
|
import com.freeturn.app.ui.components.SettingsRowDivider
|
||||||
import com.freeturn.app.ui.util.copyToClipboard
|
import com.freeturn.app.ui.util.copyToClipboard
|
||||||
import com.freeturn.app.ui.util.redact
|
import com.freeturn.app.ui.util.redact
|
||||||
import com.freeturn.app.viewmodel.ServerState
|
import com.freeturn.app.domain.ServerState
|
||||||
import com.freeturn.app.viewmodel.SshConnectionState
|
import com.freeturn.app.domain.SshConnectionState
|
||||||
import com.freeturn.app.viewmodel.ServerViewModel
|
import com.freeturn.app.viewmodel.ServerViewModel
|
||||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||||
import com.freeturn.app.viewmodel.serverSettingsAvailable
|
import com.freeturn.app.viewmodel.serverSettingsAvailable
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ import androidx.compose.ui.semantics.stateDescription
|
|||||||
import com.freeturn.app.ui.screens.setup.BusyProgressIndicator
|
import com.freeturn.app.ui.screens.setup.BusyProgressIndicator
|
||||||
import com.freeturn.app.ui.theme.LocalReducedMotion
|
import com.freeturn.app.ui.theme.LocalReducedMotion
|
||||||
import com.freeturn.app.viewmodel.ServerViewModel
|
import com.freeturn.app.viewmodel.ServerViewModel
|
||||||
import com.freeturn.app.viewmodel.SshConnectionState
|
import com.freeturn.app.domain.SshConnectionState
|
||||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ import androidx.graphics.shapes.toPath
|
|||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
import com.freeturn.app.ui.theme.LocalReducedMotion
|
import com.freeturn.app.ui.theme.LocalReducedMotion
|
||||||
import com.freeturn.app.ui.theme.extendedColorScheme
|
import com.freeturn.app.ui.theme.extendedColorScheme
|
||||||
import com.freeturn.app.viewmodel.ProxyState
|
import com.freeturn.app.domain.ProxyState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Герой главного экрана: кнопка-тоггл с морфом MaterialShapes по состоянию
|
* Герой главного экрана: кнопка-тоггл с морфом MaterialShapes по состоянию
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import com.freeturn.app.R
|
|||||||
import com.freeturn.app.data.SplitTunnelMode
|
import com.freeturn.app.data.SplitTunnelMode
|
||||||
import com.freeturn.app.ui.HapticUtil
|
import com.freeturn.app.ui.HapticUtil
|
||||||
import com.freeturn.app.ui.screens.SplitTunnelModal
|
import com.freeturn.app.ui.screens.SplitTunnelModal
|
||||||
import com.freeturn.app.viewmodel.ProxyState
|
import com.freeturn.app.domain.ProxyState
|
||||||
import com.freeturn.app.viewmodel.ProxyViewModel
|
import com.freeturn.app.viewmodel.ProxyViewModel
|
||||||
import com.freeturn.app.viewmodel.SettingsViewModel
|
import com.freeturn.app.viewmodel.SettingsViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.freeturn.app.R
|
import com.freeturn.app.R
|
||||||
import com.freeturn.app.ui.HapticUtil
|
import com.freeturn.app.ui.HapticUtil
|
||||||
import com.freeturn.app.viewmodel.UpdateState
|
import com.freeturn.app.domain.UpdateState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Диалоги цикла обновления приложения: доступно → качается → готово к установке.
|
* Диалоги цикла обновления приложения: доступно → качается → готово к установке.
|
||||||
|
|||||||
@@ -1,30 +1,5 @@
|
|||||||
package com.freeturn.app.viewmodel
|
package com.freeturn.app.viewmodel
|
||||||
|
|
||||||
// SSH connection states
|
|
||||||
sealed class SshConnectionState {
|
|
||||||
object Disconnected : SshConnectionState()
|
|
||||||
object Connecting : SshConnectionState()
|
|
||||||
data class Connected(val ip: String) : SshConnectionState()
|
|
||||||
data class Error(val message: String) : SshConnectionState()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remote server states
|
|
||||||
sealed class ServerState {
|
|
||||||
object Unknown : ServerState()
|
|
||||||
object Checking : ServerState()
|
|
||||||
data class Known(
|
|
||||||
val installed: Boolean,
|
|
||||||
val running: Boolean,
|
|
||||||
/** true → сервер запущен с -mode tcp. null если не запущен/неизвестно. */
|
|
||||||
val tcpMode: Boolean? = null,
|
|
||||||
/** Профиль обфускации сервера (none|rtpopus). null если не запущен/неизвестно. */
|
|
||||||
val obfProfile: String? = null,
|
|
||||||
val version: String? = null
|
|
||||||
) : ServerState()
|
|
||||||
data class Working(val action: String) : ServerState()
|
|
||||||
data class Error(val message: String) : ServerState()
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed interface ServerHubStatus {
|
sealed interface ServerHubStatus {
|
||||||
/**
|
/**
|
||||||
* Профиль не активен: живой SSH/ядро принадлежат активному. Предлагаем активировать.
|
* Профиль не активен: живой SSH/ядро принадлежат активному. Предлагаем активировать.
|
||||||
@@ -59,29 +34,3 @@ sealed interface ServerHubStatus {
|
|||||||
* (ServerManagementScreen), иначе условия разъезжаются.
|
* (ServerManagementScreen), иначе условия разъезжаются.
|
||||||
*/
|
*/
|
||||||
fun serverSettingsAvailable(connected: Boolean, syncOn: Boolean): Boolean = connected || !syncOn
|
fun serverSettingsAvailable(connected: Boolean, syncOn: Boolean): Boolean = connected || !syncOn
|
||||||
|
|
||||||
// Local proxy client states
|
|
||||||
sealed class ProxyState {
|
|
||||||
object Idle : ProxyState()
|
|
||||||
// Процесс поднимается, ещё не было ни одной строки, которая подтвердила бы
|
|
||||||
// работу соединения — жёлтый.
|
|
||||||
object Starting : ProxyState()
|
|
||||||
// Процесс работает, но ни один поток/сессия не подключены (active == 0) — жёлтый.
|
|
||||||
// total == 0 означает, что мы пока не знаем целевое число потоков.
|
|
||||||
data class Connecting(val active: Int, val total: Int) : ProxyState()
|
|
||||||
// Хотя бы один поток/сессия подключены — зелёный. active <= total.
|
|
||||||
data class Running(val active: Int, val total: Int) : ProxyState()
|
|
||||||
data class Error(val message: String) : ProxyState()
|
|
||||||
data class CaptchaRequired(val url: String, val sessionId: Long = 0L) : ProxyState()
|
|
||||||
}
|
|
||||||
|
|
||||||
// App update states
|
|
||||||
sealed class UpdateState {
|
|
||||||
object Idle : UpdateState()
|
|
||||||
object Checking : UpdateState()
|
|
||||||
data class Available(val version: String) : UpdateState()
|
|
||||||
object NoUpdate : UpdateState()
|
|
||||||
data class Downloading(val progress: Int) : UpdateState()
|
|
||||||
object ReadyToInstall : UpdateState()
|
|
||||||
data class Error(val message: String) : UpdateState()
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import com.freeturn.app.ProxyServiceState
|
import com.freeturn.app.ProxyServiceState
|
||||||
import com.freeturn.app.data.AppPreferences
|
import com.freeturn.app.data.AppPreferences
|
||||||
import com.freeturn.app.domain.LocalProxyManager
|
import com.freeturn.app.domain.LocalProxyManager
|
||||||
|
import com.freeturn.app.domain.ProxyState
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import com.freeturn.app.data.ObfProfile
|
|||||||
import com.freeturn.app.data.ServerOpts
|
import com.freeturn.app.data.ServerOpts
|
||||||
import com.freeturn.app.data.SshConfig
|
import com.freeturn.app.data.SshConfig
|
||||||
import com.freeturn.app.domain.ProxyOrchestrator
|
import com.freeturn.app.domain.ProxyOrchestrator
|
||||||
|
import com.freeturn.app.domain.ServerState
|
||||||
|
import com.freeturn.app.domain.SshConnectionState
|
||||||
import com.freeturn.app.domain.SshRepository
|
import com.freeturn.app.domain.SshRepository
|
||||||
import com.freeturn.app.ui.HapticUtil
|
import com.freeturn.app.ui.HapticUtil
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.freeturn.app.domain.AppUpdater
|
|||||||
import com.freeturn.app.domain.LocalProxyManager
|
import com.freeturn.app.domain.LocalProxyManager
|
||||||
import com.freeturn.app.domain.ProxyOrchestrator
|
import com.freeturn.app.domain.ProxyOrchestrator
|
||||||
import com.freeturn.app.domain.SshRepository
|
import com.freeturn.app.domain.SshRepository
|
||||||
|
import com.freeturn.app.domain.UpdateState
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.NonCancellable
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|||||||
Reference in new issue
Block a user