Skip to content

Commit 5ee5937

Browse files
committed
feat(login): Compatible with legacy login history data
1 parent 8abe038 commit 5ee5937

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/data/model/LoginHistory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data class LoginHistory(
4949

5050
@get:JsonProperty("displayPort")
5151
@param:JsonProperty("displayPort")
52-
val displayPort: Int = 0
52+
val displayPort: Int? = null,
5353
) {
5454
override fun equals(other: Any?): Boolean {
5555
if (this === other) return true
@@ -77,7 +77,7 @@ data class LoginHistory(
7777
// result = 31 * result + host.hashCode()
7878
// result = 31 * result + port
7979
result = 31 * result + displayHost.hashCode()
80-
result = 31 * result + displayPort
80+
if (displayPort != null) result = 31 * result + displayPort
8181
}
8282
result = 31 * result + username.hashCode()
8383
result = 31 * result + isHttps.hashCode()
@@ -88,6 +88,8 @@ data class LoginHistory(
8888
if (isNasLogin) {
8989
return fnId.ifBlank { "FN Connect" }
9090
}
91+
val displayHost = displayHost.ifBlank { host }
92+
val displayPort = displayPort ?: port
9193
return if (displayPort != 0) {
9294
"$displayHost:$displayPort"
9395
} else {

composeApp/src/commonMain/kotlin/com/jankinwu/fntv/client/ui/screen/LoginScreen.kt

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package com.jankinwu.fntv.client.ui.screen
33
import androidx.compose.animation.AnimatedVisibility
44
import androidx.compose.animation.slideInHorizontally
55
import androidx.compose.animation.slideOutHorizontally
6+
import androidx.compose.foundation.BorderStroke
7+
import androidx.compose.foundation.ExperimentalFoundationApi
68
import androidx.compose.foundation.Image
9+
import androidx.compose.foundation.TooltipArea
710
import androidx.compose.foundation.background
811
import androidx.compose.foundation.border
912
import androidx.compose.foundation.clickable
@@ -126,7 +129,9 @@ data class FnConnectWindowRequest(
126129
val onBaseUrlDetected: ((String) -> Unit)? = null
127130
)
128131

129-
@OptIn(ExperimentalHazeMaterialsApi::class, ExperimentalComposeUiApi::class)
132+
@OptIn(ExperimentalHazeMaterialsApi::class, ExperimentalComposeUiApi::class,
133+
ExperimentalFoundationApi::class
134+
)
130135
@Suppress("RememberReturnType")
131136
@Composable
132137
fun LoginScreen(
@@ -401,16 +406,43 @@ fun LoginScreen(
401406
modifier = Modifier
402407
.padding(horizontal = 4.dp, vertical = 12.dp)
403408
)
404-
NumberInput(
405-
onValueChange = { port = it },
406-
value = port,
409+
TooltipArea(
407410
modifier = Modifier.weight(1.0f),
408-
placeholder = "端口",
409-
minValue = 0,
410-
label = "",
411-
textColor = Colors.TextSecondaryColor,
412-
defaultValue = 5666
413-
)
411+
tooltip = {
412+
Surface(
413+
modifier = Modifier.padding(4.dp),
414+
color = FluentTheme.colors.background.smoke.default.copy(
415+
alpha = 0.8f
416+
),
417+
shape = RoundedCornerShape(4.dp),
418+
border = BorderStroke(
419+
1.dp,
420+
FluentTheme.colors.text.text.primary
421+
),
422+
) {
423+
Text(
424+
text = "端口,填 0 代表使用 HTTP 或 HTTPS 协议的默认端口",
425+
modifier = Modifier
426+
.padding(8.dp),
427+
// .width(200.dp),
428+
color = FluentTheme.colors.text.text.primary,
429+
style = FluentTheme.typography.caption
430+
)
431+
}
432+
},
433+
delayMillis = 800,
434+
) {
435+
NumberInput(
436+
onValueChange = { port = it },
437+
value = port,
438+
modifier = Modifier,
439+
placeholder = "端口",
440+
minValue = 0,
441+
label = "",
442+
textColor = Colors.TextSecondaryColor,
443+
defaultValue = 5666
444+
)
445+
}
414446
}
415447

416448
OutlinedTextField(
@@ -680,13 +712,11 @@ fun LoginScreen(
680712
password =
681713
if (history.rememberPassword) history.password.orEmpty() else ""
682714
rememberPassword = history.rememberPassword
683-
val displayHost = history.displayHost
684-
val displayPort = history.displayPort
685715
// 如果有密码,则直接登录
686716
if (history.rememberPassword && !history.password.isNullOrEmpty()) {
687717
handleLogin(
688-
host = history.displayHost,
689-
port = history.displayPort,
718+
host = history.displayHost.ifBlank { history.host },
719+
port = history.displayPort ?: history.port,
690720
username = history.username,
691721
password = history.password,
692722
isHttps = history.isHttps,
@@ -746,17 +776,23 @@ fun LoginScreen(
746776
// unfocusedTextColor = Colors.TextSecondaryColor
747777
//)
748778

749-
internal fun updateLoginHistory(current: List<LoginHistory>, incoming: LoginHistory): List<LoginHistory> {
779+
internal fun updateLoginHistory(
780+
current: List<LoginHistory>,
781+
incoming: LoginHistory
782+
): List<LoginHistory> {
750783
fun normalize(value: String): String = value.trim().lowercase()
751784

752785
fun isSameIdentity(a: LoginHistory, b: LoginHistory): Boolean {
753786
if (a.isNasLogin != b.isNasLogin) return false
754787
return if (a.isNasLogin) {
755788
normalize(a.fnId) == normalize(b.fnId) && normalize(a.username) == normalize(b.username)
756-
&& a.isHttps == b.isHttps
757789
} else {
790+
if (a.displayHost.isBlank() || a.displayPort == null) {
791+
return normalize(a.host) == normalize(b.displayHost) && a.port == b.displayPort
792+
&& normalize(a.username) == normalize(b.username)
793+
}
758794
normalize(a.displayHost) == normalize(b.displayHost) && a.displayPort == b.displayPort
759-
&& normalize(a.username) == normalize(b.username) && a.isHttps == b.isHttps
795+
&& normalize(a.username) == normalize(b.username)
760796
}
761797
}
762798

0 commit comments

Comments
 (0)