-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
Menu Bar - Orphan Cleanup.swift
57 lines (48 loc) · 1.85 KB
/
Menu Bar - Orphan Cleanup.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Menu Bar - Orphan Cleanup.swift
// Cork
//
// Created by David Bureš on 30.03.2024.
//
import SwiftUI
struct MenuBar_OrphanCleanup: View
{
@EnvironmentObject var brewData: BrewDataStorage
@State private var isUninstallingOrphanedPackages: Bool = false
var body: some View
{
if !isUninstallingOrphanedPackages
{
Button("maintenance.steps.packages.uninstall-orphans")
{
Task(priority: .userInitiated)
{
AppConstants.logger.log("Will delete orphans")
do
{
let orphanUninstallResult = try await uninstallOrphansUtility()
sendNotification(
title: String(localized: "maintenance.results.orphans-removed"),
body: String(localized: "maintenance.results.orphans-count-\(orphanUninstallResult)"),
sensitivity: .active
)
}
catch let orphanUninstallationError as OrphanRemovalError
{
AppConstants.logger.error("Failed while uninstalling orphans: \(orphanUninstallationError, privacy: .public)")
sendNotification(
title: String(localized: "maintenance.results.orphans.failure"),
body: String(localized: "maintenance.results.orphans.failure.details-\(orphanUninstallationError.localizedDescription)"),
sensitivity: .active
)
}
await synchronizeInstalledPackages(brewData: brewData)
}
}
}
else
{
Text("maintenance.step.removing-orphans")
}
}
}