mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-01 15:43:45 +00:00
feat(settings): redesign connectivity test link row
This commit is contained in:
@@ -239,24 +239,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"测试 URL…": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Test URL…"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "测试 URL…"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"测试 URL": {
|
||||
"测试链接": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
@@ -268,7 +251,7 @@
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "测试 URL"
|
||||
"value": "测试链接"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,24 +4,46 @@ struct ConnectivityURLSettings: View {
|
||||
@ObservedObject var workflow: SettingsWorkflow
|
||||
@State private var editing = false
|
||||
@State private var value = ""
|
||||
@State private var displayedURL = ""
|
||||
@State private var failure = false
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
Button(ConnectivityCopy.text("测试 URL…")) {
|
||||
do {
|
||||
value = try workflow.beginConnectivityURLEditing()
|
||||
failure = false
|
||||
editing = true
|
||||
} catch { failure = true }
|
||||
HStack(spacing: 12) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(ConnectivityCopy.text("测试链接")).font(.headline)
|
||||
Text(displayedURL)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
.textSelection(.enabled)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Button(action: beginEditing) {
|
||||
HStack(spacing: 6) {
|
||||
Text(String(localized: "编辑"))
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.caption.weight(.semibold))
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
|
||||
if failure {
|
||||
Text(ConnectivityCopy.text("无法读取或保存测试 URL"))
|
||||
.font(.caption)
|
||||
.foregroundStyle(.red)
|
||||
}
|
||||
if failure { Text(ConnectivityCopy.text("无法读取或保存测试 URL")).foregroundStyle(.red) }
|
||||
} header: {
|
||||
Text(ConnectivityCopy.text("连通性测试"))
|
||||
Text(ConnectivityCopy.text("延迟测试"))
|
||||
}
|
||||
.onAppear(perform: refreshDisplayedURL)
|
||||
.sheet(isPresented: $editing) {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
Text(ConnectivityCopy.text("测试 URL")).font(.headline)
|
||||
Text(ConnectivityCopy.text("测试链接")).font(.headline)
|
||||
TextField("HTTP", text: $value).textFieldStyle(.roundedBorder)
|
||||
Text(ConnectivityCopy.text("仅支持 HTTP。预热后采样 3 次,至少成功 2 次;显示成功样本的中位数。"))
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
@@ -35,6 +57,7 @@ struct ConnectivityURLSettings: View {
|
||||
Button(ConnectivityCopy.text("保存")) {
|
||||
Task {
|
||||
if await workflow.saveConnectivityURL(value) {
|
||||
displayedURL = ServerConnectivity.validURL(value)?.absoluteString ?? value
|
||||
editing = false
|
||||
failure = false
|
||||
} else {
|
||||
@@ -50,4 +73,26 @@ struct ConnectivityURLSettings: View {
|
||||
.interactiveDismissDisabled(workflow.isCommitting)
|
||||
}
|
||||
}
|
||||
|
||||
private func refreshDisplayedURL() {
|
||||
do {
|
||||
displayedURL = try workflow.beginConnectivityURLEditing()
|
||||
failure = false
|
||||
} catch {
|
||||
displayedURL = ""
|
||||
failure = true
|
||||
}
|
||||
}
|
||||
|
||||
private func beginEditing() {
|
||||
do {
|
||||
value = try workflow.beginConnectivityURLEditing()
|
||||
displayedURL = value
|
||||
failure = false
|
||||
editing = true
|
||||
} catch {
|
||||
displayedURL = ""
|
||||
failure = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user