From 98d8f083a1c2be6bdadca2aa638126d1ed0fb96b Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Sat, 22 Nov 2025 17:31:03 +0000 Subject: [PATCH] massively improved indexing performance: cache the downloadedEmojis Set and Array added resize image function, yet to use the app icon and name are horizontally aligned in settings --- StickerSlack.xcodeproj/project.pbxproj | 4 ++++ StickerSlack/Emoji/Emoji.swift | 24 +++++++++++++++++++ StickerSlack/Emoji/EmojiHoarder.swift | 16 +++++++++---- StickerSlack/SwiftUI/SettingsView.swift | 23 +++++++++++------- .../MessagesViewController.swift | 1 + 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index ac583bf..e80737f 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -65,6 +65,7 @@ A9BBC51A2EB8FA4500FFE82F /* ViewModifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9BBC5172EB8FA4500FFE82F /* ViewModifiers.swift */; }; A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C172DB2EB8C9AC008A7885 /* Trie.swift */; }; A9C172DD2EB8C9AC008A7885 /* Trie.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C172DB2EB8C9AC008A7885 /* Trie.swift */; }; + A9C7892D2ED2005000D954F5 /* StickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9C7892C2ED2005000D954F5 /* StickerView.swift */; }; A9D15B8B2EB1142C00404792 /* EmojiPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D15B892EB1142C00404792 /* EmojiPack.swift */; }; A9EB72392EB93FDB00658CEB /* EmojiCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72382EB93FDB00658CEB /* EmojiCollectionView.swift */; }; A9EB72472EB948C400658CEB /* EmojiRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB72462EB948C400658CEB /* EmojiRow.swift */; }; @@ -143,6 +144,7 @@ A9B9A82C2EB2CCBE004C9245 /* StickerSlackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerSlackTests.swift; sourceTree = ""; }; A9BBC5172EB8FA4500FFE82F /* ViewModifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModifiers.swift; sourceTree = ""; }; A9C172DB2EB8C9AC008A7885 /* Trie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trie.swift; sourceTree = ""; }; + A9C7892C2ED2005000D954F5 /* StickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerView.swift; sourceTree = ""; }; A9D15B892EB1142C00404792 /* EmojiPack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPack.swift; sourceTree = ""; }; A9E2ECD72EB74CE00038B2D6 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; A9EB72382EB93FDB00658CEB /* EmojiCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionView.swift; sourceTree = ""; }; @@ -324,6 +326,7 @@ A986A6C92EB659E000B6E0FA /* MainInterface.storyboard */, A986A6CA2EB659E000B6E0FA /* MessagesViewController.swift */, A986A6CB2EB659E000B6E0FA /* StickerBrowserDataSource.swift */, + A9C7892C2ED2005000D954F5 /* StickerView.swift */, ); path = StickerSlackiMessageApp; sourceTree = ""; @@ -521,6 +524,7 @@ A9EB724B2EB94A5700658CEB /* Trie.swift in Sources */, A986A6CD2EB659E000B6E0FA /* MessagesViewController.swift in Sources */, A986A6CE2EB659E000B6E0FA /* StickerBrowserDataSource.swift in Sources */, + A9C7892D2ED2005000D954F5 /* StickerView.swift in Sources */, A957C17E2ECFAA1100EA3EE9 /* GifView.swift in Sources */, A9BBC5192EB8FA4500FFE82F /* ViewModifiers.swift in Sources */, A986A6C42EB6598500B6E0FA /* SlackResponse.swift in Sources */, diff --git a/StickerSlack/Emoji/Emoji.swift b/StickerSlack/Emoji/Emoji.swift index 2bfae8d..d975e7f 100644 --- a/StickerSlack/Emoji/Emoji.swift +++ b/StickerSlack/Emoji/Emoji.swift @@ -78,6 +78,11 @@ struct Emoji: Codable, Identifiable, Hashable { return } let (data, _) = try await URLSession.shared.data(from: remoteImageURL) + + if let cgImage = UIImage(data: data)?.cgImage, + cgImage.width < 300 || cgImage.height < 300 { + + } try! await data.write(to: localImageURL) return } @@ -92,6 +97,25 @@ struct Emoji: Codable, Identifiable, Hashable { withAnimation { self.uiID = UUID() } } + func resize(image: UIImage, to targetSize: CGSize) -> UIImage { + let oldSize = image.size + let ratio: (x: CGFloat, y: CGFloat) + ratio.x = targetSize.width / oldSize.width + ratio.y = targetSize.height / oldSize.height + + var newSize: CGSize + if ratio.x > ratio.y { + newSize = CGSize(width: oldSize.width * ratio.y, height: oldSize.height * ratio.y) + } else { + newSize = CGSize(width: oldSize.width * ratio.x, height: oldSize.height * ratio.x) + } + + let rect = CGRect(origin: .zero, size: newSize) + UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) + image.draw(in: rect) + return UIGraphicsGetImageFromCurrentImageContext() ?? UIImage() + } + static var test: Emoji = Emoji( name: "s?", url: URL(string: "https://neon443.github.io/images/fav.ico")! diff --git a/StickerSlack/Emoji/EmojiHoarder.swift b/StickerSlack/Emoji/EmojiHoarder.swift index 68cca21..ae73a45 100644 --- a/StickerSlack/Emoji/EmojiHoarder.swift +++ b/StickerSlack/Emoji/EmojiHoarder.swift @@ -131,11 +131,19 @@ class EmojiHoarder: ObservableObject { func buildDownloadedEmojis() { downloadedEmojis = [] downloadedEmojisArr = [] - for emoji in emojis { - guard emoji.isLocal else { continue } - downloadedEmojis.insert(emoji.name) - downloadedEmojisArr.append(emoji.name) + downloadedEmojisArr = (try? JSONDecoder().decode([String].self, from: UserDefaults.standard.data(forKey: "downloadedEmojisArr") ?? Data())) ?? [] + downloadedEmojis = (try? JSONDecoder().decode(Set.self, from: UserDefaults.standard.data(forKey: "downloadedEmojis") ?? Data())) ?? [] + + if downloadedEmojis.isEmpty || downloadedEmojisArr.isEmpty { + for emoji in emojis { + guard emoji.isLocal else { continue } + downloadedEmojis.insert(emoji.name) + downloadedEmojisArr.append(emoji.name) + } } + + UserDefaults.standard.set(try! JSONEncoder().encode(downloadedEmojis), forKey: "downloadedEmojis") + UserDefaults.standard.set(try! JSONEncoder().encode(downloadedEmojisArr), forKey: "downloadedEmojisArr") } nonisolated diff --git a/StickerSlack/SwiftUI/SettingsView.swift b/StickerSlack/SwiftUI/SettingsView.swift index 5efd748..d96793a 100644 --- a/StickerSlack/SwiftUI/SettingsView.swift +++ b/StickerSlack/SwiftUI/SettingsView.swift @@ -18,22 +18,27 @@ struct SettingsView: View { NavigationStack { List { Section { - VStack(alignment: .leading) { + HStack { Image(isDark ? "icon-dark" : "icon") .resizable().scaledToFit() .frame(width: 100, height: 100) .clipShape(RoundedRectangle(cornerRadius: 24)) .foregroundStyle(.purple) .shadow(color: isDark ? .white : .purple, radius: 5) - Text("StickerSlack") - .font(.title) - .monospaced() - .bold() - HStack(alignment: .center, spacing: 5) { - Text(Bundle.main.appVersion) + .padding(.trailing, 10) + VStack(alignment: .leading) { + Text("StickerSlack") + .font(.title2) + .monospaced() .bold() - Text(Bundle.main.appBuild) - .foregroundStyle(.gray) + HStack(alignment: .center, spacing: 5) { + Text(Bundle.main.appVersion) + .bold() + .font(.subheadline) + Text(Bundle.main.appBuild) + .foregroundStyle(.gray) + .font(.subheadline) + } } } } diff --git a/StickerSlackiMessageApp/MessagesViewController.swift b/StickerSlackiMessageApp/MessagesViewController.swift index 8f07770..aa04846 100644 --- a/StickerSlackiMessageApp/MessagesViewController.swift +++ b/StickerSlackiMessageApp/MessagesViewController.swift @@ -27,6 +27,7 @@ class MessagesViewController: MSMessagesAppViewController { view.addSubview(stickerBrowser) stickerBrowser.reloadData() view.bringSubviewToFront(stickerBrowser) + // Called when the extension is about to move from the inactive to active state. // This will happen when the extension is about to present UI.