Skip to content

Commit

Permalink
compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleduo committed Mar 28, 2018
1 parent 2321c79 commit c3a105e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions source/tinypng4mac/model/TPTaskInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TPTaskInfo: NSObject {
var resultSize: Double
var uuid: String
var errorMessage: String?
var index: Int

init(originFile: URL, fileName: String, originSize: Double) {
self.originFile = originFile
Expand All @@ -35,6 +36,7 @@ class TPTaskInfo: NSObject {
self.resultSize = 0
self.uuid = UUID().uuidString
self.errorMessage = nil
self.index = 0
}
}

Expand Down
15 changes: 11 additions & 4 deletions source/tinypng4mac/tpclient/TPStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ class TPStore {
fileprivate init() {}

func add(_ task: TPTaskInfo) {
task.index = self.tasks.count
self.tasks.append(task)
}

func add(_ tasks: [TPTaskInfo]) {
var start = self.tasks.count
for t in tasks {
t.index = start
start = start + 1
}
self.tasks = self.tasks + tasks
}

Expand All @@ -30,6 +36,9 @@ class TPStore {
}

func remove(_ task: TPTaskInfo) -> TPTaskInfo? {
if self.tasks.count == 0 {
return nil;
}
let index = self.tasks.index(where: {$0.uuid == task.uuid})
if let i = index {
return self.tasks.remove(at: i)
Expand All @@ -56,15 +65,13 @@ class TPStore {
}

func sort() {
tasks.sort { (first, second) -> Bool in
let fi = indexOf(first)
let si = indexOf(second)
self.tasks.sort { (first, second) -> Bool in
if first.status == .error && second.status != .error {
return true
} else if first.status != .finish && second.status == .finish {
return true
}
return fi < si
return false
}
}
}

0 comments on commit c3a105e

Please sign in to comment.