Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
c22dev committed Dec 22, 2023
1 parent 2873de3 commit b069ccf
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 373 deletions.
20 changes: 4 additions & 16 deletions Geranium.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
7916D9E42B34D9C4008E88F2 /* CurrentlyDisabledDaemonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7916D9E32B34D9C4008E88F2 /* CurrentlyDisabledDaemonView.swift */; };
7916D9E62B34FC06008E88F2 /* Paths.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7916D9E52B34FC06008E88F2 /* Paths.swift */; };
7918209A2B31F109007EEC24 /* LogHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791820992B31F109007EEC24 /* LogHelper.swift */; };
792845532B2C67910021E1FD /* FileCleaner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 792845522B2C67910021E1FD /* FileCleaner.swift */; };
7928455A2B2C80A40021E1FD /* DaemonDisabler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 792845592B2C80A40021E1FD /* DaemonDisabler.swift */; };
Expand All @@ -20,7 +21,6 @@
799615442B34A1930053558E /* DaemonWelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 799615432B34A1930053558E /* DaemonWelcomeView.swift */; };
79AEFBBD2B2CBC6B0074EC34 /* ProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79AEFBBC2B2CBC6B0074EC34 /* ProgressBar.swift */; };
79BA958A2B30D91600380D83 /* RootHelperMan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79BA95892B30D91600380D83 /* RootHelperMan.swift */; };
79D359942B2C9D91004C0FCF /* LSApplicationProxy+AltList.m in Sources */ = {isa = PBXBuildFile; fileRef = 79D359932B2C9D91004C0FCF /* LSApplicationProxy+AltList.m */; };
79DF26992B31C90C005D81D2 /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79DF26982B31C90C005D81D2 /* WelcomeView.swift */; };
FAA456D52B265FEA00FC7287 /* GeraniumApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA456D42B265FEA00FC7287 /* GeraniumApp.swift */; };
FAA456D72B265FEA00FC7287 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA456D62B265FEA00FC7287 /* ContentView.swift */; };
Expand Down Expand Up @@ -53,10 +53,10 @@

/* Begin PBXFileReference section */
7916D9E32B34D9C4008E88F2 /* CurrentlyDisabledDaemonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentlyDisabledDaemonView.swift; sourceTree = "<group>"; };
7916D9E52B34FC06008E88F2 /* Paths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Paths.swift; sourceTree = "<group>"; };
791820992B31F109007EEC24 /* LogHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogHelper.swift; sourceTree = "<group>"; };
792845522B2C67910021E1FD /* FileCleaner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileCleaner.swift; sourceTree = "<group>"; };
792845592B2C80A40021E1FD /* DaemonDisabler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaemonDisabler.swift; sourceTree = "<group>"; };
792845752B2C9CAE0021E1FD /* CoreServices.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreServices.h; sourceTree = "<group>"; };
795019B82B2B5055008EEC91 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
795019BA2B2B54A6008EEC91 /* delecture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = delecture.h; sourceTree = "<group>"; };
7989FD022B347EEA00FBAB8D /* LocSimView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocSimView.swift; sourceTree = "<group>"; };
Expand All @@ -68,8 +68,6 @@
799615432B34A1930053558E /* DaemonWelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaemonWelcomeView.swift; sourceTree = "<group>"; };
79AEFBBC2B2CBC6B0074EC34 /* ProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBar.swift; sourceTree = "<group>"; };
79BA95892B30D91600380D83 /* RootHelperMan.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootHelperMan.swift; sourceTree = "<group>"; };
79D359932B2C9D91004C0FCF /* LSApplicationProxy+AltList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "LSApplicationProxy+AltList.m"; sourceTree = "<group>"; };
79D359952B2C9DAD004C0FCF /* LSApplicationProxy+AltList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LSApplicationProxy+AltList.h"; sourceTree = "<group>"; };
79DF26982B31C90C005D81D2 /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; };
FAA456D12B265FEA00FC7287 /* Geranium.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Geranium.app; sourceTree = BUILT_PRODUCTS_DIR; };
FAA456D42B265FEA00FC7287 /* GeraniumApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeraniumApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -114,16 +112,6 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
792845732B2C92680021E1FD /* LSApp */ = {
isa = PBXGroup;
children = (
792845752B2C9CAE0021E1FD /* CoreServices.h */,
79D359932B2C9D91004C0FCF /* LSApplicationProxy+AltList.m */,
79D359952B2C9DAD004C0FCF /* LSApplicationProxy+AltList.h */,
);
path = LSApp;
sourceTree = "<group>";
};
795019B72B2B5016008EEC91 /* SwiftProcessViewer */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -205,7 +193,6 @@
FAA457222B26654700FC7287 /* Addon.swift */,
79AEFBBC2B2CBC6B0074EC34 /* ProgressBar.swift */,
79BA95892B30D91600380D83 /* RootHelperMan.swift */,
792845732B2C92680021E1FD /* LSApp */,
795019B72B2B5016008EEC91 /* SwiftProcessViewer */,
FAA4570E2B2661D200FC7287 /* TrollStore */,
791820992B31F109007EEC24 /* LogHelper.swift */,
Expand Down Expand Up @@ -246,6 +233,7 @@
isa = PBXGroup;
children = (
FAA4572F2B2666F300FC7287 /* CleanerView.swift */,
7916D9E52B34FC06008E88F2 /* Paths.swift */,
792845522B2C67910021E1FD /* FileCleaner.swift */,
);
path = Cleaner;
Expand Down Expand Up @@ -386,6 +374,7 @@
buildActionMask = 2147483647;
files = (
7989FD082B34894400FBAB8D /* BookMarkSlider.swift in Sources */,
7916D9E62B34FC06008E88F2 /* Paths.swift in Sources */,
7916D9E42B34D9C4008E88F2 /* CurrentlyDisabledDaemonView.swift in Sources */,
FAA457122B2661E300FC7287 /* TSUtil.m in Sources */,
7989FD062B3486B100FBAB8D /* CustomMapView.swift in Sources */,
Expand All @@ -395,7 +384,6 @@
79DF26992B31C90C005D81D2 /* WelcomeView.swift in Sources */,
7989FD032B347EEA00FBAB8D /* LocSimView.swift in Sources */,
FAA457322B2667CB00FC7287 /* SuperviseView.swift in Sources */,
79D359942B2C9D91004C0FCF /* LSApplicationProxy+AltList.m in Sources */,
792845532B2C67910021E1FD /* FileCleaner.swift in Sources */,
799488A62B347E2C00AFFDCF /* LocSimManager.swift in Sources */,
FAA456D72B265FEA00FC7287 /* ContentView.swift in Sources */,
Expand Down
155 changes: 117 additions & 38 deletions Geranium/Cleaner/CleanerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,8 @@ struct CleanerView: View {
@State var appCaches = false
@State var otaCaches = false
@State var batteryUsageDat = false
// Caches
@State public var logmobileCachesPath = "/var/mobile/Library/Logs/"
@State public var logCachesPath = "/var/log/"
@State public var logsCachesPath = "/var/logs/"
@State public var tmpCachesPath = "/var/tmp/"
@State public var globalCachesPath = "/var/mobile/Library/Caches/com.apple.CacheDeleteAppContainerCaches.deathrow"
@State public var phototmpCachePath = "/var/mobile/Media/PhotoData/CPL/storage/filecache/"
// Safari Caches
@State public var safariCachePath = "/var/mobile/Containers/Data/Application/Safari/Library/Caches/"
// OTA Update
@State public var OTAPath = "/var/MobileSoftwareUpdate/MobileAsset/AssetsV2/com_apple_MobileAsset_SoftwareUpdate/"
@State var RHResult = ""
@State var errorDetecteed = false
var body: some View {
if UIDevice.current.userInterfaceIdiom == .pad {
// Here we remove NavigationStack for iPads. Why ? Cause pressing "Exit" button with NavigationStack would make a blank screen
Expand All @@ -47,9 +38,12 @@ struct CleanerView: View {
private func cleanerViewMain() -> some View {
VStack {
if buttonAndSelection {
if progressAmount >= 0.9 {
if progressAmount >= 0.9, !errorDetecteed {
Image(systemName: "checkmark")
.foregroundColor(.green)
.onAppear {
successVibrate()
}
Text("Done !")
.foregroundStyle(.green)
Button("Exit", action: {
Expand All @@ -68,37 +62,91 @@ struct CleanerView: View {
.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()
}
}, noCancel: false, yes: true)
else if errorDetecteed {
Image(systemName: "x.circle")
.foregroundColor(.red)
.onAppear {
progressAmount = 0.9
errorVibrate()
}
Text("Error !")
.foregroundStyle(.red)
Text("An error occured with the RootHelper.")
.foregroundColor(.secondary)
.font(.footnote)
.multilineTextAlignment(.center)

Button("Try again", action: {
withAnimation {
buttonAndSelection = true
isTabViewHidden.toggle()
errorDetecteed.toggle()
progressAmount = 0
safariCacheSize = 0
GlobalCacheSize = 0
OTACacheSize = 0
progressAmount = 0
}
})
.padding(10)
.background(.red)
.cornerRadius(8)
.foregroundColor(.black)
.transition(.scale)
}
else {
if safari || appCaches || otaCaches || batteryUsageDat {
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)
}
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)
.disabled(true)
}
Toggle(isOn: $safari) {
Image(systemName: "safari")
Text("Safari Caches")
Text(String(format: "%.2f MB", safariCacheSize / (1024 * 1024)))
Text(">"+String(format: "%.2f MB", safariCacheSize / (1024 * 1024)))
}
.toggleStyle(checkboxiOS())
.padding(2)
.onAppear {
calculateDirectorySizeAsync(url: URL(fileURLWithPath: safariCachePath)) { size in
safariCacheSize = size
calculateDirectorySizeAsync(url: URL(fileURLWithPath: removeFilePrefix(safariCachePath))) { size in
safariCacheSize += size
}
calculateDirectorySizeAsync(url: URL(fileURLWithPath: removeFilePrefix(safariImgCachePath))) { size in
safariCacheSize += size
}
}
Toggle(isOn: $appCaches) {
Image(systemName: "app.dashed")
Text("General Caches")
Text(String(format: "%.2f MB", GlobalCacheSize / (1024 * 1024)))
Text(">" + String(format: "%.2f MB", GlobalCacheSize / (1024 * 1024)))
}
.toggleStyle(checkboxiOS())
.padding(2)
Expand Down Expand Up @@ -132,7 +180,6 @@ struct CleanerView: View {
Toggle(isOn: $otaCaches) {
Image(systemName: "restart.circle")
Text("OTA Update Caches")
Text(String(format: "%.2f MB", OTACacheSize / (1024 * 1024)))
}
.toggleStyle(checkboxiOS())
.padding(2)
Expand All @@ -150,7 +197,6 @@ struct CleanerView: View {
.padding(2)
}
}

if !buttonAndSelection {
ProgressBar(value: progressAmount)
.padding(.leading, 50)
Expand All @@ -159,31 +205,64 @@ struct CleanerView: View {
performCleanup()
if safari {
print("safari")
deleteContentsOfDirectory(atPath: safariCachePath)
RHResult = deleteContentsOfDirectory(atPath: removeFilePrefix((safariCachePath)))
if RHResult != "0" {
errorDetecteed = true
}
RHResult = deleteContentsOfDirectory(atPath: removeFilePrefix((safariImgCachePath)))
if RHResult != "0" {
errorDetecteed = true
}
}
if appCaches {
print("appcaches")
deleteContentsOfDirectory(atPath: logmobileCachesPath)
deleteContentsOfDirectory(atPath: logCachesPath)
deleteContentsOfDirectory(atPath: logsCachesPath)
deleteContentsOfDirectory(atPath: tmpCachesPath)
deleteContentsOfDirectory(atPath: phototmpCachePath)
deleteContentsOfDirectory(atPath: globalCachesPath)
RHResult = deleteContentsOfDirectory(atPath: logmobileCachesPath)
if RHResult != "0" {
errorDetecteed = true
}
RHResult = deleteContentsOfDirectory(atPath: logCachesPath)
if RHResult != "0" {
errorDetecteed = true
}
RHResult = deleteContentsOfDirectory(atPath: logsCachesPath)
if RHResult != "0" {
errorDetecteed = true
}
RHResult = deleteContentsOfDirectory(atPath: tmpCachesPath)
if RHResult != "0" {
errorDetecteed = true
}
RHResult = deleteContentsOfDirectory(atPath: phototmpCachePath)
if RHResult != "0" {
errorDetecteed = true
}
RHResult = deleteContentsOfDirectory(atPath: globalCachesPath)
if RHResult != "0" {
errorDetecteed = true
}
}
if otaCaches {
print("otacaches")
deleteContentsOfDirectory(atPath: OTAPath)
RHResult = deleteContentsOfDirectory(atPath: OTAPath)
if RHResult != "0" {
errorDetecteed = true
}
}
}
}
}
.toolbar{
ToolbarItem(placement: .navigationBarLeading) {
Text("Cleaner")
.font(.title2)
.bold()
if !isTabViewHidden {
Text("Cleaner")
.font(.title2)
.bold()
}
}
}
.onAppear {
RootHelper.setPermission(url: URL(fileURLWithPath:OTAPath))
}
}
func performCleanup() {
cleanProcess(safari: safari, appCaches: appCaches, otaCaches: otaCaches, batteryUsageDat: batteryUsageDat) { progressHandler in
Expand Down
10 changes: 7 additions & 3 deletions Geranium/Cleaner/FileCleaner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func cleanProcess(safari: Bool, appCaches: Bool, otaCaches: Bool, batteryUsageDa
let progress = Double(step + 1) / Double(totalProgressSteps)
DispatchQueue.main.async {
progressHandler(progress)
miniimpactVibrate()
}
usleep(50000)
}
Expand Down Expand Up @@ -57,12 +58,15 @@ func directorySize(url: URL) -> Int64 {
return size
}

func deleteContentsOfDirectory(atPath path: String) {
func deleteContentsOfDirectory(atPath path: String) -> String {
var log = RootHelper.setPermission(url: URL(fileURLWithPath: path))
print(log)
log = RootHelper.removeItem(at: URL(fileURLWithPath: path))
print(log)
let log2 = RootHelper.removeItem(at: URL(fileURLWithPath: path))
log = RootHelper.createDirectory(at: URL(fileURLWithPath: path))
print(log)
// set perms again else things won't work properly for mobile registered paths
log = RootHelper.setPermission(url: URL(fileURLWithPath: path))
print(log)
print("Contents of directory \(path) deleted")
return(log2)
}
Loading

0 comments on commit b069ccf

Please sign in to comment.