From 6b4223a9d6d287871cc98e417f3654df98dda582 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 16 Apr 2023 13:31:10 -0400 Subject: [PATCH] Migrate drafts to new file --- .../Sources/ComposeUI/Model/DraftsManager.swift | 11 +++++++++++ Tusker/AppDelegate.swift | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Model/DraftsManager.swift b/Packages/ComposeUI/Sources/ComposeUI/Model/DraftsManager.swift index ef46ef08..5670f530 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Model/DraftsManager.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Model/DraftsManager.swift @@ -35,6 +35,17 @@ public class DraftsManager: Codable, ObservableObject { return DraftsManager() } + public static func migrate(from url: URL) -> Result { + do { + try? FileManager.default.removeItem(at: archiveURL) + try FileManager.default.moveItem(at: url, to: archiveURL) + } catch { + return .failure(error) + } + shared = load() + return .success(()) + } + private init() {} public required init(from decoder: Decoder) throws { diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index d4141592..aa64b5a8 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -11,6 +11,7 @@ import CoreData import OSLog import Sentry import UserAccounts +import ComposeUI let stateRestorationLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "StateRestoration") @@ -47,6 +48,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // no-op } } + + DispatchQueue.global(qos: .userInitiated).async { + let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! + let oldDraftsFile = documentsDirectory.appendingPathComponent("drafts").appendingPathExtension("plist") + if FileManager.default.fileExists(atPath: oldDraftsFile.path) { + if case .failure(let error) = DraftsManager.migrate(from: oldDraftsFile) { + SentrySDK.capture(error: error) + } + } + } return true }