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
Leave TeamViewer's components to its own uninstaller
Țugui Dragoș3a3fee23c44f
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 21752173..4c855aaa 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -95565,6 +95565,112 @@}}},+ "Once %@ leaves the Applications folder, its own uninstaller opens and asks to remove the components it keeps in the system. If you continue there, it deletes them, which History can’t bring back." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Jakmile aplikace %@ opustí složku Aplikace, otevře se její vlastní odinstalátor a zeptá se, zda má odstranit komponenty, které aplikace uchovává v systému. Pokud v něm budete pokračovat, smaže je a Historie je nemůže vrátit."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Sobald %@ den Ordner „Programme“ verlässt, öffnet sich das eigene Deinstallationsprogramm der App und fragt, ob es die Komponenten entfernen soll, die die App im System ablegt. Wenn du dort fortfährst, löscht das Deinstallationsprogramm diese Komponenten, die sich über den Verlauf nicht zurückholen lassen."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Cuando %@ salga de la carpeta Aplicaciones, su propio desinstalador se abrirá y pedirá permiso para eliminar los componentes que la app guarda en el sistema. Si continúas en él, borrará esos componentes, que Historial no puede recuperar."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Une fois %@ sorti du dossier Applications, son propre programme de désinstallation s’ouvre et demande à supprimer les composants que l’app conserve dans le système. Si vous continuez dans ce programme, il supprime ces composants, que l’Historique ne peut pas rétablir."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Quando %@ esce dalla cartella Applicazioni, il suo stesso programma di disinstallazione si apre e chiede di rimuovere i componenti che l’app tiene nel sistema. Se continui lì, il programma li elimina e la Cronologia non può ripristinarli."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@が“アプリケーション”フォルダから移動されると、アプリ独自のアンインストーラが開き、アプリがシステム内に置いているコンポーネントを取り除くかどうかを尋ねます。アンインストーラで操作を続けると、それらのコンポーネントは削除され、履歴から元に戻すことはできません。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "‘%@’이(가) 응용 프로그램 폴더에서 옮겨지면 앱 자체의 제거 프로그램이 열리고 앱이 시스템에 보관하는 구성 요소를 제거할지 묻습니다. 이 제거 프로그램에서 계속하면 이러한 구성 요소가 삭제되며, 이는 기록에서 되살릴 수 없습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Zodra %@ de map 'Apps' verlaat, wordt het eigen de-installatieprogramma van de app geopend, dat vraagt of je de componenten wilt verwijderen die de app in het systeem bewaart. Als je daar doorgaat, verwijdert het ze definitief, en Geschiedenis kan ze niet terugzetten."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Gdy aplikacja %@ opuści folder Aplikacje, jej własny dezinstalator otworzy się i zapyta, czy usunąć składniki, które aplikacja przechowuje w systemie. Jeśli będziesz w nim kontynuować, usunie je, a Historia nie może ich przywrócić."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Assim que %@ sair da pasta Aplicativos, o próprio desinstalador do app abre e pede para remover os componentes que o app mantém no sistema. Se você continuar nele, ele apaga esses componentes, que o Histórico não pode trazer de volta."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "După ce %@ iese din dosarul Aplicații, programul propriu de dezinstalare al aplicației se deschide și cere să elimine componentele pe care aplicația le păstrează în sistem. Dacă continuați acolo, acesta șterge componentele, care nu pot fi readuse din Istoric."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Как только приложение «%@» покинет папку «Программы», его собственная программа удаления откроется и предложит удалить компоненты, которые оно хранит в системе. Если Вы продолжите в ней, она удалит их, и История не сможет их вернуть."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "När %@ lämnar mappen Appar öppnas appens egen avinstallerare och ber att få ta bort komponenterna som appen har i systemet. Om du fortsätter där raderar avinstalleraren komponenterna, och dem kan Historik inte få tillbaka."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ uygulaması Uygulamalar klasöründen çıktığında, kendi yükleme kaldırıcısı açılır ve uygulamanın sistemde tuttuğu bileşenleri kaldırmak için izin ister. Orada devam ederseniz bileşenleri siler; Geçmiş bunları geri getiremez."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Щойно програма «%@» залишить папку «Програми», її власний деінсталятор відкриється й запропонує вилучити компоненти, які вона зберігає в системі. Якщо ви продовжите в ньому, він видалить ці компоненти, і Історія не зможе їх повернути."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "一旦“%@”离开“应用程序”文件夹,它自己的卸载器就会打开,并询问你是否要移除它保存在系统中的组件。如果你在卸载器中继续,它会删除这些组件,“历史记录”无法将其恢复。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "一旦「%@」離開「應用程式」檔案夾,它自己的解除安裝程式就會打開,並詢問你是否要移除該App保存在系統中的組件。如果你在那裡繼續,它就會刪除這些組件,而「歷史記錄」無法將其恢復。"+ }+ }+ }+ },"Once the file is in the Trash, the item is stopped." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex 19df64cb..c100df41 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -431,6 +431,8 @@ struct UninstallCommand: AsyncParsableCommand {warnings.append("Once \(app.app.name) leaves the Applications folder, its own service uninstalls it: it logs this Mac out of the account and deletes its settings, which the Trash can't bring back. Write down the account number first, or run its own uninstaller instead: \(script)")case .deletesTheApp:warnings.append("Once \(app.app.name) leaves the Applications folder, its own uninstaller opens and asks for an administrator's password. If you continue there, it deletes the app, even from the Trash, and its system files, which the Trash can't bring back.")+ case .removesItsComponents:+ warnings.append("Once \(app.app.name) leaves the Applications folder, its own uninstaller opens and asks to remove the components it keeps in the system. If you continue there, it deletes them, which the Trash can't bring back.")}}return warningsdiff --git a/Packages/PeelCore/Sources/PeelCore/Removal/UninstallsItself.swift b/Packages/PeelCore/Sources/PeelCore/Removal/UninstallsItself.swiftindex bfa5ba89..9380c150 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/UninstallsItself.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/UninstallsItself.swift@@ -8,6 +8,8 @@ public struct UninstallsItself: Sendable, Hashable {case logsOut(script: String)/// Asks for an administrator, then deletes the app, even from the Trash, and its system files.case deletesTheApp+ /// Asks to remove the components it keeps in the system, then deletes them.+ case removesItsComponents}public let app: InstalledApp@@ -71,8 +73,38 @@ public struct UninstallsItself: Sendable, Hashable {])+ /// TeamViewer's daemon `com.teamviewer.UninstallerWatcher` watches the app and, once it is in the Trash, opens the+ /// uninstaller that asks to remove what TeamViewer's package put in the system (TeamViewer 15's+ /// `TeamViewerUninstaller.app` and its helper).+ private static let teamViewer = (+ identifier: "com.teamviewer.TeamViewer",+ watcher: "Library/LaunchDaemons/com.teamviewer.UninstallerWatcher.plist"+ )++ private static let teamViewerRemoves = (+ root: [+ "Library/LaunchDaemons/com.teamviewer.Helper.plist",+ "Library/LaunchDaemons/com.teamviewer.ScriptExecutionHelper.plist",+ "Library/LaunchDaemons/com.teamviewer.UninstallerHelper.plist",+ "Library/LaunchDaemons/com.teamviewer.UninstallerWatcher.plist",+ "Library/LaunchDaemons/com.teamviewer.teamviewer_service.plist",+ "Library/LaunchAgents/com.teamviewer.teamviewer.plist",+ "Library/LaunchAgents/com.teamviewer.teamviewer_desktop.plist",+ "Library/PrivilegedHelperTools/com.teamviewer.Helper",+ "Library/PrivilegedHelperTools/com.teamviewer.UninstallerHelper",+ "Library/Application Support/TeamViewer",+ "Library/Security/SecurityAgentPlugins/TeamViewerAuthPlugin.bundle",+ "Library/Audio/Plug-Ins/HAL/TVRemoteAudio.driver",+ "Library/Caches/com.teamviewer.TeamViewer.RemotePrinting",+ "Library/Printers/Icons/TeamViewer.icns",+ "usr/libexec/cups/filter/pdftoteamviewer",+ ],+ home: [String]()+ )+public static func of(_ app: InstalledApp, environment: SearchEnvironment = .current) -> UninstallsItself? {mullvad(app, environment: environment) ?? citrix(app, environment: environment)+ ?? teamViewer(app, environment: environment)}private static func mullvad(_ app: InstalledApp, environment: SearchEnvironment) -> UninstallsItself? {@@ -102,6 +134,25 @@ public struct UninstallsItself: Sendable, Hashable {return UninstallsItself(app: app, uninstaller: .deletesTheApp, removed: paths(citrixRemoves, in: environment))}+ private static func teamViewer(_ app: InstalledApp, environment: SearchEnvironment) -> UninstallsItself? {+ let place = PathPattern.comparablePath(of: app.url)+ guard+ app.bundleIdentifier == teamViewer.identifier,+ let watcher = JobDefinition(contentsOf: environment.rootDirectory.appending(path: teamViewer.watcher)),+ !watcher.isDisabled,+ watcher.watchPaths.contains(where: {+ PathComponents.isPath(PathPattern.comparablePath(of: URL(filePath: $0)), atOrInside: place)+ }),+ let program = watcher.program,+ FileManager.default.isExecutableFile(atPath: program)+ else { return nil }+ return UninstallsItself(+ app: app,+ uninstaller: .removesItsComponents,+ removed: paths(teamViewerRemoves, in: environment)+ )+ }+private static func paths(_ removes: (root: [String], home: [String]),in environment: SearchEnvironmentdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallsItselfTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallsItselfTests.swiftindex 4213c8ee..415a3d4b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallsItselfTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallsItselfTests.swift@@ -312,6 +312,107 @@ struct UninstallsItselfTests {}}+ private struct TeamViewer: ~Copyable {+ let directory: TemporaryDirectory+ let app: InstalledApp+ let environment: SearchEnvironment++ init(watching watched: String? = nil, disabled: Bool = false, starterInPlace: Bool = true) throws {+ let directory = try TemporaryDirectory()+ let bundle = try directory.directory("root/Applications/TeamViewer.app")+ let starter = "root/Library/Application Support/TeamViewer/TeamViewerUninstaller.app/Contents/Helpers/com.teamviewer.UninstallerStarter"+ if starterInPlace {+ try directory.file(starter)+ try directory.setPermissions(0o755, of: starter)+ }+ try directory.file(+ "root/Library/LaunchDaemons/com.teamviewer.UninstallerWatcher.plist",+ contents: PropertyListSerialization.data(+ fromPropertyList: [+ "Label": "com.teamviewer.UninstallerWatcher",+ "Disabled": disabled,+ "Program": directory.url.appending(path: starter).path(percentEncoded: false),+ "WatchPaths": [watched ?? bundle.path(percentEncoded: false)],+ ],+ format: .xml,+ options: 0+ )+ )+ self.app = InstalledApp(url: bundle, bundleIdentifier: "com.teamviewer.TeamViewer", name: "TeamViewer")+ self.environment = SearchEnvironment(+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)+ )+ self.directory = directory+ }++ func job(_ path: String, running program: String) throws -> URL {+ let job = [+ "Label": URL(filePath: path).deletingPathExtension().lastPathComponent,+ "Program": app.url.appending(path: program).path(percentEncoded: false),+ ]+ return try directory.file(+ path,+ contents: PropertyListSerialization.data(fromPropertyList: job, format: .xml, options: 0)+ )+ }+ }++ @Test func teamViewerUninstallsItselfThroughTheDaemonThatWatchesIt() throws {+ let teamViewer = try TeamViewer()++ let uninstaller = UninstallsItself.of(teamViewer.app, environment: teamViewer.environment)?.uninstaller+ #expect(uninstaller == .removesItsComponents)+ }++ @Test func teamViewerIsAnOrdinaryAppWhenNoDaemonWouldOpenItsUninstaller() throws {+ let elsewhere = try TeamViewer(watching: "/Applications/Another.app")+ let disabled = try TeamViewer(disabled: true)+ let noStarter = try TeamViewer(starterInPlace: false)+ let noDaemon = try TeamViewer()+ try FileManager.default.removeItem(+ at: noDaemon.environment.rootDirectory.appending(path: "Library/LaunchDaemons/com.teamviewer.UninstallerWatcher.plist")+ )++ #expect(UninstallsItself.of(elsewhere.app, environment: elsewhere.environment) == nil)+ #expect(UninstallsItself.of(disabled.app, environment: disabled.environment) == nil)+ #expect(UninstallsItself.of(noStarter.app, environment: noStarter.environment) == nil)+ #expect(UninstallsItself.of(noDaemon.app, environment: noDaemon.environment) == nil)+ }++ @Test func leavesToTeamViewersUninstallerWhatItRemovesAndOffersTheRest() async throws {+ let teamViewer = try TeamViewer()+ let root = teamViewer.environment.rootDirectory+ let removedByIt = [+ try teamViewer.job(+ "root/Library/LaunchDaemons/com.teamviewer.teamviewer_service.plist",+ running: "Contents/MacOS/TeamViewer_Service"+ ),+ try teamViewer.job(+ "root/Library/LaunchAgents/com.teamviewer.teamviewer_desktop.plist",+ running: "Contents/Helpers/TeamViewer_Desktop"+ ),+ root.appending(path: "Library/LaunchDaemons/com.teamviewer.UninstallerWatcher.plist"),+ root.appending(path: "Library/Application Support/TeamViewer"),+ ]+ let leftByIt = [try teamViewer.directory.directory("home/Library/Caches/com.teamviewer.TeamViewer")]++ let plan = await Uninstallation.prepare(+ teamViewer.app, installedApps: [teamViewer.app], environment: teamViewer.environment+ )++ let heldBack = Dictionary(+ plan.scan.leftovers.map { (PathPattern.comparablePath(of: $0.url), $0.match.heldBack) },+ uniquingKeysWith: { first, _ in first }+ )+ for url in removedByIt {+ #expect(heldBack[PathPattern.comparablePath(of: url)] == .some(.leftToItsUninstaller), "\(url.path())")+ }+ for url in leftByIt {+ #expect(heldBack[PathPattern.comparablePath(of: url)] == .some(nil), "\(url.path())")+ }+ }+@Test func citrixsBundleMovesWhileItsHelperRunsFromIt() async throws {let citrix = try Citrix()let helper = try citrix.directory.runningProgram(diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swiftindex 34951310..fe4f6495 100644--- a/Peel/Views/Presentation.swift+++ b/Peel/Views/Presentation.swift@@ -135,6 +135,8 @@ extension UninstallsItself {Text("Once \(app.name) leaves the Applications folder, its own service uninstalls it: it logs this Mac out of your account and deletes its settings, which History can’t bring back. Write down your account number first, or run the app’s own uninstaller instead: `\(script)`.")case .deletesTheApp:Text("Once \(app.name) leaves the Applications folder, its own uninstaller opens and asks for an administrator’s password. If you continue there, it deletes the app, even from the Trash, and its system files, which History can’t bring back.")+ case .removesItsComponents:+ Text("Once \(app.name) leaves the Applications folder, its own uninstaller opens and asks to remove the components it keeps in the system. If you continue there, it deletes them, which History can’t bring back.")}}}diff --git a/SAFETY.md b/SAFETY.mdindex ffd55fee..82411362 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -153,7 +153,8 @@ Moving a database or a cache from under an agent, a daemon, or a server that isof macOS's own, such as a service keeping its cache open, is named as macOS: nobody quits it, so the item stayswhere it is. An app is code, which loses nothing when it moves, so a program that only reads inside it, as Safarireads an app's Safari extension, does not keep it in place; one that runs from it or writes in it does, unless the-app uninstalls itself once it is moved, as Mullvad VPN and Citrix Workspace do: their own uninstaller stops it. When+app uninstalls itself once it is moved, as Mullvad VPN, Citrix Workspace, and TeamViewer do: their own+uninstaller stops it. Whennothing but an app's own background programs, the launch agents and daemons that run from inside it, keeps the appin place, an uninstall stops them first and then moves the app, and starts them again if it still stays. Peel itselfcounts too: whatever Peel runs from, and any folder holding it, stays, since only Remove Peel moves Peel. Of@@ -189,7 +190,7 @@ Four things Peel starts can't be undone by History, and Peel says so before youForgetting a preference domain after a removal is not one of them: it happens only once the file is in the Trash,and putting the file back undoes it, until the app writes its settings again.-Two apps delete something of their own once they are moved, which Peel says before it moves them. Mullvad VPN's+Three apps delete something of their own once they are moved, which Peel says before it moves them. Mullvad VPN'sservice logs the Mac out of its account and deletes its settings when the app leaves the Applications folder; whatthat service removes (its launch daemon's file, its command links and shell completions, its receipt, its logs, andits settings) is listed and never moved by Peel: moving the daemon's file first would stop the service before it@@ -197,6 +198,10 @@ could clean up. Citrix Workspace's own agent opens Citrix's uninstaller once thefolder, which asks for an administrator's password and, if you continue, deletes the app, even from the Trash, andits system files; what it deletes (its launch agents and daemons, its folders in the Library, its logs, its receipt,and its settings) is listed and never moved by Peel, since moving the agent's file would stop the uninstaller.+TeamViewer's own daemon opens TeamViewer's uninstaller once the app is in the Trash, which asks to remove the+components it keeps in the system and, if you continue, deletes them; what it removes (its launch daemons and agents,+its helpers, its folder in Application Support, its authorization plug-in, its audio driver, and its printing files)+is listed and never moved by Peel, since moving its helper's file would stop the uninstaller halfway.If the record itself is damaged, it is set aside under another name rather than overwritten, because it isthe only way back from a removal. If it can't be read at all, Peel moves nothing until it can, or until you