Skip to content

Commit

Permalink
partially fixed ipad views
Browse files Browse the repository at this point in the history
  • Loading branch information
Constantin Clerc committed Dec 19, 2023
1 parent 79d7b96 commit 84dcbd0
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 226 deletions.
Binary file not shown.
246 changes: 128 additions & 118 deletions Geranium/Cleaner/CleanerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import SwiftUI

struct CleanerView: View {
@Binding var isTabViewHidden: Bool
@State var exitStatus = false
@State var loadingBarStatus = false
@State var buttonAndSelection = true
@State private var safariCacheSize: Double = 0
@State private var GlobalCacheSize: Double = 0
Expand All @@ -31,139 +33,147 @@ struct CleanerView: View {
// OTA Update
@State public var OTAPath = "/var/MobileSoftwareUpdate/MobileAsset/AssetsV2/com_apple_MobileAsset_SoftwareUpdate/"
var body: some View {
NavigationView {
VStack {
if buttonAndSelection {
if progressAmount >= 0.9 {
Image(systemName: "checkmark")
.foregroundColor(.green)
Text("Done !")
.foregroundStyle(.green)
Button("Exit", action: {
if #available(iOS 16.0, *), UIDevice.current.userInterfaceIdiom == .pad {
cleanerViewMain()
} else {
NavigationView {
cleanerViewMain()
}
}
}
@ViewBuilder
private func cleanerViewMain() -> some View {
VStack {
if buttonAndSelection {
if progressAmount >= 0.9 {
Image(systemName: "checkmark")
.foregroundColor(.green)
Text("Done !")
.foregroundStyle(.green)
Button("Exit", action: {
withAnimation {
isTabViewHidden.toggle()
progressAmount = 0
safariCacheSize = 0
GlobalCacheSize = 0
OTACacheSize = 0
progressAmount = 0
}
})
.padding(10)
.background(.green)
.cornerRadius(8)
.foregroundColor(.black)
.transition(.scale)
}
else {
Button("Clean !", action: {
UIApplication.shared.confirmAlert(title: "Selected options", body: "Safari Caches: \(truelyEnabled(safari))\nGeneral Caches: \(truelyEnabled(appCaches))\nOTA Update Caches: \(truelyEnabled(otaCaches))\nBattery Usage Data: \(truelyEnabled(batteryUsageDat))\n Are you sure you want to permanently delete those files ?", onOK: {
print("")
withAnimation {
buttonAndSelection.toggle()
isTabViewHidden.toggle()
progressAmount = 0
safariCacheSize = 0
GlobalCacheSize = 0
OTACacheSize = 0
progressAmount = 0
}
})
.padding(10)
.background(.green)
.cornerRadius(8)
.foregroundColor(.black)
.transition(.scale)
}, noCancel: false, yes: true)
})
.padding(10)
.background(Color.accentColor)
.cornerRadius(8)
.foregroundColor(.black)
.transition(.scale)
Toggle(isOn: $safari) {
Image(systemName: "safari")
Text("Safari Caches")
Text(String(format: "%.2f MB", safariCacheSize / (1024 * 1024)))
}
else {
Button("Clean !", action: {
UIApplication.shared.confirmAlert(title: "Selected options", body: "Safari Caches: \(truelyEnabled(safari))\nGeneral Caches: \(truelyEnabled(appCaches))\nOTA Update Caches: \(truelyEnabled(otaCaches))\nBattery Usage Data: \(truelyEnabled(batteryUsageDat))\n Are you sure you want to permanently delete those files ?", onOK: {
print("")
withAnimation {
buttonAndSelection.toggle()
isTabViewHidden.toggle()
}
}, noCancel: false, yes: true)
})
.padding(10)
.background(Color.accentColor)
.cornerRadius(8)
.foregroundColor(.black)
.transition(.scale)
Toggle(isOn: $safari) {
Image(systemName: "safari")
Text("Safari Caches")
Text(String(format: "%.2f MB", safariCacheSize / (1024 * 1024)))
.toggleStyle(checkboxiOS())
.padding(2)
.onAppear {
calculateDirectorySizeAsync(url: URL(fileURLWithPath: safariCachePath)) { size in
safariCacheSize = size
}
.toggleStyle(checkboxiOS())
.padding(2)
.onAppear {
calculateDirectorySizeAsync(url: URL(fileURLWithPath: safariCachePath)) { size in
safariCacheSize = size
}
}
Toggle(isOn: $appCaches) {
Image(systemName: "app.dashed")
Text("General Caches")
Text(String(format: "%.2f MB", GlobalCacheSize / (1024 * 1024)))
}
.toggleStyle(checkboxiOS())
.padding(2)
.onAppear {
progressAmount = 0
safariCacheSize = 0
GlobalCacheSize = 0
OTACacheSize = 0
progressAmount = 0
// mess
calculateDirectorySizeAsync(url: URL(fileURLWithPath: logCachesPath)) { size in
GlobalCacheSize += size
}
Toggle(isOn: $appCaches) {
Image(systemName: "app.dashed")
Text("General Caches")
Text(String(format: "%.2f MB", GlobalCacheSize / (1024 * 1024)))
calculateDirectorySizeAsync(url: URL(fileURLWithPath: logmobileCachesPath)) { size in
GlobalCacheSize += size
}
.toggleStyle(checkboxiOS())
.padding(2)
.onAppear {
progressAmount = 0
safariCacheSize = 0
GlobalCacheSize = 0
OTACacheSize = 0
progressAmount = 0
// mess
calculateDirectorySizeAsync(url: URL(fileURLWithPath: logCachesPath)) { size in
GlobalCacheSize += size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: logmobileCachesPath)) { size in
GlobalCacheSize += size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: tmpCachesPath)) { size in
GlobalCacheSize += size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: phototmpCachePath)) { size in
GlobalCacheSize += size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: logsCachesPath)) { size in
GlobalCacheSize += size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: globalCachesPath)) { size in
GlobalCacheSize += size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: tmpCachesPath)) { size in
GlobalCacheSize += size
}

Toggle(isOn: $otaCaches) {
Image(systemName: "restart.circle")
Text("OTA Update Caches")
Text(String(format: "%.2f MB", OTACacheSize / (1024 * 1024)))
calculateDirectorySizeAsync(url: URL(fileURLWithPath: phototmpCachePath)) { size in
GlobalCacheSize += size
}
.toggleStyle(checkboxiOS())
.padding(2)
.onAppear {
calculateDirectorySizeAsync(url: URL(fileURLWithPath: OTAPath)) { size in
OTACacheSize = size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: logsCachesPath)) { size in
GlobalCacheSize += size
}

Toggle(isOn: $batteryUsageDat) {
Image(systemName: "battery.100percent")
Text("Battery Usage Data")
calculateDirectorySizeAsync(url: URL(fileURLWithPath: globalCachesPath)) { size in
GlobalCacheSize += size
}
.toggleStyle(checkboxiOS())
.padding(2)
}
}

if !buttonAndSelection {
ProgressBar(value: progressAmount)
.padding(.leading, 50)
.padding(.trailing, 50)
.onAppear {
performCleanup()
if safari {
print("safari")
deleteContentsOfDirectory(atPath: safariCachePath)
}
if appCaches {
print("appcaches")
deleteContentsOfDirectory(atPath: logmobileCachesPath)
deleteContentsOfDirectory(atPath: logCachesPath)
deleteContentsOfDirectory(atPath: logsCachesPath)
deleteContentsOfDirectory(atPath: tmpCachesPath)
deleteContentsOfDirectory(atPath: phototmpCachePath)
deleteContentsOfDirectory(atPath: globalCachesPath)
}
if otaCaches {
print("otacaches")
deleteContentsOfDirectory(atPath: OTAPath)
}

Toggle(isOn: $otaCaches) {
Image(systemName: "restart.circle")
Text("OTA Update Caches")
Text(String(format: "%.2f MB", OTACacheSize / (1024 * 1024)))
}
.toggleStyle(checkboxiOS())
.padding(2)
.onAppear {
calculateDirectorySizeAsync(url: URL(fileURLWithPath: OTAPath)) { size in
OTACacheSize = size
}
}

Toggle(isOn: $batteryUsageDat) {
Image(systemName: "battery.100percent")
Text("Battery Usage Data")
}
.toggleStyle(checkboxiOS())
.padding(2)
}
}

if !buttonAndSelection {
ProgressBar(value: progressAmount)
.padding(.leading, 50)
.padding(.trailing, 50)
.onAppear {
performCleanup()
if safari {
print("safari")
deleteContentsOfDirectory(atPath: safariCachePath)
}
if appCaches {
print("appcaches")
deleteContentsOfDirectory(atPath: logmobileCachesPath)
deleteContentsOfDirectory(atPath: logCachesPath)
deleteContentsOfDirectory(atPath: logsCachesPath)
deleteContentsOfDirectory(atPath: tmpCachesPath)
deleteContentsOfDirectory(atPath: phototmpCachePath)
deleteContentsOfDirectory(atPath: globalCachesPath)
}
if otaCaches {
print("otacaches")
deleteContentsOfDirectory(atPath: OTAPath)
}
}
}
}
.navigationBarTitle("Cleaner")
}
Expand Down
57 changes: 33 additions & 24 deletions Geranium/DaemonMan/DaemonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,46 @@ struct DaemonView: View {
init() {
self.processes = []
}

var body: some View {
NavigationView {
List {
SearchBar(text: $searchText)

ForEach(filteredProcesses) { process in
HStack {
Text("PID: \(process.pid)")
Spacer()
Text("Name: \(process.procName)")
}
if #available(iOS 16.0, *) {
NavigationStack {
DaemonMainView()
}
.onDelete { indexSet in
guard let index = indexSet.first else { return }
let process = filteredProcesses[index]
//MARK: Probably the WORST EVER WAY to define a daemon's bundle ID. I'll try over objc s0n
daemonManagement(key: "com.apple.\(process.procName)",value: true, plistPath: "/var/db/com.apple.xpc.launchd/disabled.plist")
killall(process.procName)
updateProcesses()
UIApplication.shared.alert(title: "\(process.procName) was successfuly disabled in launchd database", body: "This daemon won't launch next startup.")
} else {
NavigationView {
DaemonMainView()
}
}
.navigationTitle("Daemons")
.onAppear {
startTimer()
}
@ViewBuilder
private func DaemonMainView() -> some View {
List {
SearchBar(text: $searchText)

ForEach(filteredProcesses) { process in
HStack {
Text("PID: \(process.pid)")
Spacer()
Text("Name: \(process.procName)")
}
}
.onDisappear {
stopTimer()
.onDelete { indexSet in
guard let index = indexSet.first else { return }
let process = filteredProcesses[index]
//MARK: Probably the WORST EVER WAY to define a daemon's bundle ID. I'll try over objc s0n
daemonManagement(key: "com.apple.\(process.procName)",value: true, plistPath: "/var/db/com.apple.xpc.launchd/disabled.plist")
killall(process.procName)
updateProcesses()
UIApplication.shared.alert(title: "\(process.procName) was successfuly disabled in launchd database", body: "This daemon won't launch next startup.")
}
}
.navigationTitle("Daemons")
.onAppear {
startTimer()
}
.onDisappear {
stopTimer()
}
}

private func startTimer() {
Expand Down
Loading

0 comments on commit 84dcbd0

Please sign in to comment.