Skip to content

Commit

Permalink
fix fetch web content 卡住的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Apr 23, 2024
1 parent d4e10f7 commit 32be4c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,27 @@ struct EditInfoView: View {
private var urlInputView: some View {
HStack {
TextField("地址:", text: $info.url, prompt: Text("输入或粘贴 url,例如 https://www.starming.com")).rounded()
.onSubmit {
info.name = "获取标题中......"
Task {
// MARK: 获取 Web 内容
let re = await fetchTitleFromUrl(urlString:info.url)
DispatchQueue.main.async {
if re.title.isEmpty == false {
info.name = re.title
if re.imageUrl.isEmpty == false {
IOInfo.updateCoverImage(info: info, img: IOImg(url: re.imageUrl))
}
info.imageUrls = re.imageUrls
}
}
}
}
if info.url.isEmpty == false {
Button {
info.name = "获取标题中......"
Task {
// MARK: 获取 Web 内容
info.name = "获取标题中......"
let re = await fetchTitleFromUrl(urlString:info.url)
DispatchQueue.main.async {
if re.title.isEmpty == false {
Expand Down
1 change: 1 addition & 0 deletions SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct InfoListView: View {
filterCate = ""
} label: {
Image(systemName: "xmark.circle")
.symbolRenderingMode(.multicolor)
Text("检索")
}
.help("CMD + d")
Expand Down

0 comments on commit 32be4c5

Please sign in to comment.