Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import Observationimport ParcelEngine
@MainActor @Observablefinal class SetupActionModel { let coordinator: SetupCoordinator private var unreportedFailure: String? var failure: String? { coordinator.failure ?? unreportedFailure } private(set) var isRunning = false @ObservationIgnored private var task: Task<Void, Never>? @ObservationIgnored var onCompletion: (@MainActor () -> Void)?
init(coordinator: SetupCoordinator) { self.coordinator = coordinator }
var isBusy: Bool { isRunning || coordinator.isBusy }
func run(_ action: SetupAction) { guard !isBusy else { return } isRunning = true unreportedFailure = nil task = Task { [weak self] in guard let self else { return } await execute(action) isRunning = false task = nil onCompletion?() } }
func perform(_ action: SetupAction) async -> Bool { guard !isBusy else { return false } isRunning = true unreportedFailure = nil defer { isRunning = false } return await execute(action) }
@discardableResult private func execute(_ action: SetupAction) async -> Bool { do { switch action { case .open(let id): try await coordinator.open(id) case .update(let id): try await coordinator.update(id) case .delete(let id): try await coordinator.delete(id) case .undoDelete: try await coordinator.undoDelete() case .move(let id, let index): try await coordinator.move(id, to: index) } return true } catch is CancellationError { return false } catch { unreportedFailure = coordinator.failure == nil ? error.localizedDescription : nil return false } }
func stop() { task?.cancel() }
deinit { task?.cancel() }}