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
Put a notice's buttons under its words when they don't fit beside them
Țugui Dragoșe27bcffc0ac4
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swift b/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swiftindex 01250c93..bd6fc282 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swift@@ -6,8 +6,10 @@ public struct ActionRowPlan: Equatable, Sendable {public let frames: [CGRect]public let size: CGSize- /// - Parameter sizes: Each button's own size. What has no width, a group with nothing to show, takes no room.- public init(sizes: [CGSize], width: CGFloat?, spacing: CGFloat = 8, lineSpacing: CGFloat = 6) {+ /// - Parameters:+ /// - sizes: Each button's own size. What has no width, a group with nothing to show, takes no room.+ /// - top: The space above the buttons, left out with them when none shows.+ public init(sizes: [CGSize], width: CGFloat?, spacing: CGFloat = 8, lineSpacing: CGFloat = 6, top: CGFloat = 0) {let shown = sizes.indices.filter { sizes[$0].width > 0 }let needed = shown.reduce(0) { $0 + sizes[$1].width } + spacing * CGFloat(max(shown.count - 1, 0))let room = width.flatMap { $0.isFinite ? $0 : nil } ?? needed@@ -26,7 +28,7 @@ public struct ActionRowPlan: Equatable, Sendable {}var frames = [CGRect](repeating: .zero, count: sizes.count)- var y: CGFloat = 0+ var y = topfor line in lines {let height = line.reduce(0) { max($0, sizes[$1].height) }var x = roomdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swiftindex f6232d28..8a4b0607 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swift@@ -44,6 +44,13 @@ struct ActionRowPlanTests {#expect(ActionRowPlan(sizes: [], width: 400).size.height == 0)}+ @Test func theSpaceAboveTheActionsIsThereOnlyWhileOneShows() {+ let plan = ActionRowPlan(sizes: [small], width: 400, top: 8)+ #expect(plan.frames == [CGRect(x: 300, y: 8, width: 100, height: 28)])+ #expect(plan.size.height == 36)+ #expect(ActionRowPlan(sizes: [.zero], width: 400, top: 8).size.height == 0)+ }+@Test func anActionWiderThanTheRowIsGivenTheWholeRow() {let plan = ActionRowPlan(sizes: [CGSize(width: 500, height: 28)], width: 400)#expect(plan.frames == [CGRect(x: 0, y: 0, width: 400, height: 28)])diff --git a/Peel/Views/ActionRow.swift b/Peel/Views/ActionRow.swiftindex a184b891..3959cf44 100644--- a/Peel/Views/ActionRow.swift+++ b/Peel/Views/ActionRow.swift@@ -3,6 +3,9 @@ import SwiftUI/// Buttons together at the right edge, the last, the page's main action, at the edge itself, as `ActionRowPlan` says.struct ActionRow: Layout {+ /// The space above the buttons, which a row with none to show leaves out too.+ var top: CGFloat = 0+func makeCache(subviews: Subviews) -> [CGSize] {subviews.map { $0.sizeThatFits(.unspecified) }}@@ -26,7 +29,7 @@ struct ActionRow: Layout {guard let width, size.width > width else { return size }return subview.sizeThatFits(ProposedViewSize(width: width, height: nil))}- return ActionRowPlan(sizes: fitted, width: width)+ return ActionRowPlan(sizes: fitted, width: width, top: top)}}diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swiftindex 6eaf5edf..457fda40 100644--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift@@ -176,8 +176,8 @@ struct BackgroundItemDetailView: View {detail: Text("macOS runs it, and only System Settings > General > Login Items & Extensions changes it, so Peel doesn’t start, stop, enable, or disable it here."),kind: .note) {- Button("Open Login Items & Extensions") { SMAppService.openSystemSettingsLoginItems() }Button("Open Extensions") { Navigator.shared.requestedTool = .extensions }+ Button("Open Login Items & Extensions") { SMAppService.openSystemSettingsLoginItems() }}.padding(.vertical, 6)}diff --git a/Peel/Views/MakersUninstallerNotice.swift b/Peel/Views/MakersUninstallerNotice.swiftindex 8ddecae8..0610b067 100644--- a/Peel/Views/MakersUninstallerNotice.swift+++ b/Peel/Views/MakersUninstallerNotice.swift@@ -10,6 +10,7 @@ struct MakersUninstallerNotice: View {var body: some View {Notice(title: Text(Self.title(of: uninstaller)), detail: detail, kind: .note) {+ Link("\(uninstaller.maker)’s Instructions", destination: uninstaller.instructions)switch uninstaller.step {case .command(let command):CopyButton(text: command, title: "Copy Uninstall Command")@@ -21,7 +22,6 @@ struct MakersUninstallerNotice: View {case .onItsDiskImage:EmptyView()}- Link("\(uninstaller.maker)’s Instructions", destination: uninstaller.instructions)}}diff --git a/Peel/Views/Notice.swift b/Peel/Views/Notice.swiftindex 090f43e6..e64d0692 100644--- a/Peel/Views/Notice.swift+++ b/Peel/Views/Notice.swift@@ -25,31 +25,22 @@ struct Notice<Actions: View>: View {var isAlbum = false@ViewBuilder let actions: Actions- /// The narrowest the words may get beside the buttons. With less room, the buttons move under the words,- /// so a narrow column doesn't break a long word in two.- private static var wordsFloor: CGFloat { 200 }-var body: some View {+ // The buttons go beside the words only while each line of them fits there whole, else under them at the right.ViewThatFits(in: .horizontal) {HStack(spacing: 10) {markwords- .frame(- minWidth: Self.wordsFloor,- idealWidth: Self.wordsFloor,- maxWidth: .infinity,- alignment: .leading- )+ Spacer(minLength: 10)buttons}- VStack(alignment: .leading, spacing: 8) {+ VStack(alignment: .leading, spacing: 0) {HStack(alignment: .top, spacing: 10) {markwords.frame(maxWidth: .infinity, alignment: .leading)}- buttons- .padding(.leading, 36)+ ActionRow(top: 8) { buttons }}}.padding(.horizontal, 12)diff --git a/Peel/Views/UnreadableFoldersNotice.swift b/Peel/Views/UnreadableFoldersNotice.swiftindex 74c88cfc..15dc63e3 100644--- a/Peel/Views/UnreadableFoldersNotice.swift+++ b/Peel/Views/UnreadableFoldersNotice.swift@@ -112,15 +112,15 @@ struct UnreadableFoldersActions: View {let needsFullDiskAccess: Boolvar body: some View {+ if folders.count > RemovalFailureAlert.mostListed {+ CopyButton(text: folders.map(\.abbreviatedPath).joined(separator: "\n"), title: "Copy Details")+ }if needsFullDiskAccess {+ Button("Open System Settings") { home.openFullDiskAccessSettings() }// Full Disk Access applies only to a new process, so once it may have been given, Peel offers to reopen.if home.needsRelaunchForFullDiskAccess {Button("Reopen Peel") { home.relaunch() }}- Button("Open System Settings") { home.openFullDiskAccessSettings() }- }- if folders.count > RemovalFailureAlert.mostListed {- CopyButton(text: folders.map(\.abbreviatedPath).joined(separator: "\n"), title: "Copy Details")}}}diff --git a/Peel/Views/UpdatePanel.swift b/Peel/Views/UpdatePanel.swiftindex f56cc6ed..cf5c9afe 100644--- a/Peel/Views/UpdatePanel.swift+++ b/Peel/Views/UpdatePanel.swift@@ -10,9 +10,6 @@ struct UpdatePanel<Detail: View, Action: View>: View {@ViewBuilder let detail: Detail@ViewBuilder let action: Action- /// The narrowest the words may get beside the button. With less room, the button moves under the words.- private static var wordsFloor: CGFloat { 200 }-var body: some View {HStack(alignment: .words, spacing: 12) {mark@@ -20,17 +17,12 @@ struct UpdatePanel<Detail: View, Action: View>: View {ViewThatFits(in: .horizontal) {HStack(spacing: 12) {words- .frame(- minWidth: Self.wordsFloor,- idealWidth: Self.wordsFloor,- maxWidth: .infinity,- alignment: .leading- )+ Spacer(minLength: 12)action}- VStack(alignment: .leading, spacing: 10) {+ VStack(alignment: .leading, spacing: 0) {words- action+ ActionRow(top: 10) { action }}.frame(maxWidth: .infinity, alignment: .leading)}diff --git a/PeelTests/NoticeLayoutTests.swift b/PeelTests/NoticeLayoutTests.swiftnew file mode 100644index 00000000..67378d01--- /dev/null+++ b/PeelTests/NoticeLayoutTests.swift@@ -0,0 +1,113 @@+import AppKit+@testable import Peel+import SwiftUI+import Testing++@MainActor+private final class Frames {+ var panel = CGRect.zero+ var buttons: [String: CGRect] = [:]+}++private extension View {+ func measured(into frames: Frames) -> some View {+ onGeometryChange(for: CGRect.self) { $0.frame(in: .named("page")) } action: { frames.panel = $0 }+ .coordinateSpace(.named("page"))+ }+}++@MainActor+private func button(_ title: String, into frames: Frames) -> some View {+ Button(title) {}+ .onGeometryChange(for: CGRect.self) { $0.frame(in: .named("page")) } action: { frames.buttons[title] = $0 }+}++@MainActor+private func laidOut(_ view: some View, width: CGFloat, frames: Frames, buttons: Int) async -> Frames {+ let window = NSWindow(+ contentRect: NSRect(x: 0, y: 0, width: width, height: 600), styleMask: [.titled],+ backing: .buffered, defer: true+ )+ window.contentView = NSHostingView(rootView: view.frame(width: width))+ for _ in 0..<200 where frames.buttons.count < buttons || frames.panel.isEmpty {+ window.layoutIfNeeded()+ try? await Task.sleep(for: .milliseconds(5))+ }+ return frames+}++private let paragraph = "Peel couldn’t look inside /Library/Bluetooth, /Library/Trial and 16 more folders, so something "+ + "may be there that isn’t listed here. Give Peel Full Disk Access so it can read the folders macOS protects."++@MainActor+struct NoticeLayoutTests {+ private func notice(_ detail: String, width: CGFloat) async -> Frames {+ let frames = Frames()+ let view = Notice(title: Text(verbatim: "Some folders couldn’t be read"), detail: Text(verbatim: detail)) {+ button("Open System Settings", into: frames)+ button("Reopen Peel", into: frames)+ }+ .measured(into: frames)+ return await laidOut(view, width: width, frames: frames, buttons: 2)+ }++ @Test func inANarrowColumnTheButtonsShareOneLineAtTheRightEdge() async throws {+ let frames = await notice(+ "Peel couldn’t look inside /Library/Bluetooth and 16 more folders, so something may be there that isn’t listed.",+ width: 340+ )+ let settings = try #require(frames.buttons["Open System Settings"])+ let reopen = try #require(frames.buttons["Reopen Peel"])++ #expect(settings.minY == reopen.minY)+ #expect(settings.maxX < reopen.minX)+ #expect(abs(reopen.maxX - (frames.panel.maxX - 12)) < 1)+ }++ @Test func underALongTextTheButtonsStandBelowIt() async throws {+ let frames = await notice([paragraph, paragraph, paragraph].joined(separator: "\n\n"), width: 900)+ let settings = try #require(frames.buttons["Open System Settings"])+ let reopen = try #require(frames.buttons["Reopen Peel"])++ #expect(settings.minY == reopen.minY)+ #expect(abs(reopen.maxY - (frames.panel.maxY - 8)) < 1)+ #expect(abs(reopen.maxX - (frames.panel.maxX - 12)) < 1)+ }++ @Test func aShortNoticeKeepsItsButtonsBesideItsWords() async throws {+ let frames = await notice("Give Peel Full Disk Access.", width: 900)+ let reopen = try #require(frames.buttons["Reopen Peel"])++ #expect(reopen.height > frames.panel.height / 2)+ #expect(abs(reopen.maxX - (frames.panel.maxX - 12)) < 1)+ }+}++@MainActor+struct UpdatePanelLayoutTests {+ private func panel(_ detail: String, width: CGFloat) async -> Frames {+ let frames = Frames()+ let view = UpdatePanel(version: "2.0", notes: nil, link: nil) {+ Text(verbatim: detail)+ } action: {+ button("Open Tidewater", into: frames)+ }+ .measured(into: frames)+ return await laidOut(view, width: width, frames: frames, buttons: 1)+ }++ @Test func inANarrowColumnTheButtonStandsAtTheRightEdge() async throws {+ let frames = await panel("Tidewater updates itself. Open it and choose Check for Updates in its menu.", width: 340)+ let open = try #require(frames.buttons["Open Tidewater"])++ #expect(abs(open.maxX - (frames.panel.maxX - 12)) < 1)+ }++ @Test func underALongTextTheButtonStandsBelowIt() async throws {+ let frames = await panel(paragraph, width: 900)+ let open = try #require(frames.buttons["Open Tidewater"])++ #expect(abs(open.maxY - (frames.panel.maxY - 12)) < 1)+ #expect(abs(open.maxX - (frames.panel.maxX - 12)) < 1)+ }+}