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