Skip to content

Commit 5a20390

Browse files
committed
Add some nugget tweaks?
1 parent e95dc3e commit 5a20390

3 files changed

Lines changed: 217 additions & 0 deletions

File tree

lara/classes/laramgr.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,61 @@ final class laramgr: ObservableObject {
561561
return appList
562562
}
563563

564+
func setplistvalue(path: String, key: (key: String, value: Any?), force: Bool = false) -> (ok: Bool, message: String) {
565+
do {
566+
let fm = FileManager.default
567+
if !fm.fileExists(atPath: path) && !force {
568+
return (false, "file at \(path) does not exist or couldn't be found")
569+
}
570+
if var dict = try NSMutableDictionary(contentsOf: URL(fileURLWithPath: path)) ?? [:] {
571+
if let value = key.value {
572+
dict[key.key] = value
573+
} else {
574+
dict.removeObject(forKey: key.key)
575+
}
576+
let data = try PropertyListSerialization.data(
577+
fromPropertyList: dict,
578+
format: .binary,
579+
options: 0
580+
)
581+
let result = self.lara_overwritefile(
582+
target: path,
583+
data: data
584+
)
585+
if result.ok {
586+
return (true, "overwrote plist at path \(path)")
587+
} else {
588+
return(false, "overwrite failed: \(result.message)")
589+
}
590+
} else {
591+
return(false, "could not convert plist at \(path) to readable data")
592+
}
593+
} catch {
594+
return (false, "an error occured: \(error)")
595+
}
596+
}
597+
598+
func getplistvalue(path: String, key: String) -> (ok: Bool, message: String, value: Any?) {
599+
do {
600+
let fm = FileManager.default
601+
if fm.fileExists(atPath: path) {
602+
if let dict = try NSDictionary(contentsOf: URL(fileURLWithPath: path)) {
603+
if let value = dict[key] {
604+
return (true, "success", value)
605+
} else {
606+
return (false, "key \(key) not found", nil)
607+
}
608+
} else {
609+
return(false, "could not convert plist at \(path) to readable data", nil)
610+
}
611+
} else {
612+
return (false, "file at \(path) does not exist or couldn't be found", nil)
613+
}
614+
} catch {
615+
return (false, "an error occured: \(error)", nil)
616+
}
617+
}
618+
564619
@discardableResult
565620
func apfsown(path: String, uid: UInt32, gid: UInt32) -> Bool {
566621
if !isapfs(path) {

lara/views/tweaks/MiscView.swift

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//
2+
// MiscView.swift
3+
// lara
4+
//
5+
// Created by jurre111 on 14.04.26.
6+
// Mostly copied from/inspired by nugget from leminlimez
7+
//
8+
9+
import SwiftUI
10+
11+
// ported from nugget, but kinda unnecessary
12+
enum FileLocation: String, CaseIterable {
13+
// Mobile Gestalt
14+
// case resolution = "/var/Managed Preferences/mobile/com.apple.iokit.IOMobileGraphicsFamily.plist"
15+
// case mga = "/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/com.apple.MobileGestalt.plist"
16+
17+
// Feature Flags
18+
// case featureflags = "/var/preferences/FeatureFlags/Global.plist"
19+
20+
// Springboard Options
21+
case springboard = "/var/Managed Preferences/mobile/com.apple.springboard.plist"
22+
case footnote = "/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles/Library/ConfigurationProfiles/SharedDeviceConfiguration.plist"
23+
case airdrop = "/var/Managed Preferences/mobile/com.apple.sharingd.plist"
24+
case nanoregistry = "/var/mobile/Library/Preferences/com.apple.NanoRegistry.plist"
25+
26+
// Internal Options
27+
case globalPreferences = "/var/Managed Preferences/mobile/.GlobalPreferences.plist"
28+
case appStore = "/var/Managed Preferences/mobile/com.apple.AppStore.plist"
29+
case backboardd = "/var/Managed Preferences/mobile/com.apple.backboardd.plist"
30+
case coreMotion = "/var/Managed Preferences/mobile/com.apple.CoreMotion.plist"
31+
case pasteboard = "/var/Managed Preferences/mobile/com.apple.Pasteboard.plist"
32+
case notes = "/var/Managed Preferences/mobile/com.apple.mobilenotes.plist"
33+
case uikit = "/var/Managed Preferences/mobile/com.apple.UIKit.plist"
34+
35+
// Daemons
36+
// case disabledDaemons = "/var/db/com.apple.xpc.launchd/disabled.plist"
37+
// case screentime = "/var/mobile/Library/Preferences/ScreenTimeAgent.plist"
38+
39+
// Risky Options
40+
// case ota = "/var/Managed Preferences/mobile/com.apple.MobileAsset.plist"
41+
}
42+
43+
struct tweak: Identifiable {
44+
let id: String
45+
let name: String
46+
let path: String
47+
let key: String
48+
var state: (og: Bool, enabled: Bool)
49+
var readfailed: Bool
50+
51+
init(name: String, path: String, key: String) {
52+
self.id = URL(fileURLWithPath: path).lastPathComponent + "_" + key
53+
self.name = name
54+
self.path = path
55+
self.key = key
56+
// og is the original value at the moment the page loads
57+
// enabled is the current selected value in the view
58+
self.state = (og: false, enabled: false)
59+
self.readfailed = false
60+
}
61+
}
62+
63+
64+
struct MiscView: View {
65+
@ObservedObject private var mgr = laramgr.shared
66+
let fm = FileManager.default
67+
@State private var tweaks: [tweak] = [
68+
tweak(name: "Disable lock after respring", path: FileLocation.springboard.rawValue, key: "SBDontLockAfterCrash"),
69+
tweak(name: "Disable low power alerts", path: FileLocation.springboard.rawValue, key: "SBHideLowPowerAlerts"),
70+
tweak(name: "Enable airplay support", path: FileLocation.springboard.rawValue, key: "SBExtendedDisplayOverrideSupportForAirPlayAndDontFileRadars"),
71+
tweak(name: "Disable airdrop time limit", path: FileLocation.airdrop.rawValue, key: "OverrideTimeLimitEveryoneMode"),
72+
tweak(name: "Hide respring icon", path: FileLocation.backboardd.rawValue, key: "BKHideAppleLogoOnLaunch"),
73+
tweak(name: "Show Dynamic Island in screenshots", path: FileLocation.springboard.rawValue, key: "SBAlwaysShowSystemApertureInSnapshots"),
74+
tweak(name: "Disable screen dimming while charging", path: FileLocation.springboard.rawValue, key: "SBDontDimOrLockOnAC")
75+
]
76+
77+
var body: some View {
78+
List {
79+
Section {
80+
Button("Apply") {
81+
apply()
82+
}
83+
Button("Revert") {
84+
revert()
85+
}
86+
}
87+
Section {
88+
ForEach(tweaks.indices, id: \.self) { index in
89+
Toggle(tweaks[index].name, isOn: $tweaks[index].state.enabled)
90+
.disabled(tweaks[index].readfailed)
91+
}
92+
} header: {
93+
Text("Miscellaneous Tweaks")
94+
}
95+
}
96+
.refreshable {
97+
load()
98+
}
99+
.onAppear {
100+
load()
101+
}
102+
}
103+
104+
private func load() {
105+
checkplists()
106+
for (index, tweak) in tweaks.enumerated() {
107+
if fm.fileExists(atPath: tweak.path) {
108+
let result = mgr.getplistvalue(path: tweak.path, key: tweak.key)
109+
if result.ok, let value = result.value as? Bool {
110+
tweaks[index].state.og = value
111+
continue
112+
} else {
113+
if !(result.message == "key \(tweak.key) not found") {
114+
mgr.logmsg("Failed to read \(tweak.path): \(result.message)")
115+
tweaks[index].readfailed = true
116+
continue
117+
}
118+
}
119+
}
120+
// this happens when the file doesnt exist or the doesnt exist which can happen if the tweak is disabled
121+
tweaks[index].state.og = false
122+
}
123+
}
124+
125+
func apply() {
126+
// check if the tweak was modified, else just leave it
127+
for tweak in tweaks where tweak.state.og != tweak.state.enabled {
128+
let result = mgr.setplistvalue(path: tweak.path, key: (tweak.key, tweak.state.enabled ? true : nil), force: true)
129+
if !result.ok {
130+
mgr.logmsg("Failed to set \(tweak.key) at \(tweak.path): \(result.message)")
131+
}
132+
}
133+
load()
134+
}
135+
136+
// removes all keys from the plist files and reloads (this also calls checkplists())
137+
func revert() {
138+
for tweak in tweaks {
139+
let result = mgr.setplistvalue(path: tweak.path, key: (tweak.key, nil))
140+
if !result.ok {
141+
mgr.logmsg("Failed to remove key \(tweak.key) at \(tweak.path): \(result.message)")
142+
}
143+
}
144+
load()
145+
}
146+
147+
// this will remove any empty plist files
148+
func checkplists() {
149+
for path in FileLocation.allCases.map(\.rawValue) {
150+
if fm.fileExists(atPath: path) {
151+
if let data = try?Data(contentsOf: URL(fileURLWithPath: path)), data.count == 0 {
152+
try? fm.removeItem(atPath: path)
153+
}
154+
if let dict = NSDictionary(contentsOf: URL(fileURLWithPath: path)), dict.count == 0 {
155+
try? fm.removeItem(atPath: path)
156+
}
157+
}
158+
}
159+
}
160+
}

lara/views/tweaks/TweaksView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ struct TweaksView: View {
5555
.disabled(!mgr.sbxready)
5656
NavigationLink("Custom Overwrite", destination: CustomView(mgr: mgr))
5757
.disabled(!mgr.vfsready)
58+
NavigationLink("Miscellaneous Tweaks", destination: MiscView())
59+
.disabled(!mgr.sbxready || !mgr.vfsready)
5860
}
5961

6062
NavigationLink("Extra Tools", destination: ToolsView())

0 commit comments

Comments
 (0)