@@ -30,6 +30,35 @@ class BrowserModel: ObservableObject {
3030
3131 private let fileManager = FileManager . default
3232
33+ // Helper function to determine if a file could be a media file using UTType
34+ private func isPotentialMediaFile( _ item: FileItem ) -> Bool {
35+ // If we have a UTType, check if it's media-related or if it's nil (unknown)
36+ guard let uti = item. uti else {
37+ // No UTType means the system couldn't identify it - could be a media file without proper extension
38+ return true
39+ }
40+
41+ // Allow known media types
42+ if uti. conforms ( to: . image) || uti. conforms ( to: . movie) || uti. conforms ( to: . audiovisualContent) {
43+ return true
44+ }
45+
46+ // Explicitly exclude known non-media types
47+ if uti. conforms ( to: . sourceCode) ||
48+ uti. conforms ( to: . json) ||
49+ uti. conforms ( to: . xml) ||
50+ uti. conforms ( to: . plainText) ||
51+ uti. conforms ( to: . archive) ||
52+ uti. conforms ( to: . executable) ||
53+ uti. conforms ( to: . application) {
54+ return false
55+ }
56+
57+ // If it's an unknown type that doesn't conform to known non-media types, allow it
58+ // This covers potential media files with unusual extensions or no extensions
59+ return true
60+ }
61+
3362 init ( ) {
3463 let documentsURL = fileManager. urls ( for: . documentDirectory, in: . userDomainMask) . first
3564 let desktopURL = fileManager. urls ( for: . desktopDirectory, in: . userDomainMask) . first
@@ -111,7 +140,18 @@ class BrowserModel: ObservableObject {
111140
112141 fileItems. sort { $0. name. localizedCaseInsensitiveCompare ( $1. name) == . orderedAscending }
113142
114- self . items = fileItems
143+ // Filter to only show directories and potential media files
144+ let filteredItems = fileItems. filter { item in
145+ // Always show directories for navigation
146+ if item. isDirectory {
147+ return true
148+ }
149+
150+ // Show files that could be media files using UTType
151+ return isPotentialMediaFile ( item)
152+ }
153+
154+ self . items = filteredItems
115155 // Prune cache to current directory entries to bound memory usage
116156 let currentURLs = Set ( fileItems. map { $0. url } )
117157 fileItemCache = fileItemCache. filter { currentURLs. contains ( $0. key) }
0 commit comments