mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-20 20:23:25 +01:00
Prevents deleting legacy sideloaded apps
This commit is contained in:
@@ -20,6 +20,8 @@ extension UserDefaults
|
|||||||
@NSManaged var isDebugModeEnabled: Bool
|
@NSManaged var isDebugModeEnabled: Bool
|
||||||
@NSManaged var presentedLaunchReminderNotification: Bool
|
@NSManaged var presentedLaunchReminderNotification: Bool
|
||||||
|
|
||||||
|
@NSManaged var legacySideloadedApps: [String]?
|
||||||
|
|
||||||
func registerDefaults()
|
func registerDefaults()
|
||||||
{
|
{
|
||||||
self.register(defaults: [#keyPath(UserDefaults.isBackgroundRefreshEnabled): true])
|
self.register(defaults: [#keyPath(UserDefaults.isBackgroundRefreshEnabled): true])
|
||||||
|
|||||||
@@ -56,6 +56,18 @@ extension AppManager
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
let installedApps = try context.fetch(fetchRequest)
|
let installedApps = try context.fetch(fetchRequest)
|
||||||
|
|
||||||
|
if UserDefaults.standard.legacySideloadedApps == nil
|
||||||
|
{
|
||||||
|
// First time updating apps since updating AltStore to use custom UTIs,
|
||||||
|
// so cache all existing apps temporarily to prevent us from accidentally
|
||||||
|
// deleting them due to their custom UTI not existing (yet).
|
||||||
|
let apps = installedApps.map { $0.bundleIdentifier }
|
||||||
|
UserDefaults.standard.legacySideloadedApps = apps
|
||||||
|
}
|
||||||
|
|
||||||
|
let legacySideloadedApps = Set(UserDefaults.standard.legacySideloadedApps ?? [])
|
||||||
|
|
||||||
for app in installedApps
|
for app in installedApps
|
||||||
{
|
{
|
||||||
let uti = UTTypeCopyDeclaration(app.installedAppUTI as CFString)?.takeRetainedValue() as NSDictionary?
|
let uti = UTTypeCopyDeclaration(app.installedAppUTI as CFString)?.takeRetainedValue() as NSDictionary?
|
||||||
@@ -66,12 +78,10 @@ extension AppManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if uti == nil && !UIApplication.shared.canOpenURL(app.openAppURL)
|
if uti == nil && !legacySideloadedApps.contains(app.bundleIdentifier)
|
||||||
{
|
{
|
||||||
// This UTI is not declared by any apps, which means this app has been deleted by the user.
|
// This UTI is not declared by any apps, which means this app has been deleted by the user.
|
||||||
// We also check canOpenURL as a fallback for apps installed before we switched to using custom UTIs.
|
// This app is also not a legacy sideloaded app, so we can assume it's fine to delete it.
|
||||||
// canOpenURL always returns NO for apps not declared in our Info.plist,
|
|
||||||
// so it should not affect UTI-based installation checks.
|
|
||||||
context.delete(app)
|
context.delete(app)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,6 +438,12 @@ private extension AppManager
|
|||||||
do { try installedApp.managedObjectContext?.save() }
|
do { try installedApp.managedObjectContext?.save() }
|
||||||
catch { print("Error saving installed app.", error) }
|
catch { print("Error saving installed app.", error) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let index = UserDefaults.standard.legacySideloadedApps?.firstIndex(of: installedApp.bundleIdentifier)
|
||||||
|
{
|
||||||
|
// No longer a legacy sideloaded app, so remove it from cached list.
|
||||||
|
UserDefaults.standard.legacySideloadedApps?.remove(at: index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Finished operation!", context.bundleIdentifier)
|
print("Finished operation!", context.bundleIdentifier)
|
||||||
|
|||||||
Reference in New Issue
Block a user