From 84691a45ed8e6b63f6a93cb6979b41613224ad9a Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sun, 2 Jul 2023 16:04:24 +0100 Subject: [PATCH] Mark deleting bottles as in-flight --- Whisky/Models/Bottle.swift | 3 +++ Whisky/Models/BottleVMEntries.swift | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/Whisky/Models/Bottle.swift b/Whisky/Models/Bottle.swift index 1e4ced79c..02acf0c38 100644 --- a/Whisky/Models/Bottle.swift +++ b/Whisky/Models/Bottle.swift @@ -121,6 +121,9 @@ public class Bottle: Hashable, Identifiable { @MainActor func delete() { do { + if let bottle = BottleVM.shared.bottles.first(where: { $0.url == url}) { + bottle.inFlight = true + } try FileManager.default.removeItem(at: url) if let path = BottleVM.shared.bottlesList.paths.firstIndex(of: url) { BottleVM.shared.bottlesList.paths.remove(at: path) diff --git a/Whisky/Models/BottleVMEntries.swift b/Whisky/Models/BottleVMEntries.swift index 2e1111052..5a6ea2a40 100644 --- a/Whisky/Models/BottleVMEntries.swift +++ b/Whisky/Models/BottleVMEntries.swift @@ -18,14 +18,17 @@ class BottleVMEntries { .appendingPathComponent("Library") .appendingPathComponent("Containers") .appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.isaacmarovitz.Whisky") + static let bottleEntriesDir = containerDir .appendingPathComponent("BottleVM") .appendingPathExtension("plist") + private var file: BottleEntries { didSet { encode() } } + var paths: [URL] { get { file.paths @@ -34,9 +37,11 @@ class BottleVMEntries { file.paths = newValue } } + static func exists() -> Bool { return FileManager.default.fileExists(atPath: Self.bottleEntriesDir.path()) } + init() { file = .init() if !Self.exists() { @@ -46,6 +51,7 @@ class BottleVMEntries { encode() } } + @discardableResult func decode() -> Bool { let decoder = PropertyListDecoder() @@ -61,6 +67,7 @@ class BottleVMEntries { return false } } + @discardableResult public func encode() -> Bool { let encoder = PropertyListEncoder()