fix downloading images 💀

make downloadimage not return a uiimage cos its not used anywhere
This commit is contained in:
neon443
2025-11-02 22:56:40 +00:00
parent f90a2c65b4
commit 29784a9a8f
4 changed files with 11 additions and 19 deletions

View File

@@ -71,15 +71,14 @@ struct Emoji: Codable, Identifiable, Hashable {
self.remoteImageURL = url
}
nonisolated
func downloadImage() async throws -> UIImage {
func downloadImage() async throws {
if let data = try? await Data(contentsOf: localImageURL),
let uiimage = UIImage(data: data) {
return uiimage
return
}
let (data, _) = try await URLSession.shared.data(from: remoteImageURL)
try! await data.write(to: localImageURL)
return UIImage(data: data)!
return
}
func deleteImage() {

View File

@@ -131,13 +131,4 @@ class EmojiHoarder: ObservableObject {
}
}
}
func downloadEmoji(_ toDownload: Emoji) async {
}
@MainActor
func deleteEmoji(_ toDelete: Emoji) {
}
}

View File

@@ -66,15 +66,17 @@ struct ContentView: View {
.buttonStyle(.plain)
if emoji.isLocal {
Button("", systemImage: "trash") {
hoarder.deleteEmoji(emoji)
emoji.deleteImage()
emoji.refresh()
}
.buttonStyle(.plain)
} else {
Button("", systemImage: "arrow.down.circle") {
Task.detached {
await hoarder.downloadEmoji(emoji)
await emoji.refresh()
try? await emoji.downloadImage()
await MainActor.run {
emoji.refresh()
}
}
}
.buttonStyle(.plain)
@@ -83,7 +85,7 @@ struct ContentView: View {
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
if emoji.isLocal {
Button("Remove", systemImage: "trash") {
hoarder.deleteEmoji(emoji)
emoji.deleteImage()
emoji.refresh()
}
.tint(.red)

View File

@@ -17,7 +17,7 @@ struct StickerSlackTests {
url: URL(string: "https://neon443.github.io/images/fav.ico")!,
id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")!
)
let _ = try! await goodEmoji.downloadImage()
try! await goodEmoji.downloadImage()
#expect(goodEmoji.sticker!.validate(), "should be true")
let badEmoji = Emoji(
@@ -25,7 +25,7 @@ struct StickerSlackTests {
url: URL(string: "https://files.catbox.moe/ifh710.png")!,
id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")!
)
let _ = try! await badEmoji.downloadImage()
try! await badEmoji.downloadImage()
#expect(goodEmoji.sticker!.validate(), "should be true")
badEmoji.deleteImage()
}