-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix: ios skip posting hash response after detached from engine #22695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| class ImmichPlugin: NSObject { | ||
| var detached: Bool | ||
|
|
||
| override init() { | ||
| detached = false | ||
| super.init() | ||
| } | ||
|
|
||
| func detachFromEngine() { | ||
| self.detached = true | ||
| } | ||
|
|
||
| func completeWhenActive<T>(for completion: @escaping (T) -> Void, with value: T) { | ||
| guard !self.detached else { return } | ||
| completion(value) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,25 @@ struct AssetWrapper: Hashable, Equatable { | |
| } | ||
| } | ||
|
|
||
| class NativeSyncApiImpl: NativeSyncApi { | ||
| class NativeSyncApiImpl: ImmichPlugin, NativeSyncApi, FlutterPlugin { | ||
| static let name = "NativeSyncApi" | ||
|
|
||
| static func register(with registrar: any FlutterPluginRegistrar) { | ||
| let instance = NativeSyncApiImpl() | ||
| NativeSyncApiSetup.setUp(binaryMessenger: registrar.messenger(), api: instance) | ||
| registrar.publish(instance) | ||
| } | ||
|
|
||
| func detachFromEngine(for registrar: any FlutterPluginRegistrar) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: useless override |
||
| super.detachFromEngine() | ||
| } | ||
mertalev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private let defaults: UserDefaults | ||
| private let changeTokenKey = "immich:changeToken" | ||
| private let albumTypes: [PHAssetCollectionType] = [.album, .smartAlbum] | ||
| 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 hashCancelled = Result<[HashResult], Error>.failure(PigeonError(code: hashCancelledCode, message: "Hashing cancelled", details: nil)) | ||
|
|
||
|
|
@@ -272,15 +284,15 @@ class NativeSyncApiImpl: NativeSyncApi { | |
| } | ||
|
|
||
| if Task.isCancelled { | ||
| return completion(Self.hashCancelled) | ||
| return self?.completeWhenActive(for: completion, with: Self.hashCancelled) | ||
| } | ||
|
|
||
| await withTaskGroup(of: HashResult?.self) { taskGroup in | ||
| var results = [HashResult]() | ||
| results.reserveCapacity(assets.count) | ||
| for asset in assets { | ||
| if Task.isCancelled { | ||
| return completion(Self.hashCancelled) | ||
| return self?.completeWhenActive(for: completion, with: Self.hashCancelled) | ||
| } | ||
| taskGroup.addTask { | ||
| guard let self = self else { return nil } | ||
|
|
@@ -290,7 +302,7 @@ class NativeSyncApiImpl: NativeSyncApi { | |
|
|
||
| for await result in taskGroup { | ||
| guard let result = result else { | ||
| return completion(Self.hashCancelled) | ||
| return self?.completeWhenActive(for: completion, with: Self.hashCancelled) | ||
| } | ||
| results.append(result) | ||
| } | ||
|
|
@@ -299,7 +311,7 @@ class NativeSyncApiImpl: NativeSyncApi { | |
| results.append(HashResult(assetId: missing, error: "Asset not found in library", hash: nil)) | ||
| } | ||
|
|
||
| completion(.success(results)) | ||
| return self?.completeWhenActive(for: completion, with: .success(results)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.