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.

Tell to restart when an audio driver moved to the Trash

Țugui Dragoșa2a27199cba9
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 26a83563..e30aa515 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -126977,6 +126977,112 @@
}
}
},
+ "Restart your Mac to finish." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Chcete-li odstranění dokončit, restartujte Mac."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Starte deinen Mac neu, um das Entfernen abzuschließen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Reinicia el Mac para terminar."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Redémarrez votre Mac pour terminer la suppression."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Riavvia il Mac per completare la rimozione."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "完了するにはMacを再起動してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "제거를 완료하려면 Mac을 재시동하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Start je Mac opnieuw op om de verwijdering te voltooien."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aby zakończyć, uruchom ponownie Maca."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Reinicie o Mac para concluir."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Reporniți Mac‑ul pentru a încheia eliminarea."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Чтобы завершить удаление, перезагрузите Mac."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Starta om datorn för att slutföra borttagningen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kaldırma işlemini tamamlamak için Mac’inizi yeniden başlatın."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Перезапустіть Mac, щоб завершити вилучення."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "重新启动你的Mac以完成移除。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "請將Mac重新開機以完成移除。"
+ }
+ }
+ }
+ },
"Restarts itself" : {
"localizations" : {
"cs" : {
@@ -198834,6 +198940,218 @@
}
}
},
+ "macOS keeps the audio driver %@ running until you restart your Mac." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Systém macOS ponechá zvukový ovladač %@ spuštěný, dokud nerestartujete Mac."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS lässt den Audiotreiber „%@“ weiterlaufen, bis du deinen Mac neu startest."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS mantiene en ejecución el driver de audio %@ hasta que reinicies el Mac."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS continue d’exécuter le gestionnaire audio %@ jusqu’à ce que vous redémarriez votre Mac."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS mantiene in esecuzione il driver audio %@ finché non riavvii il Mac."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Macを再起動するまで、macOSはオーディオドライバ“%@”を実行し続けます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mac을 재시동할 때까지 macOS가 ‘%@’ 오디오 드라이버를 계속 실행합니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS houdt het audiobesturingsbestand %@ actief totdat je je Mac opnieuw opstart."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS utrzymuje działanie sterownika audio %@, dopóki nie uruchomisz ponownie Maca."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O macOS mantém o driver de áudio %@ em execução até você reiniciar o Mac."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS continuă să ruleze driverul audio %@ până când reporniți Mac‑ul."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Аудиодрайвер «%@» продолжит работать в macOS, пока Вы не перезагрузите Mac."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS håller ljuddrivrutinen %@ igång tills du startar om datorn."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS, %@ ses sürücüsünü Mac’iniz yeniden başlatılana kadar çalışır durumda tutar."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS залишає запущеним аудіодрайвер «%@», доки ви не перезапустите Mac."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS会让音频驱动程序“%@”保持运行,直到你重新启动Mac。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS會讓音訊驅動程式「%@」繼續執行,直到你將Mac重新開機。"
+ }
+ }
+ }
+ },
+ "macOS keeps the audio drivers %@ running until you restart your Mac." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Systém macOS ponechá zvukové ovladače %@ spuštěné, dokud nerestartujete Mac."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS lässt die Audiotreiber %@ weiterlaufen, bis du deinen Mac neu startest."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS mantiene en ejecución los drivers de audio %@ hasta que reinicies el Mac."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS continue d’exécuter les gestionnaires audio %@ jusqu’à ce que vous redémarriez votre Mac."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS mantiene in esecuzione i driver audio %@ finché non riavvii il Mac."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Macを再起動するまで、macOSはオーディオドライバ%@を実行し続けます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mac을 재시동할 때까지 macOS가 %@ 오디오 드라이버를 계속 실행합니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS houdt de audiobesturingsbestanden %@ actief totdat je je Mac opnieuw opstart."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS utrzymuje działanie sterowników audio %@, dopóki nie uruchomisz ponownie Maca."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O macOS mantém os drivers de áudio %@ em execução até você reiniciar o Mac."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS continuă să ruleze driverele audio %@ până când reporniți Mac‑ul."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Аудиодрайверы %@ продолжат работать в macOS, пока Вы не перезагрузите Mac."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS håller ljuddrivrutinerna %@ igång tills du startar om datorn."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS, %@ ses sürücülerini Mac’iniz yeniden başlatılana kadar çalışır durumda tutar."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS залишає запущеними аудіодрайвери %@, доки ви не перезапустите Mac."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS会让音频驱动程序“%@”保持运行,直到你重新启动Mac。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS會讓音訊驅動程式%@繼續執行,直到你將Mac重新開機。"
+ }
+ }
+ }
+ },
"macOS keeps this app, so it stays where it is." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/AudioDrivers.swift b/Packages/PeelCore/Sources/PeelCore/Removal/AudioDrivers.swift
new file mode 100644
index 00000000..fc4e856c
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/AudioDrivers.swift
@@ -0,0 +1,21 @@
+public import Foundation
+internal import PeelPrivileged
+
+/// The audio drivers a removal took from the folder macOS loads them from, a `.driver` bundle in
+/// `/Library/Audio/Plug-Ins/HAL` (`AudioServerPlugIn.h`). The audio server keeps one it loaded until it starts again,
+/// which a restart of the Mac does.
+public enum AudioDrivers {
+ public static func awaitingARestart(
+ after result: TrashResult,
+ root: URL = URL(filePath: "/", directoryHint: .isDirectory)
+ ) -> [String] {
+ let library = root.appending(path: "Library", directoryHint: .isDirectory)
+ let folder = PathPattern.comparablePath(
+ of: library.appending(path: LibraryFolder.audioDrivers.rawValue, directoryHint: .isDirectory)
+ )
+ return result.trashed.map(\.originalURL).filter { url in
+ url.pathExtension.caseInsensitiveCompare("driver") == .orderedSame
+ && PathPattern.comparablePath(of: url.deletingLastPathComponent()) == folder
+ }.map { $0.deletingPathExtension().lastPathComponent }
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AudioDriversTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AudioDriversTests.swift
new file mode 100644
index 00000000..55b35c6f
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AudioDriversTests.swift
@@ -0,0 +1,19 @@
+import Foundation
+@testable import PeelCore
+import Testing
+
+struct AudioDriversTests {
+ @Test func namesTheDriversARemovalTookFromTheFolderMacOSLoadsThemFrom() {
+ let root = URL(filePath: "/private/tmp/org.example.root", directoryHint: .isDirectory)
+ let moved = [
+ "Library/Audio/Plug-Ins/HAL/BlackHole2ch.driver",
+ "Library/Audio/Plug-Ins/Components/Example.component",
+ "Library/Audio/Plug-Ins/HAL/notes.txt",
+ "Users/me/Library/Audio/Plug-Ins/HAL/Personal.driver",
+ ].map { path in
+ TrashedItem(originalURL: root.appending(path: path), trashedURL: root.appending(path: ".Trash/x"), date: .now)
+ }
+
+ #expect(AudioDrivers.awaitingARestart(after: TrashResult(trashed: moved), root: root) == ["BlackHole2ch"])
+ }
+}
diff --git a/Peel/Model/RemovalOutcome.swift b/Peel/Model/RemovalOutcome.swift
index dfc7c3ea..098eda8b 100644
--- a/Peel/Model/RemovalOutcome.swift
+++ b/Peel/Model/RemovalOutcome.swift
@@ -2,8 +2,8 @@ import Foundation
import Observation
import PeelCore
-/// What a removal could not do, held by the app rather than by the page that asked. Removing an app closes its
-/// page, and an alert owned by that page would close with it.
+/// What a removal could not do, or left for a restart to finish, held by the app rather than by the page that asked.
+/// Removing an app closes its page, and an alert owned by that page would close with it.
@Observable
final class RemovalOutcome {
/// What came of one app's privacy reset.
@@ -19,12 +19,15 @@ final class RemovalOutcome {
private(set) var appsToQuit: [String] = []
/// The apps that stayed while files of their own were selected, which stayed with them.
private(set) var keptTheirFiles: [String] = []
+ /// The audio drivers that moved, which macOS keeps running until the Mac restarts.
+ private(set) var driversAwaitingARestart: [String] = []
private(set) var movedCount = 0
- var isEmpty: Bool { failures.isEmpty && privacy.isEmpty && appsToQuit.isEmpty }
+ var isEmpty: Bool { failures.isEmpty && privacy.isEmpty && appsToQuit.isEmpty && driversAwaitingARestart.isEmpty }
- /// Keeps what the removal could not do, for the alert. `privacy` is every reset the removal ran, and
- /// `PrivacyReset.worthTelling` picks which of them to tell. A removal with nothing to tell changes nothing.
+ /// Keeps what the removal could not do, and the audio drivers a restart finishes removing, for the alert.
+ /// `privacy` is every reset the removal ran, and `PrivacyReset.worthTelling` picks which of them to tell. A
+ /// removal with nothing to tell changes nothing.
func report(
_ result: TrashResult,
privacy resets: [(app: InstalledApp, result: PrivacyReset.Result)] = [],
@@ -34,12 +37,14 @@ final class RemovalOutcome {
let privacy = PrivacyReset.worthTelling(resets, after: result).map {
Privacy(app: $0.app.name, result: $0.result)
}
- guard !result.failures.isEmpty || !privacy.isEmpty || !appsToQuit.isEmpty else { return }
+ let drivers = AudioDrivers.awaitingARestart(after: result)
+ guard !result.failures.isEmpty || !privacy.isEmpty || !appsToQuit.isEmpty || !drivers.isEmpty else { return }
failures = result.failures
movedCount = result.trashed.count
self.privacy = privacy
self.appsToQuit = appsToQuit
self.keptTheirFiles = keptTheirFiles
+ driversAwaitingARestart = drivers
}
func clear() {
@@ -48,5 +53,6 @@ final class RemovalOutcome {
privacy = []
appsToQuit = []
keptTheirFiles = []
+ driversAwaitingARestart = []
}
}
diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swift
index 3cbb202e..a5c35f62 100644
--- a/Peel/Views/RemovalFailureAlert.swift
+++ b/Peel/Views/RemovalFailureAlert.swift
@@ -3,8 +3,8 @@ import PeelCore
import SwiftUI
/// The alert every tool shows when a removal fails for some items: which ones, and why, with a button that
-/// fixes the cause when there is one. It also reports the privacy resets worth telling about, since two
-/// alerts cannot be up at once.
+/// fixes the cause when there is one. It also reports the privacy resets worth telling about, and the audio drivers
+/// that wait for a restart, since two alerts cannot be up at once.
struct RemovalFailureAlert: ViewModifier {
/// How many items the alert lists by path. The rest are only counted, to keep the alert short.
static let mostListed = 4
@@ -40,6 +40,9 @@ struct RemovalFailureAlert: ViewModifier {
}
private var title: Text {
+ if outcome.failures.isEmpty, outcome.appsToQuit.isEmpty, outcome.privacy.isEmpty {
+ return Text("Restart your Mac to finish.")
+ }
if outcome.failures.isEmpty, outcome.appsToQuit.isEmpty {
return outcome.privacy.count == 1 ? Text("Privacy permissions weren’t reset.") : Text("Some privacy permissions weren’t reset.")
}
@@ -53,10 +56,19 @@ struct RemovalFailureAlert: ViewModifier {
if rest > 0 {
lines.append(String(inflecting: "And ^[\(rest) more item](inflect: true)."))
}
- lines += keptLines + extraLines
+ lines += keptLines + driverLines + extraLines
return lines.joined(separator: "\n\n")
}
+ private var driverLines: [String] {
+ let drivers = outcome.driversAwaitingARestart
+ guard !drivers.isEmpty else { return [] }
+ let names = drivers.formatted(.list(type: .and))
+ return drivers.count == 1
+ ? [String(localized: "macOS keeps the audio driver \(names) running until you restart your Mac.")]
+ : [String(localized: "macOS keeps the audio drivers \(names) running until you restart your Mac.")]
+ }
+
/// A line for each app that stayed, since its files, which wait for it, stayed too and are not listed.
private var keptLines: [String] {
outcome.keptTheirFiles.map { String(localized: "\($0) stayed, and so did its files.") }
@@ -75,7 +87,7 @@ struct RemovalFailureAlert: ViewModifier {
/// selected.
private func copyDetails() {
let lines = quitLines + outcome.failures.map { "\($0.url.path(percentEncoded: false))\n\($0.reason.explanation)" }
- + keptLines + extraLines
+ + keptLines + driverLines + extraLines
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(lines.joined(separator: "\n\n"), forType: .string)
}