@@ -14,16 +14,19 @@ import androidx.compose.foundation.layout.wrapContentSize
14
14
import androidx.compose.material.icons.Icons
15
15
import androidx.compose.material.icons.automirrored.filled.ArrowBack
16
16
import androidx.compose.material.icons.filled.MoreVert
17
+ import androidx.compose.material.icons.filled.WarningAmber
17
18
import androidx.compose.material3.CircularProgressIndicator
18
19
import androidx.compose.material3.DropdownMenu
19
20
import androidx.compose.material3.DropdownMenuItem
20
21
import androidx.compose.material3.Icon
21
22
import androidx.compose.material3.IconButton
22
23
import androidx.compose.material3.LocalTextStyle
24
+ import androidx.compose.material3.MaterialTheme
23
25
import androidx.compose.material3.Scaffold
24
26
import androidx.compose.material3.Text
25
27
import androidx.compose.material3.TopAppBar
26
28
import androidx.compose.runtime.Composable
29
+ import androidx.compose.runtime.LaunchedEffect
27
30
import androidx.compose.runtime.getValue
28
31
import androidx.compose.runtime.mutableStateOf
29
32
import androidx.compose.runtime.remember
@@ -46,6 +49,8 @@ import kotlinx.coroutines.runBlocking
46
49
import kotlinx.serialization.Serializable
47
50
import li.songe.gkd.META
48
51
import li.songe.gkd.data.Value
52
+ import li.songe.gkd.ui.component.updateDialogOptions
53
+ import li.songe.gkd.util.LocalMainViewModel
49
54
import li.songe.gkd.util.LocalNavController
50
55
import li.songe.gkd.util.ProfileTransitions
51
56
import li.songe.gkd.util.client
@@ -59,10 +64,14 @@ import li.songe.gkd.util.throttle
59
64
fun WebViewPage (
60
65
initUrl : String ,
61
66
) {
67
+ val mainVm = LocalMainViewModel .current
62
68
val navController = LocalNavController .current
63
69
val webViewState = rememberWebViewState(url = initUrl)
64
70
val webViewClient = remember { GkdWebViewClient () }
65
71
val webView = remember { Value <WebView ?>(null ) }
72
+ LaunchedEffect (null ) {
73
+ WebView .getCurrentWebViewPackage()?.versionName?.run { splitToSequence(' .' ).first() }
74
+ }
66
75
Scaffold (modifier = Modifier , topBar = {
67
76
Box (
68
77
modifier = Modifier .fillMaxWidth(),
@@ -99,6 +108,20 @@ fun WebViewPage(
99
108
}
100
109
},
101
110
actions = {
111
+ if (chromeVersion > 0 && chromeVersion < MINI_CHROME_VERSION ) {
112
+ IconButton (onClick = throttle {
113
+ mainVm.dialogFlow.updateDialogOptions(
114
+ title = " 兼容性提示" ,
115
+ text = " 检测到您的系统内置浏览器版本($chromeVersion )过低, 可能无法正常浏览网页文档\n\n 建议自行升级版本后重启 GKD 再查看文档, 或点击右上角后在外部浏览器打开查阅\n\n 若能正常浏览文档请忽略此项提示"
116
+ )
117
+ }) {
118
+ Icon (
119
+ imageVector = Icons .Default .WarningAmber ,
120
+ contentDescription = null ,
121
+ tint = MaterialTheme .colorScheme.error,
122
+ )
123
+ }
124
+ }
102
125
var expanded by remember { mutableStateOf(false ) }
103
126
IconButton (onClick = { expanded = true }) {
104
127
Icon (imageVector = Icons .Default .MoreVert , contentDescription = null )
@@ -128,7 +151,7 @@ fun WebViewPage(
128
151
},
129
152
onClick = {
130
153
expanded = false
131
- webView.value?.url?. let { copyText(it) }
154
+ copyText( webView.value?.url ? : initUrl)
132
155
}
133
156
)
134
157
DropdownMenuItem (
@@ -137,7 +160,7 @@ fun WebViewPage(
137
160
},
138
161
onClick = {
139
162
expanded = false
140
- webView.value?.url?. let { openUri(it) }
163
+ openUri( webView.value?.url ? : initUrl)
141
164
}
142
165
)
143
166
}
@@ -164,6 +187,14 @@ fun WebViewPage(
164
187
}
165
188
}
166
189
190
+ // 兼容性检测为最近 3 年, 2022-03-29
191
+ private const val MINI_CHROME_VERSION = 100
192
+ private val chromeVersion by lazy {
193
+ WebView .getCurrentWebViewPackage()?.versionName?.run {
194
+ splitToSequence(' .' ).first().toIntOrNull()
195
+ } ? : 0
196
+ }
197
+
167
198
private const val DOC_CONFIG_URL =
168
199
" https://registry.npmmirror.com/@gkd-kit/docs/latest/files/_config.json"
169
200
0 commit comments