High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(mobile): pause image loading on inactive state (#21543)
Merte427778a9671
diff --git a/mobile/ios/Runner/Images/ThumbnailsImpl.swift b/mobile/ios/Runner/Images/ThumbnailsImpl.swiftindex 42f0930cb1..d1ea2cc0e0 100644--- a/mobile/ios/Runner/Images/ThumbnailsImpl.swift+++ b/mobile/ios/Runner/Images/ThumbnailsImpl.swift@@ -46,6 +46,23 @@ class ThumbnailApiImpl: ThumbnailApi {assetCache.countLimit = 10000return assetCache}()+ private static let activitySemaphore = DispatchSemaphore(value: 1)+ private static let willResignActiveObserver = NotificationCenter.default.addObserver(+ forName: UIApplication.willResignActiveNotification,+ object: nil,+ queue: .main+ ) { _ in+ processingQueue.suspend()+ activitySemaphore.wait()+ }+ private static let didBecomeActiveObserver = NotificationCenter.default.addObserver(+ forName: UIApplication.didBecomeActiveNotification,+ object: nil,+ queue: .main+ ) { _ in+ processingQueue.resume()+ activitySemaphore.signal()+ }func getThumbhash(thumbhash: String, completion: @escaping (Result<[String : Int64], any Error>) -> Void) {Self.processingQueue.async {@@ -53,6 +70,7 @@ class ThumbnailApiImpl: ThumbnailApi {else { return completion(.failure(PigeonError(code: "", message: "Invalid base64 string: \(thumbhash)", details: nil)))}let (width, height, pointer) = thumbHashToRGBA(hash: data)+ self.waitForActiveState()completion(.success(["pointer": Int64(Int(bitPattern: pointer.baseAddress)), "width": Int64(width), "height": Int64(height)]))}}@@ -142,6 +160,7 @@ class ThumbnailApiImpl: ThumbnailApi {return completion(Self.cancelledResult)}+ self.waitForActiveState()completion(.success(["pointer": Int64(Int(bitPattern: pointer)), "width": Int64(cgImage.width), "height": Int64(cgImage.height)]))Self.removeRequest(requestId: requestId)}@@ -184,4 +203,9 @@ class ThumbnailApiImpl: ThumbnailApi {assetQueue.async { assetCache.setObject(asset, forKey: assetId as NSString) }return asset}++ func waitForActiveState() {+ Self.activitySemaphore.wait()+ Self.activitySemaphore.signal()+ }}