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