mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltStoreCore] Updates DatabaseManager to support #Preview macro
Synchronously loads database via startForPreview(), and also erases database for DEBUG builds.
This commit is contained in:
@@ -86,8 +86,24 @@ public extension DatabaseManager
|
||||
|
||||
guard !self.isStarted else { return finish(nil) }
|
||||
|
||||
if self.persistentContainer.isMigrationRequired {
|
||||
|
||||
#if DEBUG
|
||||
// Wrap in #if DEBUG to *ensure* we never accidentally delete production databases.
|
||||
if ProcessInfo.processInfo.isPreview
|
||||
{
|
||||
do
|
||||
{
|
||||
print("!!! Purging database for preview...")
|
||||
try FileManager.default.removeItem(at: PersistentContainer.defaultDirectoryURL())
|
||||
}
|
||||
catch
|
||||
{
|
||||
print("Failed to remove database directory for preview.", error)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if self.persistentContainer.isMigrationRequired
|
||||
{
|
||||
// Quit any other running AltStore processes to prevent concurrent database access during and after migration.
|
||||
self.ignoreWillMigrateDatabaseNotification = true
|
||||
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), .willMigrateDatabase, nil, nil, true)
|
||||
@@ -164,6 +180,22 @@ public extension DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
public extension DatabaseManager
|
||||
{
|
||||
func startForPreview()
|
||||
{
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
|
||||
self.dispatchQueue.async {
|
||||
self.startCompletionHandlers.append { error in
|
||||
semaphore.signal()
|
||||
}
|
||||
}
|
||||
|
||||
semaphore.wait()
|
||||
}
|
||||
}
|
||||
|
||||
public extension DatabaseManager
|
||||
{
|
||||
var viewContext: NSManagedObjectContext {
|
||||
|
||||
Reference in New Issue
Block a user