review changes

This commit is contained in:
shenlong-tanwen 2025-10-12 17:21:25 +05:30
parent 08f2ebd90c
commit 4c0e1ff5f8
2 changed files with 6 additions and 12 deletions

View file

@ -52,9 +52,7 @@ import UIKit
} }
public static func registerPlugins(with engine: FlutterEngine) { public static func registerPlugins(with engine: FlutterEngine) {
if !engine.hasPlugin("NativeSyncApi") { NativeSyncApiImpl.register(with: engine.registrar(forPlugin: NativeSyncApiImpl.name)!)
NativeSyncApiImpl.register(with: engine.registrar(forPlugin: "NativeSyncApi")!)
}
ThumbnailApiSetup.setUp(binaryMessenger: engine.binaryMessenger, api: ThumbnailApiImpl()) ThumbnailApiSetup.setUp(binaryMessenger: engine.binaryMessenger, api: ThumbnailApiImpl())
BackgroundWorkerFgHostApiSetup.setUp(binaryMessenger: engine.binaryMessenger, api: BackgroundWorkerApiImpl()) BackgroundWorkerFgHostApiSetup.setUp(binaryMessenger: engine.binaryMessenger, api: BackgroundWorkerApiImpl())
} }

View file

@ -33,7 +33,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
private let albumTypes: [PHAssetCollectionType] = [.album, .smartAlbum] private let albumTypes: [PHAssetCollectionType] = [.album, .smartAlbum]
private let recoveredAlbumSubType = 1000000219 private let recoveredAlbumSubType = 1000000219
private var hashTask: Task<Void, Error>? private var hashTask: Task<Void?, Error>?
private static let hashCancelledCode = "HASH_CANCELLED" private static let hashCancelledCode = "HASH_CANCELLED"
private static let hashCancelled = Result<[HashResult], Error>.failure(PigeonError(code: hashCancelledCode, message: "Hashing cancelled", details: nil)) private static let hashCancelled = Result<[HashResult], Error>.failure(PigeonError(code: hashCancelledCode, message: "Hashing cancelled", details: nil))
@ -282,8 +282,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
} }
if Task.isCancelled { if Task.isCancelled {
self?.completeWhenActive(for: completion, with: Self.hashCancelled) return self?.completeWhenActive(for: completion, with: Self.hashCancelled)
return
} }
await withTaskGroup(of: HashResult?.self) { taskGroup in await withTaskGroup(of: HashResult?.self) { taskGroup in
@ -291,8 +290,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
results.reserveCapacity(assets.count) results.reserveCapacity(assets.count)
for asset in assets { for asset in assets {
if Task.isCancelled { if Task.isCancelled {
self?.completeWhenActive(for: completion, with: Self.hashCancelled) return self?.completeWhenActive(for: completion, with: Self.hashCancelled)
return
} }
taskGroup.addTask { taskGroup.addTask {
guard let self = self else { return nil } guard let self = self else { return nil }
@ -302,8 +300,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
for await result in taskGroup { for await result in taskGroup {
guard let result = result else { guard let result = result else {
self?.completeWhenActive(for: completion, with: Self.hashCancelled) return self?.completeWhenActive(for: completion, with: Self.hashCancelled)
return
} }
results.append(result) results.append(result)
} }
@ -312,8 +309,7 @@ class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin {
results.append(HashResult(assetId: missing, error: "Asset not found in library", hash: nil)) results.append(HashResult(assetId: missing, error: "Asset not found in library", hash: nil))
} }
self?.completeWhenActive(for: completion, with: .success(results)) return self?.completeWhenActive(for: completion, with: .success(results))
return
} }
} }
} }