Remove an unneeded var.

This commit is contained in:
Damiano Galassi committed 2019-02-08 14:36:29 +01:00
1 parent 51eaa922be
commit db374f209f
1 file changed
+4 -14
+4 -14
View File
@@ -25,7 +25,6 @@ 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
@@ -39,7 +38,6 @@ 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")
@@ -79,11 +77,8 @@ 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 = item self.currentItem = item
self.currentIndex = index
} }
item.status = .working item.status = .working
@@ -93,11 +88,10 @@ class Queue {
item.delegate = nil item.delegate = nil
self.arrayQueue.sync { self.arrayQueue.sync {
self.currentItem = nil self.currentItem = nil
self.currentIndex = -1
} }
} }
self.handleSBStatusWorking(progress: 0, index: index) self.handleSBStatusWorking(progress: 0, index: self.index(of: item))
do { do {
try item.process() try item.process()
@@ -112,7 +106,7 @@ class Queue {
return .cancelled return .cancelled
} else { } else {
item.status = .completed item.status = .completed
self.handleSBStatusWorking(progress: 100, index: index) self.handleSBStatusWorking(progress: 100, index: self.index(of: item))
return .completed return .completed
} }
} catch { } catch {
@@ -324,18 +318,14 @@ class Queue {
// MARK: Notifications // MARK: Notifications
func updateProgress(_ progress: Double) { func updateProgress(_ progress: Double) {
var currentIndex = -1 handleSBStatusWorking(progress: progress, index: -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
/// sends SBQueueWorkingNotification. /// sends SBQueueWorkingNotification.
private func handleSBStatusWorking(progress: Double, index: Int) { private func handleSBStatusWorking(progress: Double, index: Int) {
let itemDescription = currentItem?.localizedWorkingDescription ?? NSLocalizedString("Working", comment: "Queue Working.") let itemDescription = currentItem?.localizedWorkingDescription ?? NSLocalizedString("Working", comment: "Queue Working.")
let info = String.localizedStringWithFormat(NSLocalizedString("%@, item %ld.", comment: ""), itemDescription, index + 1) let info = String.localizedStringWithFormat(NSLocalizedString("%@.", comment: ""), itemDescription)
NotificationCenter.default.post(name: Queue.Working, object: self, userInfo: ["ProgressString": info, "Progress": progress, "ItemIndex": index]) NotificationCenter.default.post(name: Queue.Working, object: self, userInfo: ["ProgressString": info, "Progress": progress, "ItemIndex": index])
} }