mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 13:26:17 +00:00
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
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
A9BBC5172EB8FA4500FFE82F /* ViewModifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModifiers.swift; sourceTree = "<group>"; };
|
||||
A9C172DB2EB8C9AC008A7885 /* Trie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trie.swift; sourceTree = "<group>"; };
|
||||
A9C7892C2ED2005000D954F5 /* StickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerView.swift; sourceTree = "<group>"; };
|
||||
A9D15B892EB1142C00404792 /* EmojiPack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPack.swift; sourceTree = "<group>"; };
|
||||
A9E2ECD72EB74CE00038B2D6 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
||||
A9EB72382EB93FDB00658CEB /* EmojiCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionView.swift; sourceTree = "<group>"; };
|
||||
@@ -324,6 +326,7 @@
|
||||
A986A6C92EB659E000B6E0FA /* MainInterface.storyboard */,
|
||||
A986A6CA2EB659E000B6E0FA /* MessagesViewController.swift */,
|
||||
A986A6CB2EB659E000B6E0FA /* StickerBrowserDataSource.swift */,
|
||||
A9C7892C2ED2005000D954F5 /* StickerView.swift */,
|
||||
);
|
||||
path = StickerSlackiMessageApp;
|
||||
sourceTree = "<group>";
|
||||
@@ -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 */,
|
||||
|
||||
@@ -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")!
|
||||
|
||||
@@ -131,6 +131,10 @@ class EmojiHoarder: ObservableObject {
|
||||
func buildDownloadedEmojis() {
|
||||
downloadedEmojis = []
|
||||
downloadedEmojisArr = []
|
||||
downloadedEmojisArr = (try? JSONDecoder().decode([String].self, from: UserDefaults.standard.data(forKey: "downloadedEmojisArr") ?? Data())) ?? []
|
||||
downloadedEmojis = (try? JSONDecoder().decode(Set<String>.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)
|
||||
@@ -138,6 +142,10 @@ class EmojiHoarder: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
UserDefaults.standard.set(try! JSONEncoder().encode(downloadedEmojis), forKey: "downloadedEmojis")
|
||||
UserDefaults.standard.set(try! JSONEncoder().encode(downloadedEmojisArr), forKey: "downloadedEmojisArr")
|
||||
}
|
||||
|
||||
nonisolated
|
||||
func loadLocalDB() -> [Emoji] {
|
||||
if let localEmojiDB = try? Data(contentsOf: EmojiHoarder.localEmojiDB) {
|
||||
|
||||
@@ -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)
|
||||
.padding(.trailing, 10)
|
||||
VStack(alignment: .leading) {
|
||||
Text("StickerSlack")
|
||||
.font(.title)
|
||||
.font(.title2)
|
||||
.monospaced()
|
||||
.bold()
|
||||
HStack(alignment: .center, spacing: 5) {
|
||||
Text(Bundle.main.appVersion)
|
||||
.bold()
|
||||
.font(.subheadline)
|
||||
Text(Bundle.main.appBuild)
|
||||
.foregroundStyle(.gray)
|
||||
.font(.subheadline)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user