Skip to content

feat: simplify target handling to use full paths#12

Merged
screwyprof merged 11 commits intomainfrom
feat/downloads
Dec 23, 2024
Merged

feat: simplify target handling to use full paths#12
screwyprof merged 11 commits intomainfrom
feat/downloads

Conversation

@screwyprof
Copy link
Owner

feat!: simplify target handling to use full paths

This PR simplifies how FavKit handles Finder favorites by treating all user directory items as custom locations with full paths.

BREAKING CHANGE: Desktop and Downloads are now handled as custom locations with full paths instead of special targets with ~ notation.

- Add Desktop as a special Target type alongside Downloads
- Add path detection for user's Desktop folder (/Users/*/Desktop/)
- Display Desktop target as ~/Desktop in sidebar
- Add acceptance test for Desktop folder handling
- Replace custom URL handling with MacOsPath type
- Use standard Rust traits (From, Display) instead of custom methods
- Centralize path detection logic in MacOsPath
- Replace TargetUrl and MacOsPath with a single FavoriteItem type
- Move item-related code to favorites/item.rs
- Improve naming to better reflect domain concepts
- Add MacOsUrl enum to handle all URL types (AirDrop, Recents, Applications, Downloads, Desktop, Custom)
- Move URL constants and path validation logic from FavoriteItem to MacOsUrl
- Implement From<&str> for MacOsUrl for direct URL parsing
- Add helper methods is_user_downloads and is_user_desktop
- Add USER_HOME_FOLDER_DEPTH constant for path validation
- Extract path validation logic into is_inside_home_dir helper method
- Make MacOsUrl public and derive common traits (Debug, Clone, PartialEq, Eq)
- Make constants public for reuse in tests
- Add Display implementation for FavoriteItem
- Add comprehensive test coverage for path validation edge cases
- Use AsRef<str> for more flexible string handling
- Use functional style with Option methods for prefix handling
- Remove redundant is_user_downloads and is_user_desktop helper methods
- Add USER_PREFIX, DOWNLOADS, and DESKTOP constants for better maintainability
- Simplify is_user_folder by removing separate is_inside_home_dir function
- Use direct path component validation instead of string manipulation
- Make path validation more explicit with take(2) and component checks
- Use constants in pattern matching for better readability
- Strip file:// prefix and trailing slash from custom location paths
- Use display name as label for custom locations
- Update tests to verify custom location handling
- Add constants for Projects location in tests
- Remove redundant test case for Documents location

The changes ensure custom locations are displayed in a user-friendly format:
Label -> last part of the URL
Path -> absolute path without file:// prefix and trailing slash
- Move clean_path function to MacOsUrl impl block
- Implement From<Url> instead of From<&str> for MacOsUrl
- Remove duplicate path cleaning logic from Target conversion
- Update tests to use proper URL creation
- Add Target::custom constructor in domain layer
- Update all Target::Custom creations to use the constructor
- Update tests to use the new constructor
- Rename test to better describe what it verifies
- Remove redundant test cases that check the same behavior
- Keep only essential test for deep path recognition
- Remove special Desktop and Downloads targets
- Treat all user directory items as custom locations
- Update tests to reflect simplified target handling
- Remove unused constants and test cases

BREAKING CHANGE: Desktop and Downloads are now handled as custom locations with full paths instead of special targets with ~ notation.
@codecov-commenter
Copy link

codecov-commenter commented Dec 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (8e5817b) to head (c5fd7b3).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##             main       #12      +/-   ##
===========================================
+ Coverage   99.82%   100.00%   +0.17%     
===========================================
  Files          12        12              
  Lines         584       595      +11     
  Branches        3         0       -3     
===========================================
+ Hits          583       595      +12     
+ Partials        1         0       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@screwyprof screwyprof merged commit ac0e996 into main Dec 23, 2024
1 check passed
@screwyprof screwyprof deleted the feat/downloads branch December 23, 2024 00:59
This was referenced Dec 23, 2024
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.

2 participants