Skip to content

Commit

Permalink
Add DEV UI support for SOCKS proxy port
Browse files Browse the repository at this point in the history
  • Loading branch information
pyamsoft committed Dec 31, 2024
1 parent 837932a commit e6ee0f6
Show file tree
Hide file tree
Showing 30 changed files with 493 additions and 151 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/pyamsoft/tetherfi/PreferencesImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import com.pyamsoft.tetherfi.server.TweakPreferences
import com.pyamsoft.tetherfi.server.WifiPreferences
import com.pyamsoft.tetherfi.server.broadcast.BroadcastType
import com.pyamsoft.tetherfi.server.network.PreferredNetwork
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.random.Random
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -48,9 +51,6 @@ import kotlinx.coroutines.flow.combineTransform
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.random.Random

@Singleton
internal class PreferencesImpl
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/pyamsoft/tetherfi/info/InfoEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.pyamsoft.pydroid.ui.inject.ComposableInjector
import com.pyamsoft.pydroid.ui.inject.rememberComposableInjector
import com.pyamsoft.pydroid.ui.util.rememberNotNull
import com.pyamsoft.tetherfi.ObjectGraph
import com.pyamsoft.tetherfi.core.FeatureFlags
import com.pyamsoft.tetherfi.ui.ServerViewState
import javax.inject.Inject

Expand All @@ -43,6 +44,7 @@ internal class InfoInjector : ComposableInjector() {
fun InfoEntry(
modifier: Modifier = Modifier,
appName: String,
featureFlags: FeatureFlags,
serverViewState: ServerViewState,
onShowQRCode: () -> Unit,
onShowSlowSpeedHelp: () -> Unit,
Expand All @@ -54,6 +56,7 @@ fun InfoEntry(
modifier = modifier,
state = viewModel,
appName = appName,
featureFlags = featureFlags,
serverViewState = serverViewState,
onShowQRCode = onShowQRCode,
onShowSlowSpeedHelp = onShowSlowSpeedHelp,
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/pyamsoft/tetherfi/main/MainContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import com.pyamsoft.tetherfi.connections.ConnectionEntry
import com.pyamsoft.tetherfi.core.FeatureFlags
import com.pyamsoft.tetherfi.info.InfoEntry
import com.pyamsoft.tetherfi.server.status.RunningStatus
import com.pyamsoft.tetherfi.status.StatusEntry
Expand All @@ -32,6 +33,7 @@ import com.pyamsoft.tetherfi.ui.ServerViewState
fun MainContent(
modifier: Modifier = Modifier,
appName: String,
featureFlags: FeatureFlags,
pagerState: PagerState,
state: ServerViewState,
allTabs: List<MainView>,
Expand Down Expand Up @@ -70,6 +72,7 @@ fun MainContent(
InfoEntry(
modifier = Modifier.fillMaxSize(),
appName = appName,
featureFlags = featureFlags,
serverViewState = state,
onShowQRCode = onShowQRCode,
onShowSlowSpeedHelp = onShowSlowSpeedHelp,
Expand All @@ -78,6 +81,7 @@ fun MainContent(
MainView.STATUS -> {
StatusEntry(
modifier = Modifier.fillMaxSize(),
featureFlags = featureFlags,
appName = appName,
serverViewState = state,
onShowQRCode = onShowQRCode,
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/pyamsoft/tetherfi/main/MainEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.pyamsoft.pydroid.ui.util.fillUpToPortraitSize
import com.pyamsoft.pydroid.ui.util.rememberNotNull
import com.pyamsoft.tetherfi.ObjectGraph
import com.pyamsoft.tetherfi.core.AppDevEnvironment
import com.pyamsoft.tetherfi.core.FeatureFlags
import com.pyamsoft.tetherfi.core.Timber
import com.pyamsoft.tetherfi.qr.QRCodeEntry
import com.pyamsoft.tetherfi.server.broadcast.BroadcastNetworkStatus
Expand All @@ -68,10 +69,9 @@ internal class MainInjector @Inject internal constructor() : ComposableInjector(
@JvmField @Inject internal var viewModel: MainViewModeler? = null

@JvmField @Inject internal var appEnvironment: AppDevEnvironment? = null

@JvmField @Inject internal var permissionRequestBus: EventBus<PermissionRequests>? = null

@JvmField @Inject internal var permissionResponseBus: EventConsumer<PermissionResponse>? = null
@JvmField @Inject internal var featureFlags: FeatureFlags? = null

override fun onInject(activity: ComponentActivity) {
ObjectGraph.ActivityScope.retrieve(activity).inject(this)
Expand All @@ -82,6 +82,7 @@ internal class MainInjector @Inject internal constructor() : ComposableInjector(
appEnvironment = null
permissionRequestBus = null
permissionResponseBus = null
featureFlags = null
}
}

Expand Down Expand Up @@ -206,6 +207,7 @@ fun MainEntry(
val appEnvironment = rememberNotNull(component.appEnvironment)
val permissionRequestBus = rememberNotNull(component.permissionRequestBus)
val permissionResponseBus = rememberNotNull(component.permissionResponseBus)
val featureFlags = rememberNotNull(component.featureFlags)

// Use the LifecycleOwner.CoroutineScope (Activity usually)
// so that the scope does not die because of navigation events
Expand Down Expand Up @@ -241,6 +243,7 @@ fun MainEntry(
modifier = modifier,
appName = appName,
state = viewModel,
featureFlags = featureFlags,
pagerState = pagerState,
allTabs = allTabs,
onTabChanged = { handleTabSelected(it) },
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/pyamsoft/tetherfi/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.pyamsoft.pydroid.ui.util.rememberAsStateList
import com.pyamsoft.tetherfi.core.FeatureFlags
import com.pyamsoft.tetherfi.server.broadcast.BroadcastNetworkStatus
import com.pyamsoft.tetherfi.server.broadcast.BroadcastType
import com.pyamsoft.tetherfi.server.network.PreferredNetwork
import com.pyamsoft.tetherfi.server.status.RunningStatus
import com.pyamsoft.tetherfi.service.prereq.HotspotStartBlocker
import com.pyamsoft.tetherfi.ui.test.makeTestFeatureFlags
import kotlinx.coroutines.flow.MutableStateFlow
import org.jetbrains.annotations.TestOnly

Expand All @@ -41,6 +43,7 @@ fun MainScreen(
modifier: Modifier = Modifier,
appName: String,
state: MainViewState,
featureFlags: FeatureFlags,
pagerState: PagerState,
allTabs: List<MainView>,

Expand Down Expand Up @@ -88,6 +91,7 @@ fun MainScreen(
.heightIn(
min = remember(pv) { pv.calculateBottomPadding() },
),
featureFlags = featureFlags,
appName = appName,
pagerState = pagerState,
state = state,
Expand Down Expand Up @@ -122,7 +126,9 @@ private fun PreviewMainScreen(
override val isShowingSlowSpeedHelp = MutableStateFlow(isShowingSlowSpeedHelp)
override val group = MutableStateFlow(BroadcastNetworkStatus.GroupInfo.Empty)
override val connection = MutableStateFlow(BroadcastNetworkStatus.ConnectionInfo.Empty)
override val port = MutableStateFlow(0)

override val httpPort = MutableStateFlow(0)
override val socksPort = MutableStateFlow(0)

// TODO support RNDIS
override val broadcastType = MutableStateFlow(BroadcastType.WIFI_DIRECT)
Expand All @@ -143,6 +149,7 @@ private fun PreviewMainScreen(
val allTabs = MainView.entries.rememberAsStateList()

MainScreen(
featureFlags = makeTestFeatureFlags(),
appName = "TEST",
state = state,
pagerState = rememberPagerState { allTabs.size },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.pyamsoft.pydroid.ui.inject.ComposableInjector
import com.pyamsoft.pydroid.ui.inject.rememberComposableInjector
import com.pyamsoft.pydroid.ui.util.rememberNotNull
import com.pyamsoft.tetherfi.ObjectGraph
import com.pyamsoft.tetherfi.core.FeatureFlags
import com.pyamsoft.tetherfi.server.status.RunningStatus
import com.pyamsoft.tetherfi.ui.ServerViewState
import javax.inject.Inject
Expand Down Expand Up @@ -140,6 +141,7 @@ fun StatusEntry(
modifier: Modifier = Modifier,
appName: String,
serverViewState: ServerViewState,
featureFlags: FeatureFlags,

// Actions
onShowQRCode: () -> Unit,
Expand Down Expand Up @@ -186,6 +188,7 @@ fun StatusEntry(
state = viewModel,
serverViewState = serverViewState,
appName = appName,
featureFlags = featureFlags,
onShowQRCode = onShowQRCode,
onRefreshConnection = onRefreshConnection,
onJumpToHowTo = onJumpToHowTo,
Expand All @@ -196,7 +199,8 @@ fun StatusEntry(
},
onSsidChanged = { viewModel.handleSsidChanged(it.trim()) },
onPasswordChanged = { viewModel.handlePasswordChanged(it) },
onPortChanged = { viewModel.handlePortChanged(it) },
onHttpPortChanged = { viewModel.handlePortChanged(it, ServerPortTypes.HTTP) },
onSocksPortChanged = { viewModel.handlePortChanged(it, ServerPortTypes.SOCKS) },
onViewSlowSpeedHelp = onShowSlowSpeedHelp,
onOpenBatterySettings = {
onLaunchIntent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
Expand Down
5 changes: 5 additions & 0 deletions info/src/main/java/com/pyamsoft/tetherfi/info/InfoScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.pyamsoft.pydroid.theme.keylines
import com.pyamsoft.tetherfi.core.FeatureFlags
import com.pyamsoft.tetherfi.ui.LANDSCAPE_MAX_WIDTH
import com.pyamsoft.tetherfi.ui.ServerViewState
import com.pyamsoft.tetherfi.ui.renderLinks
import com.pyamsoft.tetherfi.ui.renderPYDroidExtras
import com.pyamsoft.tetherfi.ui.test.TestServerState
import com.pyamsoft.tetherfi.ui.test.makeTestFeatureFlags
import com.pyamsoft.tetherfi.ui.test.makeTestServerState

private enum class InfoContentTypes {
Expand All @@ -45,6 +47,7 @@ private enum class InfoContentTypes {
fun InfoScreen(
modifier: Modifier = Modifier,
appName: String,
featureFlags: FeatureFlags,
state: InfoViewState,
serverViewState: ServerViewState,
onTogglePasswordVisibility: () -> Unit,
Expand Down Expand Up @@ -79,6 +82,7 @@ fun InfoScreen(
itemModifier = Modifier.widthIn(max = LANDSCAPE_MAX_WIDTH),
appName = appName,
state = state,
featureFlags = featureFlags,
serverViewState = serverViewState,
onTogglePasswordVisibility = onTogglePasswordVisibility,
onShowQRCode = onShowQRCode,
Expand All @@ -100,6 +104,7 @@ fun InfoScreen(
private fun PreviewInfoScreen() {
InfoScreen(
appName = "TEST",
featureFlags = makeTestFeatureFlags(),
state = MutableInfoViewState(),
serverViewState = makeTestServerState(TestServerState.EMPTY),
onTogglePasswordVisibility = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.pyamsoft.pydroid.theme.keylines
import com.pyamsoft.tetherfi.core.FeatureFlags
import com.pyamsoft.tetherfi.info.sections.renderAppSetup
import com.pyamsoft.tetherfi.info.sections.renderConnectionComplete
import com.pyamsoft.tetherfi.info.sections.renderDeviceIdentifiers
import com.pyamsoft.tetherfi.info.sections.renderDeviceSetup
import com.pyamsoft.tetherfi.ui.ServerViewState
import com.pyamsoft.tetherfi.ui.test.TestServerState
import com.pyamsoft.tetherfi.ui.test.makeTestFeatureFlags
import com.pyamsoft.tetherfi.ui.test.makeTestServerState
import org.jetbrains.annotations.TestOnly

Expand All @@ -41,6 +43,7 @@ private enum class ConnectionInstructionContentTypes {
internal fun LazyListScope.renderConnectionInstructions(
itemModifier: Modifier = Modifier,
appName: String,
featureFlags: FeatureFlags,
state: InfoViewState,
serverViewState: ServerViewState,
onShowQRCode: () -> Unit,
Expand Down Expand Up @@ -85,6 +88,7 @@ internal fun LazyListScope.renderConnectionInstructions(
itemModifier = itemModifier,
appName = appName,
state = state,
featureFlags = featureFlags,
serverViewState = serverViewState,
onTogglePasswordVisibility = onTogglePasswordVisibility,
onShowQRCode = onShowQRCode,
Expand Down Expand Up @@ -119,6 +123,7 @@ private fun PreviewConnectionInstructions(state: InfoViewState, server: TestServ
LazyColumn {
renderConnectionInstructions(
appName = "TEST",
featureFlags = makeTestFeatureFlags(),
serverViewState = makeTestServerState(server),
state = state,
onTogglePasswordVisibility = {},
Expand Down
Loading

0 comments on commit e6ee0f6

Please sign in to comment.