Explorar o código

fix: 修复部分 bugs

陈文艺 hai 3 meses
pai
achega
f6322c4764

+ 15 - 3
Lanu/Common/Storage/LNUserDefaults.swift

@@ -17,10 +17,9 @@ class LNUserDefaultsManager {
     
     // 内存缓存容器
     private var cache: [String: Any] = [:]
-    // 存储容器(支持 App Group)
+    private let lock = NSLock()
+    
     private let userDefaults: UserDefaults = {
-        // 如需共享数据,可替换为 App Group 的 suiteName
-        // return UserDefaults(suiteName: "your.app.group") ?? .standard
         return .standard
     }()
     
@@ -44,7 +43,9 @@ class LNUserDefaultsManager {
             let data = try JSONEncoder().encode(value)
             userDefaults.set(data, forKey: key.rawValue)
             // 更新缓存
+            lock.lock()
             cache[key.rawValue] = value
+            lock.unlock()
         } catch {
             Log.e("存储失败(key: \(key)):\(error)")
         }
@@ -53,6 +54,11 @@ class LNUserDefaultsManager {
     /// 读取数据(自动推断类型,无需显式传递 Type.self)
     private func value<T: Codable>(forKey key: LNUserDefaultsKey) -> T? {
         // 优先从缓存读取
+        lock.lock()
+        defer {
+            lock.unlock()
+        }
+        
         if let cached = cache[key.rawValue] as? T {
             return cached
         }
@@ -79,17 +85,23 @@ class LNUserDefaultsManager {
     // 辅助方法:删除数据
     func remove(forKey key: LNUserDefaultsKey) {
         userDefaults.removeObject(forKey: key.rawValue)
+        lock.lock()
         cache.removeValue(forKey: key.rawValue)
+        lock.unlock()
     }
     
     // 辅助方法:清除所有数据(包括缓存)
     func clearAll() {
         userDefaults.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
+        lock.lock()
         cache.removeAll()
+        lock.unlock()
     }
     
     // 辅助方法:仅清除内存缓存
     func clearCache() {
+        lock.lock()
         cache.removeAll()
+        lock.unlock()
     }
 }

+ 2 - 0
Lanu/Views/Settings/LNAboutViewController.swift

@@ -105,6 +105,8 @@ extension LNAboutViewController {
             version.onTap {
                 LNAppConfig.shared.jumpToAppStore()
             }
+        } else {
+            showToast(.init(key: "已是最新版本"))
         }
         stackView.addArrangedSubview(version)
     }

+ 1 - 0
Lanu/Views/Wallet/Coin/LNCoinViewController.swift

@@ -256,6 +256,7 @@ extension LNCoinViewController {
         textView.font = .body_s
         textView.textColor = .text_4
         textView.linkTextAttributes = [.foregroundColor: UIColor.primary_5]
+        textView.isEditable = false
         container.addSubview(textView)
         textView.snp.makeConstraints { make in
             make.directionalHorizontalEdges.equalToSuperview().inset(-4)

+ 1 - 0
Lanu/Views/Wallet/Diamond/LNDiamondViewController.swift

@@ -256,6 +256,7 @@ extension LNDiamondViewController {
         textView.font = .body_s
         textView.textColor = .text_4
         textView.linkTextAttributes = [.foregroundColor: UIColor.primary_5]
+        textView.isEditable = false
         container.addSubview(textView)
         textView.snp.makeConstraints { make in
             make.directionalHorizontalEdges.equalToSuperview().inset(-4)