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 self.remoteImageURL = url
} }
nonisolated func downloadImage() async throws {
func downloadImage() async throws -> UIImage {
if let data = try? await Data(contentsOf: localImageURL), if let data = try? await Data(contentsOf: localImageURL),
let uiimage = UIImage(data: data) { let uiimage = UIImage(data: data) {
return uiimage return
} }
let (data, _) = try await URLSession.shared.data(from: remoteImageURL) let (data, _) = try await URLSession.shared.data(from: remoteImageURL)
try! await data.write(to: localImageURL) try! await data.write(to: localImageURL)
return UIImage(data: data)! return
} }
func deleteImage() { 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) .buttonStyle(.plain)
if emoji.isLocal { if emoji.isLocal {
Button("", systemImage: "trash") { Button("", systemImage: "trash") {
hoarder.deleteEmoji(emoji) emoji.deleteImage()
emoji.refresh() emoji.refresh()
} }
.buttonStyle(.plain) .buttonStyle(.plain)
} else { } else {
Button("", systemImage: "arrow.down.circle") { Button("", systemImage: "arrow.down.circle") {
Task.detached { Task.detached {
await hoarder.downloadEmoji(emoji) try? await emoji.downloadImage()
await emoji.refresh() await MainActor.run {
emoji.refresh()
}
} }
} }
.buttonStyle(.plain) .buttonStyle(.plain)
@@ -83,7 +85,7 @@ struct ContentView: View {
.swipeActions(edge: .trailing, allowsFullSwipe: true) { .swipeActions(edge: .trailing, allowsFullSwipe: true) {
if emoji.isLocal { if emoji.isLocal {
Button("Remove", systemImage: "trash") { Button("Remove", systemImage: "trash") {
hoarder.deleteEmoji(emoji) emoji.deleteImage()
emoji.refresh() emoji.refresh()
} }
.tint(.red) .tint(.red)

View File

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