Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
A peel://open link moves Peel's page only for a real app
Țugui Dragoș90355f929719
diff --git a/Packages/PeelCore/Sources/PeelLink/OpenRequest.swift b/Packages/PeelCore/Sources/PeelLink/OpenRequest.swiftindex 230f4523..b22537c6 100644--- a/Packages/PeelCore/Sources/PeelLink/OpenRequest.swift+++ b/Packages/PeelCore/Sources/PeelLink/OpenRequest.swift@@ -22,11 +22,15 @@ public enum OpenRequest {if url.isFileURL {return url.pathExtension == "app" ? url : nil}+ // A scheme and a host are case insensitive (RFC 3986), and macOS hands Peel the link however they are+ // written. Any app or web page can send one, so a path a control character would make read as another+ // is refused.guard- url.scheme == "peel",- url.host() == "open",+ url.scheme?.lowercased() == "peel",+ url.host()?.lowercased() == "open",let path = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.first(where: { $0.name == "path" })?.value,- path.hasPrefix("/")+ path.hasPrefix("/"),+ !path.unicodeScalars.contains(where: { $0.properties.generalCategory == .control })else { return nil }// The extension is read from a URL, not from the string: a bundle is a folder, and every sender of this// link writes its path with a trailing slash.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OpenRequestTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OpenRequestTests.swiftindex b58eca92..e3f3c163 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/OpenRequestTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/OpenRequestTests.swift@@ -39,6 +39,22 @@ struct OpenRequestTests {#expect(OpenRequest.applicationURL(from: URL(filePath: "/Users/x/Documents/notes.txt")) == nil)}+ /// macOS hands Peel a link whatever the case of its scheme and host, which RFC 3986 says are case insensitive.+ @Test func opensALinkWhateverTheCaseOfItsSchemeAndHost() throws {+ for text in ["PEEL://open?path=/Applications/Foo.app", "Peel://OPEN?path=/Applications/Foo.app"] {+ let link = try #require(URL(string: text))+ let opened = try #require(OpenRequest.applicationURL(from: link), "\(text) was refused")+ #expect(opened.lastPathComponent == "Foo.app")+ }+ }++ @Test func refusesALinkWhosePathHoldsAControlCharacter() throws {+ for name in ["Foo\n.app", "Fo\u{7F}o.app", "Foo\u{0}.app", "Foo\u{85}.app"] {+ let app = URL(filePath: "/Users/x/Downloads/\(name)", directoryHint: .isDirectory)+ #expect(OpenRequest.applicationURL(from: try link(for: app)) == nil, "\(name.debugDescription) was opened")+ }+ }+@Test func theFinderMenuIsForExactlyOneApp() {let app = URL(filePath: "/Applications/Foo.app", directoryHint: .isDirectory)let other = URL(filePath: "/Applications/Bar.app", directoryHint: .isDirectory)diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swiftindex 5bb004a9..22876ac0 100644--- a/Peel/Model/AppLibrary.swift+++ b/Peel/Model/AppLibrary.swift@@ -728,16 +728,18 @@ final class AppLibrary {}/// Selects the apps together, adding each first when it lives outside the scanned folders, for example in- /// the Trash. What is not an app is passed over.- func reveal(_ urls: [URL]) async {+ /// the Trash. What is not an app is passed over, and false means none was.+ @discardableResult+ func reveal(_ urls: [URL]) async -> Bool {var chosen: Set<InstalledApp.ID> = []for url in urls {if let id = await listed(url) {chosen.insert(id)}}- guard !chosen.isEmpty else { return }+ guard !chosen.isEmpty else { return false }selection = chosen+ return true}private func listed(_ url: URL) async -> InstalledApp.ID? {diff --git a/Peel/Views/ContentView.swift b/Peel/Views/ContentView.swiftindex 93b24d5c..c68f05e5 100644--- a/Peel/Views/ContentView.swift+++ b/Peel/Views/ContentView.swift@@ -127,10 +127,14 @@ struct ContentView: View {.quietTitlebarSeparators().measuresFrames().focusedSceneValue(\.selectedTool, shownTool)+ // The page changes only for a bundle that is an app, since any app or web page can send the link..onOpenURL { url inguard let applicationURL = OpenRequest.applicationURL(from: url) else { return }- show(.applications)- Task { await library.reveal([applicationURL]) }+ Task {+ if await library.reveal([applicationURL]) {+ show(.applications)+ }+ }}// A request made while the window was closed (from a Shortcut, the Finder extension, or the menu bar// panel) is already set when this view appears, and `onChange` only fires on a change, so anything