Skip to content

Commit 11015cc

Browse files
- Implemented Trash filtering
1 parent 2d8ddd9 commit 11015cc

4 files changed

Lines changed: 52 additions & 50 deletions

File tree

Example/WelcomeWindowExample.xcodeproj/project.pbxproj

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
5ED3B5C72DE7490600F6DB0B /* WelcomeWindow in Frameworks */ = {isa = PBXBuildFile; productRef = 5ED3B5C62DE7490600F6DB0B /* WelcomeWindow */; };
10+
5EACE6612DF4D56C005E08B8 /* WelcomeWindow in Frameworks */ = {isa = PBXBuildFile; productRef = 5EACE6602DF4D56C005E08B8 /* WelcomeWindow */; };
1111
/* End PBXBuildFile section */
1212

1313
/* Begin PBXFileReference section */
14+
5EACE65F2DF4D569005E08B8 /* WelcomeWindow */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = WelcomeWindow; path = ..; sourceTree = "<group>"; };
1415
5ED3AEFA2DE72A2800F6DB0B /* WelcomeWindowExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WelcomeWindowExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
15-
5ED3B5B22DE747D400F6DB0B /* WelcomeWindow */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = WelcomeWindow; path = ..; sourceTree = "<group>"; };
1616
/* End PBXFileReference section */
1717

1818
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
@@ -41,18 +41,26 @@
4141
isa = PBXFrameworksBuildPhase;
4242
buildActionMask = 2147483647;
4343
files = (
44-
5ED3B5C72DE7490600F6DB0B /* WelcomeWindow in Frameworks */,
44+
5EACE6612DF4D56C005E08B8 /* WelcomeWindow in Frameworks */,
4545
);
4646
runOnlyForDeploymentPostprocessing = 0;
4747
};
4848
/* End PBXFrameworksBuildPhase section */
4949

5050
/* Begin PBXGroup section */
51+
5EACE65E2DF4D569005E08B8 /* Frameworks */ = {
52+
isa = PBXGroup;
53+
children = (
54+
5EACE65F2DF4D569005E08B8 /* WelcomeWindow */,
55+
);
56+
name = Frameworks;
57+
sourceTree = "<group>";
58+
};
5159
5ED3AEF12DE72A2800F6DB0B = {
5260
isa = PBXGroup;
5361
children = (
5462
5ED3AEFC2DE72A2800F6DB0B /* WelcomeWindowExample */,
55-
5ED3B5B12DE747D400F6DB0B /* Frameworks */,
63+
5EACE65E2DF4D569005E08B8 /* Frameworks */,
5664
5ED3AEFB2DE72A2800F6DB0B /* Products */,
5765
);
5866
sourceTree = "<group>";
@@ -65,14 +73,6 @@
6573
name = Products;
6674
sourceTree = "<group>";
6775
};
68-
5ED3B5B12DE747D400F6DB0B /* Frameworks */ = {
69-
isa = PBXGroup;
70-
children = (
71-
5ED3B5B22DE747D400F6DB0B /* WelcomeWindow */,
72-
);
73-
name = Frameworks;
74-
sourceTree = "<group>";
75-
};
7676
/* End PBXGroup section */
7777

7878
/* Begin PBXNativeTarget section */
@@ -94,7 +94,7 @@
9494
);
9595
name = WelcomeWindowExample;
9696
packageProductDependencies = (
97-
5ED3B5C62DE7490600F6DB0B /* WelcomeWindow */,
97+
5EACE6602DF4D56C005E08B8 /* WelcomeWindow */,
9898
);
9999
productName = WelcomeWindowExample;
100100
productReference = 5ED3AEFA2DE72A2800F6DB0B /* WelcomeWindowExample.app */;
@@ -293,12 +293,12 @@
293293
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
294294
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
295295
CODE_SIGN_ENTITLEMENTS = WelcomeWindowExample/WelcomeWindowExample.entitlements;
296-
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
296+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
297297
CODE_SIGN_STYLE = Automatic;
298298
COMBINE_HIDPI_IMAGES = YES;
299299
CURRENT_PROJECT_VERSION = 1;
300300
DEAD_CODE_STRIPPING = YES;
301-
DEVELOPMENT_TEAM = HG8TU44368;
301+
DEVELOPMENT_TEAM = "";
302302
ENABLE_HARDENED_RUNTIME = YES;
303303
ENABLE_PREVIEWS = YES;
304304
GENERATE_INFOPLIST_FILE = YES;
@@ -325,12 +325,12 @@
325325
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
326326
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
327327
CODE_SIGN_ENTITLEMENTS = WelcomeWindowExample/WelcomeWindowExample.entitlements;
328-
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
328+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
329329
CODE_SIGN_STYLE = Automatic;
330330
COMBINE_HIDPI_IMAGES = YES;
331331
CURRENT_PROJECT_VERSION = 1;
332332
DEAD_CODE_STRIPPING = YES;
333-
DEVELOPMENT_TEAM = HG8TU44368;
333+
DEVELOPMENT_TEAM = "";
334334
ENABLE_HARDENED_RUNTIME = YES;
335335
ENABLE_PREVIEWS = YES;
336336
GENERATE_INFOPLIST_FILE = YES;
@@ -386,7 +386,7 @@
386386
/* End XCRemoteSwiftPackageReference section */
387387

388388
/* Begin XCSwiftPackageProductDependency section */
389-
5ED3B5C62DE7490600F6DB0B /* WelcomeWindow */ = {
389+
5EACE6602DF4D56C005E08B8 /* WelcomeWindow */ = {
390390
isa = XCSwiftPackageProductDependency;
391391
productName = WelcomeWindow;
392392
};

Example/WelcomeWindowExample/WelcomeWindowExampleApp.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ struct WelcomeWindowExampleApp: App {
1717
var body: some Scene {
1818
Group {
1919
WelcomeWindow(
20-
title: "Welcome to SwiftUI!",
21-
subtitleView: { Text("Custom subtitle") },
2220
actions: { dismiss in
2321
WelcomeButton(
2422
iconName: "circle.fill",

Sources/WelcomeWindow/Model/RecentsStore.swift

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public enum RecentsStore {
1111
/// Notification sent when the recent projects list is updated.
1212
public static let didUpdateNotification = Notification.Name("RecentsStore.didUpdate")
1313

14-
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "", category: "RecentsStore")
15-
1614
/// Internal representation of a bookmark entry.
1715
private struct BookmarkEntry: Codable, Equatable {
1816
/// The standardized file path of the bookmarked URL.
@@ -37,24 +35,26 @@ public enum RecentsStore {
3735
}
3836
}
3937

38+
private static let logger = Logger(
39+
subsystem: Bundle.main.bundleIdentifier ?? "com.example.app",
40+
category: "RecentsStore"
41+
)
42+
4043
// MARK: - Public API
4144

4245
/// Returns an array of all recent project URLs resolved from stored bookmarks.
4346
///
4447
/// - Returns: An array of `URL` representing the recent projects.
4548
public static func recentProjectURLs() -> [URL] {
46-
filterURLs(by: { url in
47-
(try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
48-
})
49-
}
50-
51-
/// Returns an array of all recent single file URLs resolved from stored bookmarks.
52-
///
53-
/// - Returns: An array of `URL` representing the recent files.
54-
public static func recentFileURLs() -> [URL] {
55-
filterURLs(by: { url in
56-
!((try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false)
57-
})
49+
var seen = Set<String>()
50+
return loadBookmarks().compactMap { entry in
51+
guard let resolved = entry.url else { return nil }
52+
guard !isInTrash(resolved) else { return nil }
53+
let path = resolved.standardized.path
54+
guard !seen.contains(path) else { return nil }
55+
seen.insert(path)
56+
return resolved
57+
}
5858
}
5959

6060
/// Notifies the store that a project was opened.
@@ -76,9 +76,8 @@ public enum RecentsStore {
7676
bookmarks.insert(BookmarkEntry(urlPath: standardizedPath, bookmarkData: bookmark), at: 0)
7777

7878
saveBookmarks(Array(bookmarks.prefix(100)))
79-
donateSearchableItems()
8079
} catch {
81-
logger.error("❌ Failed to create bookmark for recent project: \(error.localizedDescription)")
80+
print("❌ Failed to create bookmark for recent project: \(error)")
8281
}
8382
}
8483

@@ -126,14 +125,26 @@ public enum RecentsStore {
126125
private static func filterURLs(by filter: (URL) -> Bool) -> [URL] {
127126
var seen = Set<String>()
128127
return loadBookmarks().compactMap { entry in
129-
guard let resolved = entry.url, filter(resolved) else { return nil }
128+
guard let resolved = entry.url,
129+
!isInTrash(resolved),
130+
filter(resolved)
131+
else { return nil }
132+
130133
let path = resolved.standardized.path
131134
guard !seen.contains(path) else { return nil }
132135
seen.insert(path)
133136
return resolved
134137
}
135138
}
136139

140+
/// Returns `true` when the url resides in a macOS Trash folder.
141+
private static func isInTrash(_ url: URL) -> Bool {
142+
let comps = url.standardized.pathComponents
143+
// ~/.Trash/... → ".Trash"
144+
// /Volumes/Disk/.Trashes/501/... → ".Trashes"
145+
return comps.contains(".Trash") || comps.contains(".Trashes")
146+
}
147+
137148
/// Loads the stored bookmarks from UserDefaults.
138149
///
139150
/// - Returns: An array of `BookmarkEntry` values decoded from UserDefaults.

Sources/WelcomeWindow/Views/RecentsListView.swift

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,12 @@ public struct RecentsListView: View {
8484
removeRecentProjects()
8585
}
8686
.background {
87-
ZStack {
88-
if colorScheme == .dark {
89-
Color(.black).opacity(0.075)
90-
.background(.thickMaterial)
91-
} else {
92-
Color(.white).opacity(0.6)
93-
.background(.regularMaterial)
94-
}
95-
Color.clear
96-
.contentShape(Rectangle())
97-
.onTapGesture {
98-
selection.removeAll()
99-
}
87+
if colorScheme == .dark {
88+
Color(.black).opacity(0.075)
89+
.background(.thickMaterial)
90+
} else {
91+
Color(.white).opacity(0.6)
92+
.background(.regularMaterial)
10093
}
10194
}
10295
.background {

0 commit comments

Comments
 (0)