Fix more queue regressions.

This commit is contained in:
Damiano Galassi committed 2019-01-29 11:22:31 +01:00
1 parent 7fffcd3916
commit 6d71efe9b4
3 files changed
+22 -9

No files matched your search

+3 -1
View File
@@ -58,7 +58,9 @@ class ItemViewController : NSViewController {
guard let s = self, let newCount = change.newValue?.count else { return } guard let s = self, let newCount = change.newValue?.count else { return }
let count = newCount - (change.oldValue?.count ?? 0) let count = newCount - (change.oldValue?.count ?? 0)
let height = 16.0 * CGFloat(count >= 0 ? count : 1) let height = 16.0 * CGFloat(count >= 0 ? count : 1)
s.tableHeight.constant = height DispatchQueue.main.async {
s.tableHeight.constant = height
}
} }
} }
+12 -3
View File
@@ -25,6 +25,7 @@ class Queue {
private var cancelled: Bool private var cancelled: Bool
private var currentItem: QueueItem? private var currentItem: QueueItem?
private var currentIndex: Int
private let url: URL private let url: URL
@@ -38,6 +39,7 @@ class Queue {
url = queueURL url = queueURL
statusInternal = .unknown statusInternal = .unknown
cancelled = false cancelled = false
currentIndex = -1
workQueue = DispatchQueue(label: "org.subler.WorkQueue") workQueue = DispatchQueue(label: "org.subler.WorkQueue")
arrayQueue = DispatchQueue(label: "org.subler.SaveQueue") arrayQueue = DispatchQueue(label: "org.subler.SaveQueue")
@@ -77,11 +79,13 @@ class Queue {
private func process(_ item: QueueItem) -> ProcessResult { private func process(_ item: QueueItem) -> ProcessResult {
return autoreleasepool { () -> ProcessResult in return autoreleasepool { () -> ProcessResult in
let index = self.index(of: item)
self.arrayQueue.sync { self.arrayQueue.sync {
self.currentItem = currentItem self.currentItem = item
self.currentIndex = index
} }
let index = self.index(of: item)
item.status = .working item.status = .working
item.delegate = self item.delegate = self
@@ -89,6 +93,7 @@ class Queue {
item.delegate = nil item.delegate = nil
self.arrayQueue.sync { self.arrayQueue.sync {
self.currentItem = nil self.currentItem = nil
self.currentIndex = -1
} }
} }
@@ -319,7 +324,11 @@ class Queue {
// MARK: Notifications // MARK: Notifications
func updateProgress(_ progress: Double) { func updateProgress(_ progress: Double) {
handleSBStatusWorking(progress: progress, index: -1) var currentIndex = -1
arrayQueue.sync {
currentIndex = self.currentIndex
}
handleSBStatusWorking(progress: progress, index: currentIndex)
} }
/// Processes SBQueueStatusWorking state information. Current implementation just /// Processes SBQueueStatusWorking state information. Current implementation just
+7 -5
View File
@@ -113,15 +113,19 @@ class QueueItem: NSObject, NSSecureCoding {
} }
func addAction(_ action: QueueActionProtocol) { func addAction(_ action: QueueActionProtocol) {
willChangeValue(for: \.actions)
queue.sync { queue.sync {
actionsInternal.append(action) actionsInternal.append(action)
} }
didChangeValue(for: \.actions)
} }
func removeAction(at index: Int) { func removeAction(at index: Int) {
willChangeValue(for: \.actions)
_ = queue.sync { _ = queue.sync {
actionsInternal.remove(at: index) actionsInternal.remove(at: index)
} }
didChangeValue(for: \.actions)
} }
// MARK: Item processing // MARK: Item processing
@@ -292,8 +296,7 @@ class QueueItem: NSObject, NSSecureCoding {
guard let mp4 = mp4File else { return } guard let mp4 = mp4File else { return }
weak var weakSelf = self mp4.progressHandler = { [weak self] in self?.delegate?.updateProgress($0) }
mp4.progressHandler = { (progress) in weakSelf?.delegate?.updateProgress(progress) }
// Check if there is enough space on the destination disk // Check if there is enough space on the destination disk
if filePathURL != destURL { if filePathURL != destURL {
@@ -313,13 +316,12 @@ class QueueItem: NSObject, NSSecureCoding {
} }
} }
// Optimize the file
if cancelled == false { if cancelled == false {
if let action = actions.first(where: { $0.type == .post }) { for action in actions.filter( { $0.type == .post }) {
localizedWorkingDescription = action.localizedDescription localizedWorkingDescription = action.localizedDescription
delegate?.updateProgress(0) delegate?.updateProgress(0)
let result = action.runAction(self) let result = action.runAction(self)
if result == false { if result == false, let _ = action as? QueueOptimizeAction {
throw ProcessError.optimizationFailure throw ProcessError.optimizationFailure
} }
} }