Skip to content

Commit

Permalink
Mark deleting bottles as in-flight
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jul 2, 2023
1 parent f44de67 commit 84691a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Whisky/Models/Bottle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions Whisky/Models/BottleVMEntries.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -46,6 +51,7 @@ class BottleVMEntries {
encode()
}
}

@discardableResult
func decode() -> Bool {
let decoder = PropertyListDecoder()
Expand All @@ -61,6 +67,7 @@ class BottleVMEntries {
return false
}
}

@discardableResult
public func encode() -> Bool {
let encoder = PropertyListEncoder()
Expand Down

0 comments on commit 84691a4

Please sign in to comment.