mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
support systemwide picker
cleanup
This commit is contained in:
5 files changed
+27
-31
No files matched your search
@@ -69,7 +69,7 @@ class EmojiHoarder: BaseHoarder {
|
||||
await withTaskGroup { group in
|
||||
for i in emojis.indices {
|
||||
group.addTask {
|
||||
guard await self.downloadedStickers.contains(self.emojis[i].name) else { return }
|
||||
guard self.downloadedStickers.contains(self.emojis[i].name) else { return }
|
||||
await self.delete(emoji: self.emojis[i], skipStoreIndex: true)
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ class EmojiHoarder: BaseHoarder {
|
||||
}
|
||||
|
||||
nonisolated private func saveTrieDict() async {
|
||||
guard let dataDict = try? await encoder.encode(trie.dict) else {
|
||||
guard let dataDict = try? encoder.encode(trie.dict) else {
|
||||
fatalError("failed to encode trie dict")
|
||||
}
|
||||
try! dataDict.write(to: EmojiHoarder.localTrieDict)
|
||||
@@ -113,18 +113,17 @@ class EmojiHoarder: BaseHoarder {
|
||||
return decodedDict
|
||||
}
|
||||
|
||||
nonisolated
|
||||
func buildTrie() async {
|
||||
nonisolated func buildTrie() async {
|
||||
let start = Date().timeIntervalSince1970
|
||||
var wordlist = await trie.wordlist
|
||||
var dict = await trie.dict
|
||||
for emoji in await emojis {
|
||||
var wordlist = trie.wordlist
|
||||
var dict = trie.dict
|
||||
for emoji in emojis {
|
||||
// trie.insert(word: emoji.name)
|
||||
wordlist.insert(emoji.name)
|
||||
dict[emoji.name] = emoji
|
||||
}
|
||||
await trie.wordlist = wordlist
|
||||
await trie.dict = dict
|
||||
trie.wordlist = wordlist
|
||||
trie.dict = dict
|
||||
|
||||
await buildDownloadedStickers()
|
||||
print("done building trie in", Date().timeIntervalSince1970-start)
|
||||
@@ -153,7 +152,7 @@ class EmojiHoarder: BaseHoarder {
|
||||
nonisolated private func loadRemoteDB() async {
|
||||
async let fetched = self.fetchRemoteDB()
|
||||
if let fetched = await fetched,
|
||||
await fetched != self.emojis {
|
||||
fetched != self.emojis {
|
||||
await MainActor.run {
|
||||
withAnimation(.snappy) { self.emojis = fetched }
|
||||
sendChangeNotif(for: .emojis)
|
||||
@@ -164,9 +163,9 @@ class EmojiHoarder: BaseHoarder {
|
||||
nonisolated private func fetchRemoteDB() async -> [Emoji]? {
|
||||
do {
|
||||
async let (data, _) = try URLSession.shared.data(from: endpoint)
|
||||
let decoded: [SlackResponse] = try await decoder.decode([SlackResponse].self, from: await data)
|
||||
try await storeDB(data: await data)
|
||||
return await SlackResponse.toEmojis(from: decoded)
|
||||
let decoded: [SlackResponse] = try decoder.decode([SlackResponse].self, from: await data)
|
||||
try storeDB(data: await data)
|
||||
return SlackResponse.toEmojis(from: decoded)
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
return nil
|
||||
@@ -215,7 +214,7 @@ class EmojiHoarder: BaseHoarder {
|
||||
|
||||
override nonisolated func download(emoji: (any StickerProtocol)?, skipStoreIndex: Bool = false) async {
|
||||
guard let emoji else { return }
|
||||
guard await !downloadedStickers.contains(emoji.name) else { return }
|
||||
guard !downloadedStickers.contains(emoji.name) else { return }
|
||||
await super.download(emoji: emoji, skipStoreIndex: skipStoreIndex)
|
||||
|
||||
await MainActor.run {
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>MSSupportedPresentationContexts</key>
|
||||
<array>
|
||||
<string>MSMessagesAppPresentationContextMessages</string>
|
||||
<string>MSMessagesAppPresentationContextMedia</string>
|
||||
</array>
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
|
||||
@@ -79,9 +79,8 @@ extension StickerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated
|
||||
func downloadImage() async throws {
|
||||
if let data = try? await Data(contentsOf: localImageURL),
|
||||
nonisolated func downloadImage() async throws {
|
||||
if let data = try? Data(contentsOf: localImageURL),
|
||||
let _ = UIImage(data: data) {
|
||||
return
|
||||
}
|
||||
@@ -90,11 +89,11 @@ extension StickerProtocol {
|
||||
|
||||
let targetSize = CGSize(width: 100, height: 100)
|
||||
if let uiImage = UIImage(data: data),
|
||||
await localImageURLString.suffix(4) != ".gif" {
|
||||
localImageURLString.suffix(4) != ".gif" {
|
||||
data = await resize(image: uiImage, to: targetSize).pngData()!
|
||||
}
|
||||
|
||||
try! await data.write(to: localImageURL)
|
||||
try! data.write(to: localImageURL)
|
||||
}
|
||||
|
||||
func deleteImage() {
|
||||
|
||||
@@ -37,7 +37,7 @@ class EmojiPackDetailViewController: UIViewController {
|
||||
|
||||
let suiView = EmptyCollectionView(
|
||||
title: "No Emoji",
|
||||
details: "Add emojis to this pack by editing it using the pencil button in the toolbar.",
|
||||
details: "Add emojis to this pack by editing it using the edit button in the toolbar.",
|
||||
systemImage: "exclamationmark.triangle.fill"
|
||||
)
|
||||
self.emptyCollectionView = UIHostingController(rootView: suiView)
|
||||
@@ -160,13 +160,12 @@ class EmojiPackDetailViewController: UIViewController {
|
||||
}
|
||||
|
||||
func setToolbar(editing: Bool) {
|
||||
let items: [UIBarButtonItem]
|
||||
var items: [UIBarButtonItem] = [self.collectionView.editButtonItem]
|
||||
if editing {
|
||||
if #available(iOS 26, *) {
|
||||
items = [self.collectionView.editButtonItem, .fixedSpace(), self.adderSheetButton]
|
||||
} else {
|
||||
items = [self.collectionView.editButtonItem, self.adderSheetButton]
|
||||
items.append(.fixedSpace(0))
|
||||
}
|
||||
items.append(self.adderSheetButton)
|
||||
} else {
|
||||
let shareMenu = UIMenu(options: .displayInline, children: [shareButton])
|
||||
let menu = UIMenu(children: [downloadButton, shareMenu])
|
||||
|
||||
@@ -216,7 +216,6 @@ class EmojiPackListView: UITableViewController {
|
||||
let duplicate = UIAction(title: "Duplicate", image: UIImage(systemName: "plus.square.fill.on.square.fill")) { action in
|
||||
self.dup(indexPath)
|
||||
}
|
||||
// UIMenu(options: .displayInline, children: [delete])
|
||||
let share = UIAction(title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { action in
|
||||
self.share(indexPath)
|
||||
}
|
||||
@@ -267,11 +266,6 @@ class EmojiPackListView: UITableViewController {
|
||||
}
|
||||
delete.image = UIImage(systemName: "trash")
|
||||
|
||||
let dupButton = UIContextualAction(style: .normal, title: "Duplicate") { _, _, _ in
|
||||
self.dup(indexPath)
|
||||
}
|
||||
dupButton.image = UIImage(systemName: "plus.square.fill.on.square.fill")
|
||||
|
||||
let rename = UIContextualAction(style: .normal, title: "Rename") { _, _, _ in
|
||||
self.showRenamer(for: indexPath)
|
||||
}
|
||||
@@ -281,7 +275,7 @@ class EmojiPackListView: UITableViewController {
|
||||
self.share(indexPath)
|
||||
}
|
||||
share.image = UIImage(systemName: "square.and.arrow.up")
|
||||
return UISwipeActionsConfiguration(actions: [delete, dupButton, rename, share])
|
||||
return UISwipeActionsConfiguration(actions: [delete, rename, share])
|
||||
}
|
||||
|
||||
}
|
||||