Skip to content
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

Bugfix: Missing lock icons in vaults list #386

Merged
merged 7 commits into from
Oct 16, 2024

Conversation

iammajid
Copy link
Contributor

This pull request fixes the issue described in bug ticket #346, where the lock icons are missing in the vaults list after iOS 17.4 and newer.

Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

The changes primarily involve significant updates to the VaultListViewModel class in VaultListViewModel.swift, particularly in the refreshVaultLockStates and checkVaultUnlockStatus methods. The former has been refactored to utilize promises for concurrent checks of vault unlock statuses, while the latter now directly queries the unlock status for each vault. Additionally, the VaultListViewModelTests class has been updated to reflect these changes, specifically in the assertions of the testRefreshVaultLockedStates method. The project structure has also been modified, with some files removed and new ones added.

Changes

File Change Summary
Cryptomator/VaultList/VaultListViewModel.swift Refactored refreshVaultLockStates to use promises for concurrent checks of vault unlock statuses. Updated checkVaultUnlockStatus to directly query vault unlock status and enhanced error handling. Method signature updated for refreshVaultLockStates, and a new method checkVaultUnlockStatus added.
CryptomatorTests/VaultListViewModelTests.swift Modified testRefreshVaultLockedStates to update assertions related to passedDomainIdentifier and xpcInvalidationCallCount, reflecting changes in the VaultListViewModel logic.
Cryptomator.xcodeproj/project.pbxproj Removed Promise+AllIgnoringResult.swift and Promise+AllIgnoringResultsTests.swift. Added new files and updated project structure with new groups and build phases.
CryptomatorCommon/Sources/CryptomatorCommonCore/Promise+AllIgnoringResult.swift Changed visibility of all function from internal to public.
CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Promise+AllIgnoringResultsTests.swift Updated module name from CryptomatorFileProviderTests to CryptomatorCommonCoreTests, modified import statements, but no changes to test logic.
CryptomatorCommon/Tests/CryptomatorCommonCoreTests/XCTestCase+Promises.swift Added method XCTAssertGetsNotExecuted to enhance promise testing capabilities.
Cryptomator/Snapshots/SnapshotCoordinator.swift Removed getUnlockedVaultDomainIdentifiers method from SnapshotVaultLockingMock.
CryptomatorCommon/Sources/CryptomatorCommonCore/FileProviderXPC/VaultLocking.swift Removed getUnlockedVaultDomainIdentifiers method from VaultLocking protocol.
CryptomatorFileProvider/FileProviderAdapterManager.swift Removed getDomainIdentifiersOfUnlockedVaults() method.
CryptomatorFileProvider/ServiceSource/VaultLockingServiceSource.swift Removed getUnlockedVaultDomainIdentifiers method.
CryptomatorFileProviderTests/FileProviderAdapterManagerTests.swift Removed testGetDomainIdentifiersOfUnlockedVaults() method.
CryptomatorFileProviderTests/Mocks/FileProviderAdapterCacheTypeMock.swift Removed getAllCachedIdentifiers method and associated properties.

Possibly related PRs

  • Add UnauthorizedError screen for invalid cloud access in Files app #384: The changes in the main PR involve modifications to the VaultListViewModel class, particularly in methods related to vault unlock status, which may be indirectly related to the user experience improvements introduced in the unauthorized error handling and reauthentication processes in the retrieved PR.

Poem

In the vaults where secrets hide,
A promise whispers, side by side.
Locks now checked with swift delight,
As rabbits hop through day and night.
With tests refined, our paths align,
Unlocking treasures, oh so fine! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@iammajid iammajid changed the title Bugix/missing lock icon Bugix: Missing Lock Icons in Vaults List Oct 11, 2024
@iammajid iammajid changed the title Bugix: Missing Lock Icons in Vaults List Bugix: Missing lock icons in vaults list Oct 11, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 87bda1b and 99a0e0c.

📒 Files selected for processing (2)
  • Cryptomator/VaultList/VaultListViewModel.swift (1 hunks)
  • CryptomatorTests/VaultListViewModelTests.swift (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
CryptomatorTests/VaultListViewModelTests.swift (3)

134-134: LGTM. Please clarify the reason for this change.

The assertion has been updated to expect a specific domain identifier ("vault1") instead of a nil value. This change aligns with the PR objective of fixing the missing lock icon issue.

Could you please provide more context on why this change was necessary? For example, was the previous behavior incorrect, or does this reflect a change in the implementation of refreshVaultLockStates?


146-146: LGTM. Please explain the reason for increasing the expected count.

The expected xpcInvalidationCallCount has been increased from 1 to 2. This change suggests that an additional XPC invalidation is now occurring during the refreshVaultLockStates process.

Could you please elaborate on why this additional invalidation is now necessary? Is it related to ensuring the lock icon is properly updated in the UI?


Line range hint 1-265: Overall, the changes look good. Please provide an overview of the fix.

The modifications to the testRefreshVaultLockedStates method seem to align with the PR objective of fixing the missing lock icon issue. The test now expects a specific domain identifier to be passed and an additional XPC invalidation to occur.

To ensure a comprehensive understanding of the fix:

  1. Could you provide an overview of the changes made in the main implementation to address the missing lock icon issue?
  2. How do these test modifications reflect those changes?
  3. Are there any other tests that needed to be updated as a result of this fix?

Cryptomator/VaultList/VaultListViewModel.swift Outdated Show resolved Hide resolved
Cryptomator/VaultList/VaultListViewModel.swift Outdated Show resolved Hide resolved
Cryptomator/VaultList/VaultListViewModel.swift Outdated Show resolved Hide resolved
Cryptomator/VaultList/VaultListViewModel.swift Outdated Show resolved Hide resolved
Cryptomator/VaultList/VaultListViewModel.swift Outdated Show resolved Hide resolved
Cryptomator/VaultList/VaultListViewModel.swift Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
CryptomatorCommon/Sources/CryptomatorCommonCore/Promise+AllIgnoringResult.swift (1)

Line range hint 12-17: Approve the visibility change and suggest a minor naming improvement.

The change to make this function public is appropriate, as it allows for its use in other modules like VaultListViewModel. This aligns with the learning from tobihagemann.

However, I have a minor suggestion to improve clarity:

Consider renaming the function to allSettled or allCompleted instead of all. The current name might be slightly misleading as the function uses any internally and doesn't behave exactly like a typical Promise.all. The suggested names better reflect that the function waits for all promises to settle, regardless of their individual outcomes.

Here's a suggested change:

-public func all<Value, Container: Sequence>(ignoringResult promises: Container) -> Promise<Void> where Container.Element == Promise<Value> {
+public func allSettled<Value, Container: Sequence>(ignoringResult promises: Container) -> Promise<Void> where Container.Element == Promise<Value> {

This change would make the function's behavior more immediately clear to other developers using this API.

CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Promise+AllIgnoringResultsTests.swift (1)

Line range hint 13-33: LGTM: Test methods remain valid and comprehensive.

The test methods testWaitForAll and testWaitForAllWithRejectedPromise appear to be unchanged and still valid after the module restructuring. They provide good coverage for both fulfilled and rejected promise scenarios.

For improved clarity, consider adding a brief comment before each test method explaining its purpose. For example:

// Test that all(ignoringResult:) waits for all promises to be fulfilled
func testWaitForAll() throws {
    // ... existing code ...
}

// Test that all(ignoringResult:) completes even when one promise is rejected
func testWaitForAllWithRejectedPromise() throws {
    // ... existing code ...
}
CryptomatorCommon/Tests/CryptomatorCommonCoreTests/XCTestCase+Promises.swift (1)

41-48: Excellent addition to enhance promise testing capabilities!

The XCTAssertGetsNotExecuted method is a valuable addition to the XCTestCase extension. It provides a clean way to assert that a promise does not execute within a specified timeframe, which is crucial for negative testing scenarios.

The implementation is well-thought-out:

  1. Using an inverted expectation is an elegant solution.
  2. The always block ensures the expectation is fulfilled regardless of the promise's outcome.
  3. The method signature is consistent with XCTest conventions.

Consider adding a brief comment explaining the method's purpose and how it works. This would enhance code readability and make it easier for other developers to understand and use this method. For example:

/// Asserts that the given promise does not execute within the specified timeout.
/// This is useful for testing scenarios where a promise is expected to not resolve or reject.
func XCTAssertGetsNotExecuted<T>(_ promise: Promise<T>, timeout seconds: TimeInterval = 1.0, file: StaticString = #filePath, line: UInt = #line) {
    // ... (existing implementation)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 99a0e0c and 889984d.

📒 Files selected for processing (6)
  • Cryptomator.xcodeproj/project.pbxproj (0 hunks)
  • Cryptomator/VaultList/VaultListViewModel.swift (1 hunks)
  • CryptomatorCommon/Sources/CryptomatorCommonCore/Promise+AllIgnoringResult.swift (1 hunks)
  • CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Promise+AllIgnoringResultsTests.swift (1 hunks)
  • CryptomatorCommon/Tests/CryptomatorCommonCoreTests/XCTestCase+Promises.swift (1 hunks)
  • CryptomatorFileProvider/Workflow/WorkflowDependencyFactory.swift (1 hunks)
💤 Files with no reviewable changes (1)
  • Cryptomator.xcodeproj/project.pbxproj
✅ Files skipped from review due to trivial changes (1)
  • CryptomatorFileProvider/Workflow/WorkflowDependencyFactory.swift
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: tobihagemann
PR: cryptomator/ios#386
File: Cryptomator/VaultList/VaultListViewModel.swift:112-112
Timestamp: 2024-10-14T15:45:13.118Z
Learning: In `VaultListViewModel`, use `all(ignoringResult: promises)` instead of `all(promises).then { }` and omit unnecessary logging when refreshing vault lock states.
Cryptomator/VaultList/VaultListViewModel.swift (2)
Learnt from: tobihagemann
PR: cryptomator/ios#386
File: Cryptomator/VaultList/VaultListViewModel.swift:112-112
Timestamp: 2024-10-14T15:45:13.118Z
Learning: In `VaultListViewModel`, use `all(ignoringResult: promises)` instead of `all(promises).then { }` and omit unnecessary logging when refreshing vault lock states.
Learnt from: tobihagemann
PR: cryptomator/ios#386
File: Cryptomator/VaultList/VaultListViewModel.swift:123-126
Timestamp: 2024-10-14T15:45:19.005Z
Learning: Prefer using `DDLogDebug` instead of `DDLogInfo` to avoid log spam.
🔇 Additional comments (2)
Cryptomator/VaultList/VaultListViewModel.swift (2)

107-111: Excellent refactoring of refreshVaultLockStates

The implementation has been improved to use concurrent asynchronous checks for vault unlock statuses. The use of all(ignoringResult: promises) is an excellent choice, as it allows the operation to proceed even if individual checks fail. This aligns with the best practices for handling multiple promises in this codebase.


107-123: Overall improvements in vault lock state handling

The changes in this file significantly improve the handling of vault lock states:

  1. The refreshVaultLockStates method now efficiently manages concurrent asynchronous checks for all vaults.
  2. The new checkVaultUnlockStatus method provides a clear, promise-based approach to checking individual vault lock states.

These improvements should effectively address the issue of missing lock icons in the vaults list (bug ticket #346). The code is now more robust and should handle the lock state updates more reliably, especially after the iOS 17.4 update.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
Cryptomator/VaultList/VaultListViewModel.swift (1)

113-126: LGTM! Well-implemented unlock status check with appropriate logging.

The checkVaultUnlockStatus method efficiently checks the unlock status for a single vault and uses appropriate logging levels (DDLogDebug and DDLogError) as suggested in previous feedback.

Consider adding a specific error type or enum for better error handling and consistency across the codebase.

You could improve error handling by defining a specific error type:

enum VaultUnlockStatusError: Error {
    case failedToGetXPC
    case failedToCheckUnlockStatus(underlyingError: Error)
}

Then update the error handling:

}.catch { error in
    let vaultError = VaultUnlockStatusError.failedToCheckUnlockStatus(underlyingError: error)
    DDLogError("Failed to check unlock status for vault \(vault.vaultUID): \(vaultError)")
}

This approach would provide more structured error information and improve error handling consistency throughout the codebase.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 889984d and 849b837.

📒 Files selected for processing (1)
  • Cryptomator/VaultList/VaultListViewModel.swift (1 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: tobihagemann
PR: cryptomator/ios#386
File: Cryptomator/VaultList/VaultListViewModel.swift:112-112
Timestamp: 2024-10-14T15:45:13.118Z
Learning: In `VaultListViewModel`, use `all(ignoringResult: promises)` instead of `all(promises).then { }` and omit unnecessary logging when refreshing vault lock states.
Cryptomator/VaultList/VaultListViewModel.swift (1)
Learnt from: tobihagemann
PR: cryptomator/ios#386
File: Cryptomator/VaultList/VaultListViewModel.swift:112-112
Timestamp: 2024-10-14T15:45:13.118Z
Learning: In `VaultListViewModel`, use `all(ignoringResult: promises)` instead of `all(promises).then { }` and omit unnecessary logging when refreshing vault lock states.
🔇 Additional comments (1)
Cryptomator/VaultList/VaultListViewModel.swift (1)

107-111: LGTM! Efficient implementation of concurrent vault lock state refresh.

The refactored refreshVaultLockStates method now uses all(ignoringResult: promises) to handle multiple promises concurrently, which is an improvement in efficiency. The implementation aligns with the previous feedback and learnings.

@tobihagemann tobihagemann changed the title Bugix: Missing lock icons in vaults list Bugfix: Missing lock icons in vaults list Oct 16, 2024
@tobihagemann tobihagemann added this to the 2.6.3 milestone Oct 16, 2024
@tobihagemann tobihagemann linked an issue Oct 16, 2024 that may be closed by this pull request
2 tasks
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
Cryptomator/VaultList/VaultCellViewModel.swift (1)

48-48: Approve the direct update of vault unlock status

The change to directly update self.vault.vaultIsUnlocked.value = false in the lockVault() method is a good simplification. It centralizes the responsibility of updating the vault's unlock status and removes the need for a separate setVaultUnlockStatus method.

Consider adding a comment explaining why this update is done here, to improve code readability:

-			self.vault.vaultIsUnlocked.value = false
+			// Update the vault's unlock status after successfully locking it
+			self.vault.vaultIsUnlocked.value = false
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 849b837 and 21a95df.

📒 Files selected for processing (8)
  • Cryptomator/Snapshots/SnapshotCoordinator.swift (0 hunks)
  • Cryptomator/VaultList/VaultCellViewModel.swift (1 hunks)
  • CryptomatorCommon/Sources/CryptomatorCommonCore/FileProviderXPC/VaultLocking.swift (0 hunks)
  • CryptomatorFileProvider/FileProviderAdapterManager.swift (0 hunks)
  • CryptomatorFileProvider/ServiceSource/VaultLockingServiceSource.swift (0 hunks)
  • CryptomatorFileProviderTests/FileProviderAdapterManagerTests.swift (0 hunks)
  • CryptomatorFileProviderTests/Mocks/FileProviderAdapterCacheTypeMock.swift (0 hunks)
  • CryptomatorTests/VaultListViewModelTests.swift (2 hunks)
💤 Files with no reviewable changes (6)
  • Cryptomator/Snapshots/SnapshotCoordinator.swift
  • CryptomatorCommon/Sources/CryptomatorCommonCore/FileProviderXPC/VaultLocking.swift
  • CryptomatorFileProvider/FileProviderAdapterManager.swift
  • CryptomatorFileProvider/ServiceSource/VaultLockingServiceSource.swift
  • CryptomatorFileProviderTests/FileProviderAdapterManagerTests.swift
  • CryptomatorFileProviderTests/Mocks/FileProviderAdapterCacheTypeMock.swift
🚧 Files skipped from review as they are similar to previous changes (1)
  • CryptomatorTests/VaultListViewModelTests.swift
🧰 Additional context used
🔇 Additional comments (2)
Cryptomator/VaultList/VaultCellViewModel.swift (2)

Line range hint 1-67: Clarify the connection between these changes and the missing lock icons

While the changes improve the code by simplifying the update of the vault's unlock status, it's not immediately clear how this directly addresses the issue of missing lock icons in the vaults list (as mentioned in the PR objective).

Could you please clarify:

  1. How does updating self.vault.vaultIsUnlocked.value relate to the display of lock icons?
  2. Are there any UI components that observe this value to update the lock icon visibility?

To help investigate this, please run the following script:


Line range hint 13-18: Verify the impact of removing setVaultUnlockStatus(unlocked: Bool) from the protocol

The setVaultUnlockStatus(unlocked: Bool) method has been removed from the VaultCellViewModelProtocol. This change might affect other parts of the codebase that implement or use this protocol.

Please run the following script to check for any remaining implementations or usages of this method:

✅ Verification successful

Removal of setVaultUnlockStatus(unlocked: Bool) Verified

The removal of setVaultUnlockStatus(unlocked: Bool) from VaultCellViewModelProtocol and VaultCellViewModel has been successfully verified. No remaining implementations or usages were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for implementations or usages of setVaultUnlockStatus method

# Test 1: Search for implementations of setVaultUnlockStatus
echo "Searching for implementations of setVaultUnlockStatus:"
rg --type swift 'func\s+setVaultUnlockStatus'

# Test 2: Search for calls to setVaultUnlockStatus
echo "Searching for calls to setVaultUnlockStatus:"
rg --type swift 'setVaultUnlockStatus\('

# Test 3: Search for references to VaultCellViewModelProtocol
echo "Searching for references to VaultCellViewModelProtocol:"
rg --type swift 'VaultCellViewModelProtocol'

Length of output: 720

@tobihagemann tobihagemann merged commit 840ff2b into develop Oct 16, 2024
4 checks passed
@tobihagemann tobihagemann deleted the bugix/missing-lock-icon branch October 16, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Lock Icon in Vaults Overview Since Update to iOS 17.4
2 participants