Skip to content

Commit

Permalink
fixed cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Constantin Clerc committed Dec 21, 2023
1 parent bf11295 commit e2a5ec2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 76 deletions.
19 changes: 6 additions & 13 deletions Geranium/Cleaner/FileCleaner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,11 @@ func directorySize(url: URL) -> Int64 {
}

func deleteContentsOfDirectory(atPath path: String) {
var RHOutput = ""
do {
let contents = try FileManager.default.contentsOfDirectory(atPath: path)

for content in contents {
let contentPath = (path as NSString).appendingPathComponent(content)
try FileManager.default.removeItem(atPath: contentPath)
RHOutput = RootHelper.removeItem(at: URL(fileURLWithPath: content))
print("\(RHOutput)")
}
var log = RootHelper.setPermission(url: URL(fileURLWithPath: path))
print(log)
log = RootHelper.removeItem(at: URL(fileURLWithPath: path))
print(log)
log = RootHelper.createDirectory(at: URL(fileURLWithPath: path))
print(log)
print("Contents of directory \(path) deleted")
} catch {
print("Error deleting contents of directory \(path): \(error.localizedDescription) and \(RHOutput)")
}
}
140 changes: 77 additions & 63 deletions Geranium/DaemonMan/DaemonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,79 +43,93 @@ struct DaemonView: View {
}
@ViewBuilder
private func DaemonMainView() -> some View {
List {
SearchBar(text: $searchText)

ForEach(filteredProcesses) { process in
HStack {
Text("Name: \(process.procName)")
.foregroundColor(toDisable.contains(process.procName) ? .red : .primary)
}
}
.onDelete { indexSet in
guard let index = indexSet.first else { return }
let process = processes[index]
toDisable.append(process.procName)
updateProcesses()
if filteredProcesses.isEmpty {
VStack {
Text("No daemons found.")
.foregroundColor(.secondary)
.font(.title)
.padding()
.multilineTextAlignment(.center)
Text("This isn't normal. Is the app sandboxed ? Try installing Geranium with TrollStore.")
.foregroundColor(.secondary)
.font(.footnote)
.multilineTextAlignment(.center)
}
}
.toolbar{
ToolbarItem(placement: .navigationBarLeading) {
Text("Daemons")
.font(.title2)
.bold()
else {
List {
SearchBar(text: $searchText)
ForEach(filteredProcesses) { process in
HStack {
Text("Name: \(process.procName)")
.foregroundColor(toDisable.contains(process.procName) ? .red : .primary)
}
}
.onDelete { indexSet in
guard let index = indexSet.first else { return }
let process = processes[index]
toDisable.append(process.procName)
updateProcesses()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
//MARK: Probably the WORST EVER WAY to define a daemon's bundle ID. I'll try over objc s0n
for process in toDisable {
UIApplication.shared.confirmAlert(title: "Are you sure you want to disable \(process) ?", body: "You can undo this action before you reboot by going to the manager icon.", onOK: {
daemonManagement(key: "com.apple.\(process)", value: true, plistPath: "/var/db/com.apple.xpc.launchd/disabled.plist")
}, noCancel: false)
.toolbar{
ToolbarItem(placement: .navigationBarLeading) {
Text("Daemons")
.font(.title2)
.bold()
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
//MARK: Probably the WORST EVER WAY to define a daemon's bundle ID. I'll try over objc s0n
for process in toDisable {
UIApplication.shared.confirmAlert(title: "Are you sure you want to disable \(process) ?", body: "You can undo this action before you reboot by going to the manager icon.", onOK: {
daemonManagement(key: "com.apple.\(process)", value: true, plistPath: "/var/db/com.apple.xpc.launchd/disabled.plist")
}, noCancel: false)
}
if toDisable == [] {
UIApplication.shared.alert(title: "You didn't select any daemon", body: "Please swipe a running daemon to the left to disable it.")
}
}) {
Image(systemName: "checkmark")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24, height: 24)
}
if toDisable == [] {
UIApplication.shared.alert(title: "You didn't select any daemon", body: "Please swipe a running daemon to the left to disable it.")
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
var error = RootHelper.copy(from: URL(fileURLWithPath: "/var/db/com.apple.xpc.launchd/disabled.plist"), to: URL(fileURLWithPath: "/var/mobile/Documents/disabled.plist"))
print(error)
error = RootHelper.setPermission(url: URL(fileURLWithPath: "/var/mobile/Documents/disabled.plist"))
manageSheet.toggle()
}) {
Image(systemName: "list.bullet")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24, height: 24)
}
}) {
Image(systemName: "checkmark")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24, height: 24)
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
var error = RootHelper.copy(from: URL(fileURLWithPath: "/var/db/com.apple.xpc.launchd/disabled.plist"), to: URL(fileURLWithPath: "/var/mobile/Documents/disabled.plist"))
print(error)
error = RootHelper.setPermission(url: URL(fileURLWithPath: "/var/mobile/Documents/disabled.plist"))
manageSheet.toggle()
}) {
Image(systemName: "list.bullet")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24, height: 24)
}
.onAppear {
startTimer()
}
}
.onAppear {
startTimer()
}
.onDisappear {
stopTimer()
}
.sheet(isPresented: $isDaemonFirstRun) {
if #available(iOS 16.0, *) {
NavigationStack {
DaemonWelcomeView()
}
} else {
NavigationView {
DaemonWelcomeView()
.onDisappear {
stopTimer()
}
.sheet(isPresented: $isDaemonFirstRun) {
if #available(iOS 16.0, *) {
NavigationStack {
DaemonWelcomeView()
}
} else {
NavigationView {
DaemonWelcomeView()
}
}
}
}
.sheet(isPresented:$manageSheet) {
CurrentlyDisabledDaemonView()
.sheet(isPresented:$manageSheet) {
CurrentlyDisabledDaemonView()
}
}
}

Expand Down

0 comments on commit e2a5ec2

Please sign in to comment.