diff --git a/AltStore/Operations/InstallAppOperation.swift b/AltStore/Operations/InstallAppOperation.swift index 547eccec..0f1e47bd 100644 --- a/AltStore/Operations/InstallAppOperation.swift +++ b/AltStore/Operations/InstallAppOperation.swift @@ -176,6 +176,13 @@ final class InstallAppOperation: ResultOperation var installing = true if installedApp.storeApp?.bundleIdentifier.range(of: Bundle.Info.appbundleIdentifier) != nil { + do { + // we need to flush changes to the disk now in case the changes are lost when iOS kills current process + try installedApp.managedObjectContext?.save() + } catch { + print("Failed to flush installedApp to disk: \(error)") + } + // Reinstalling ourself will hang until we leave the app, so we need to exit it without force closing DispatchQueue.main.asyncAfter(deadline: .now() + 3) { if UIApplication.shared.applicationState != .active { diff --git a/AltStoreCore/Model/DatabaseManager/DatabaseManager.swift b/AltStoreCore/Model/DatabaseManager/DatabaseManager.swift index 0dd2080c..bd41b077 100644 --- a/AltStoreCore/Model/DatabaseManager/DatabaseManager.swift +++ b/AltStoreCore/Model/DatabaseManager/DatabaseManager.swift @@ -399,6 +399,40 @@ private extension DatabaseManager // For backwards compatibility reasons, we cannot use localApp's buildVersion as storeBuildVersion, // or else the latest update will _always_ be considered new because we don't use buildVersions in our source (yet). installedApp = InstalledApp(resignedApp: localApp, originalBundleIdentifier: StoreApp.altstoreAppID, certificateSerialNumber: serialNumber, storeBuildVersion: nil, context: context) + + // figure out if the current AltStoreApp is signed with "Use Main Profie" option + // by checking if the first extension's entitlement's application-identifier matches current one + repeat { + guard let pluginURL = Bundle.main.builtInPlugInsURL else { + installedApp.useMainProfile = true + break + } + guard let pluginFolders = try? FileManager.default.contentsOfDirectory(at: pluginURL, includingPropertiesForKeys: nil) else { + installedApp.useMainProfile = true + break + } + + guard let pluginFolder = pluginFolders.first, let altPluginApp = ALTApplication(fileURL: pluginFolder) else { + installedApp.useMainProfile = true + break + } + + let entitlements = altPluginApp.entitlements + guard let appId = entitlements[ALTEntitlement.applicationIdentifier] as? String else { + installedApp.useMainProfile = false + print("no ALTEntitlementApplicationIdentifier???") + break + } + + if appId.hasSuffix(Bundle.main.bundleIdentifier!) { + installedApp.useMainProfile = true + } else { + installedApp.useMainProfile = false + } + + + } while(false) + installedApp.storeApp = storeApp }