diff --git a/lara/views/tweaks/OTAView.swift b/lara/views/tweaks/OTAView.swift index da79720c..32951cf7 100644 --- a/lara/views/tweaks/OTAView.swift +++ b/lara/views/tweaks/OTAView.swift @@ -51,14 +51,14 @@ struct OTAView: View { } } .disabled(isWorking || !otaDisabled) - - Button("Respring") { - mgr.respring() - } - .disabled(isWorking) } } .navigationTitle("OTA Updates") + .onAppear { + if !otaDisabled { + syncStateFromPlist() + } + } .alert("Result", isPresented: .constant(lastResult != nil)) { Button("OK") { lastResult = nil } } message: { @@ -66,6 +66,28 @@ struct OTAView: View { } } + private func syncStateFromPlist() { + DispatchQueue.global(qos: .userInitiated).async { + let plistPath = "/private/var/db/com.apple.xpc.launchd/disabled.plist" + let daemonLabels = [ + "com.apple.mobile.softwareupdated", + "com.apple.OTATaskingAgent", + "com.apple.softwareupdateservicesd", + "com.apple.mobile.NRDUpdated", + ] + guard let data = NSData(contentsOfFile: plistPath) as Data?, + let plist = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: Any] else { + return + } + let allDisabled = daemonLabels.allSatisfy { (plist[$0] as? Bool) == true } + if allDisabled { + DispatchQueue.main.async { + otaDisabled = true + } + } + } + } + private func apply(disabled: Bool) { isWorking = true DispatchQueue.global(qos: .userInitiated).async { diff --git a/lara/views/tweaks/ScreenTimeView.swift b/lara/views/tweaks/ScreenTimeView.swift index fa997892..5796f813 100644 --- a/lara/views/tweaks/ScreenTimeView.swift +++ b/lara/views/tweaks/ScreenTimeView.swift @@ -80,14 +80,14 @@ struct ScreenTimeView: View { } } .disabled(isWorking || !screenTimeDisabled) - - Button("Respring") { - mgr.respring() - } - .disabled(isWorking) } } .navigationTitle("Screen Time") + .onAppear { + if !screenTimeDisabled { + syncStateFromPlist() + } + } .alert("Result", isPresented: .constant(lastResult != nil)) { Button("OK") { lastResult = nil } } message: { @@ -95,6 +95,26 @@ struct ScreenTimeView: View { } } + private func syncStateFromPlist() { + DispatchQueue.global(qos: .userInitiated).async { + let plistPath = "/private/var/db/com.apple.xpc.launchd/disabled.plist" + let daemonLabels = [ + "com.apple.ScreenTimeAgent", + "com.apple.UsageTrackingAgent", + ] + guard let data = NSData(contentsOfFile: plistPath) as Data?, + let plist = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: Any] else { + return + } + let allDisabled = daemonLabels.allSatisfy { (plist[$0] as? Bool) == true } + if allDisabled { + DispatchQueue.main.async { + screenTimeDisabled = true + } + } + } + } + private func applyDisable() { isWorking = true let agent = killScreenTimeAgent