mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
fix memory leak when emojipack some emojis that dont exist
added a refersh button
This commit is contained in:
3 files changed
+34
-18
No files matched your search
@@ -188,10 +188,10 @@ class EmojiHoarder: BaseHoarder {
|
||||
nonisolated
|
||||
private func loadRemoteDB() async {
|
||||
async let fetched = self.fetchRemoteDB()
|
||||
if let fetched = await fetched {
|
||||
if let fetched = await fetched,
|
||||
await fetched != self.emojis {
|
||||
await MainActor.run {
|
||||
withAnimation(.snappy) { self.emojis = fetched }
|
||||
print(EmojiHoarder.container)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,21 +209,6 @@ class EmojiHoarder: BaseHoarder {
|
||||
}
|
||||
}
|
||||
|
||||
private func refreshDB() async {
|
||||
guard let fetched = await self.fetchRemoteDB() else {
|
||||
let local = loadLocalDB()
|
||||
await MainActor.run {
|
||||
emojis = local
|
||||
}
|
||||
await buildTrie()
|
||||
return
|
||||
}
|
||||
await MainActor.run {
|
||||
withAnimation(.snappy) { self.emojis = fetched }
|
||||
}
|
||||
await buildTrie()
|
||||
}
|
||||
|
||||
nonisolated func batchDownload(emojis emojisToDownload: [any StickerProtocol]) async {
|
||||
let emojiNames = emojisToDownload.map { $0.name }
|
||||
for emoji in emojisToDownload {
|
||||
|
||||
@@ -21,6 +21,8 @@ struct EmojiPackDetailView: View {
|
||||
|
||||
@State var showShare: Bool = false
|
||||
|
||||
@State var showNotFoundAlert: Bool = false
|
||||
|
||||
var allDownloaded: Bool {
|
||||
let date = Date.now
|
||||
let result = Set(pack.items).isSubset(of: hoarder.downloadedStickers)
|
||||
@@ -102,14 +104,39 @@ struct EmojiPackDetailView: View {
|
||||
LazyVGrid(columns: layout, spacing: spacing) {
|
||||
ForEach(pack.items, id: \.self) { name in
|
||||
TimelineView(.animation) { tl in
|
||||
let emoji = hoarder.trie.dict[name] ?? .test
|
||||
Group {
|
||||
VStack {
|
||||
if let emoji = hoarder.trie.dict[name] {
|
||||
StickerPreview(sticker: emoji)
|
||||
Text(emoji.UIName)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
} else {
|
||||
Image(systemName: "questionmark.circle.dashed")
|
||||
.resizable().scaledToFit()
|
||||
.foregroundStyle(.gray.opacity(0.5))
|
||||
.overlay(alignment: .topTrailing) {
|
||||
Button {
|
||||
showNotFoundAlert.toggle()
|
||||
} label: {
|
||||
Image(systemName: "info")
|
||||
.font(.title3.bold())
|
||||
}
|
||||
}
|
||||
Text(name)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(.caption)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.alert("This emoji was not found", isPresented: $showNotFoundAlert) {
|
||||
Button("OK") {
|
||||
showNotFoundAlert.toggle()
|
||||
}
|
||||
} message: {
|
||||
Text("Try reopening the app with an Internet connection to refresh the emoji database.")
|
||||
}
|
||||
}
|
||||
.overlay(alignment: .topLeading) {
|
||||
if edit {
|
||||
Button(role: .destructive) {
|
||||
|
||||
@@ -112,6 +112,10 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
Section("Debug") {
|
||||
Button("Refresh", systemImage: "arrow.clockwise", role: .destructive) {
|
||||
hoarder.startLoading(localOnly: false, skipIndex: false)
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
TrieTestingView(hoarder: hoarder)
|
||||
} label: {
|
||||
|
||||