Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Take Peel's own icon out of the Dock when it removes itself

Țugui Dragoș86d1565e6503
diff --git a/GUIDE.md b/GUIDE.md
index 4df8d70e..12cc7b17 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -252,8 +252,8 @@ it.
In Settings > General, choose Remove Peel. It has its helper move its record of what it moved to the Trash, removes
its helper and its login item, moves itself, the files that are certainly its own, and its folder in Application
-Support to the Trash, clears its settings, and quits. That
-folder holds History, your exclusions, and the settings Peel saved when you reset an app.
+Support to the Trash, takes its icon out of the Dock, clears its settings, and quits. That folder holds History, your
+exclusions, and the settings Peel saved when you reset an app.
What Peel changed for you stays as it is: tweaks, Terminal's theme and its options, `~/.hushlogin`, Git's
settings, the build folders you left out of Time Machine, and the background items you disabled. Turn them off
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swift b/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swift
index ce2b6198..abdda624 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swift
@@ -58,8 +58,9 @@ public struct DockTiles: Sendable {
}
/// Takes the tiles of `apps` out of the Dock, remembering where each was, and restarts the Dock once. False
- /// when none had a tile, or when that could not be remembered or written.
- public func takeOut(_ apps: [URL]) async -> Bool {
+ /// when none had a tile, or when that could not be remembered or written. Peel removing itself remembers nothing,
+ /// since its folder, where the memory is kept, has gone to the Trash.
+ public func takeOut(_ apps: [URL], remembering: Bool = true) async -> Bool {
guard var tiles = store.tiles() else { return false }
var removed: [String: [Removed]] = [:]
for app in apps {
@@ -70,11 +71,13 @@ public struct DockTiles: Sendable {
}
if !found.isEmpty, kept.count == found.count { removed[key(app)] = kept }
}
- guard !removed.isEmpty, change({ $0.merge(removed) { _, new in new } }) else { return false }
+ guard !removed.isEmpty, !remembering || change({ $0.merge(removed) { _, new in new } }) else { return false }
let taken = Set(removed.values.flatMap { $0.map(\.index) })
tiles = tiles.indices.filter { !taken.contains($0) }.map { tiles[$0] }
guard store.setTiles(tiles) else {
- _ = change { entries in removed.keys.forEach { entries[$0] = nil } }
+ if remembering {
+ _ = change { entries in removed.keys.forEach { entries[$0] = nil } }
+ }
return false
}
await store.restartTheDock()
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swift
index 75c8b9b2..d55f1e9d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swift
@@ -70,6 +70,18 @@ struct DockTilesTests {
#expect(store.paths.count == 4, "a tile was put back twice")
}
+ @Test func takesOutATileWithoutRememberingItInAFolderThatIsGone() async throws {
+ let directory = try TemporaryDirectory()
+ let store = Store([Self.tile("file:///Applications/org.example.Studio.app/")])
+ let folder = directory.url.appending(path: "Peel", directoryHint: .isDirectory)
+ let tiles = DockTiles(store: store, memory: folder.appending(path: "dock-tiles.json"))
+
+ #expect(await tiles.takeOut([studio], remembering: false))
+ #expect(store.paths.isEmpty)
+ #expect(store.restarts.load(ordering: .relaxed) == 1)
+ #expect(folder.isMissing)
+ }
+
/// Several apps removed together restart the Dock once, and each comes back to its own place.
@Test func takesOutSeveralAppsTilesWithOneRestart() async throws {
let directory = try TemporaryDirectory()
diff --git a/Peel/Model/SelfUninstall.swift b/Peel/Model/SelfUninstall.swift
index 0e05939b..50513b8f 100644
--- a/Peel/Model/SelfUninstall.swift
+++ b/Peel/Model/SelfUninstall.swift
@@ -90,6 +90,7 @@ final class SelfUninstall {
failure = (lines + (ledger == .moved ? [Self.ledgerInTheTrash] : [])).joined(separator: "\n\n")
return
}
+ _ = await DockTiles().takeOut([bundleURL], remembering: false)
var stayed = result.failures
if case .stayed(let failure) = ledger {
stayed.append(failure)