Skip to content

Commit 36b1380

Browse files
committed
Should fix some startup crashes
1 parent 41ea137 commit 36b1380

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Sources/ContentView.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,9 @@ Thanks to:
262262
}
263263

264264
func bindingForAppleIntelligence() -> Binding<Bool> {
265-
guard let cacheVersion = mobileGestalt["CacheVersion"] else {
265+
guard let cacheExtra = mobileGestalt["CacheExtra"] as? NSMutableDictionary else {
266266
return State(initialValue: false).projectedValue
267267
}
268-
269-
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
270268
let key = "A62OafQ85EJAiiqKn4agtg"
271269
return Binding(
272270
get: {
@@ -291,7 +289,9 @@ Thanks to:
291289
}
292290

293291
func bindingForRegionRestriction() -> Binding<Bool> {
294-
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
292+
guard let cacheExtra = mobileGestalt["CacheExtra"] as? NSMutableDictionary else {
293+
return State(initialValue: false).projectedValue
294+
}
295295
return Binding<Bool>(
296296
get: {
297297
return cacheExtra["h63QSdBCiT/z0WU6rdQv6Q"] as? String == "US" &&
@@ -310,16 +310,14 @@ Thanks to:
310310
}
311311

312312
func bindingForTrollPad() -> Binding<Bool> {
313-
guard let cacheVersion = mobileGestalt["CacheVersion"] else {
313+
// We're going to overwrite DeviceClassNumber but we can't do it via CacheExtra, so we need to do it via CacheData instead
314+
guard let cacheData = mobileGestalt["CacheData"] as? NSMutableData,
315+
let cacheExtra = mobileGestalt["CacheExtra"] as? NSMutableDictionary else {
314316
return State(initialValue: false).projectedValue
315317
}
316-
317-
// We're going to overwrite DeviceClassNumber but we can't do it via CacheExtra, so we need to do it via CacheData instead
318318
let valueOffset = UserDefaults.standard.integer(forKey: "MGCacheDataDeviceClassNumberOffset")
319-
let cacheData = mobileGestalt["CacheData"] as! NSMutableData
320319
//print("Read value from \(cacheData.mutableBytes.load(fromByteOffset: valueOffset, as: Int.self))")
321320

322-
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
323321
let keys = [
324322
"uKc7FPnEO++lVhHWHFlGbQ", // ipad
325323
"mG0AnH/Vy1veoqoLRAIgTA", // MedusaFloatingLiveAppCapability
@@ -350,11 +348,9 @@ Thanks to:
350348
}
351349

352350
func bindingForMGKeys<T: Equatable>(_ keys: [String], type: T.Type = Int.self, defaultValue: T? = 0, enableValue: T? = 1) -> Binding<Bool> {
353-
guard let cacheVersion = mobileGestalt["CacheVersion"] else {
351+
guard let cacheExtra = mobileGestalt["CacheExtra"] as? NSMutableDictionary else {
354352
return State(initialValue: false).projectedValue
355353
}
356-
357-
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
358354
return Binding(
359355
get: {
360356
if let value = cacheExtra[keys.first!] as? T?, let enableValue {

0 commit comments

Comments
 (0)