diff --git a/mac/Sources/Byre/Store.swift b/mac/Sources/Byre/Store.swift index 509d1d8..742957b 100644 --- a/mac/Sources/Byre/Store.swift +++ b/mac/Sources/Byre/Store.swift @@ -511,6 +511,10 @@ final class Store { } func applyFocus(_ f: Focus) { + if f.projectId != focus.projectId { + markVisited(focus.projectId) + markVisited(f.projectId) + } focus = f if f.taskId != selectedTaskId { selectTask(f.taskId) @@ -662,14 +666,14 @@ final class Store { } } - private func markVisited(_ taskId: String?) { - guard let taskId else { + private func markVisited(_ id: String?) { + guard let id else { return } let at = Date().timeIntervalSince1970 * 1000 - let records = fetchRecords(FetchDescriptor(predicate: #Predicate { $0.taskId == taskId })) + let records = fetchRecords(FetchDescriptor(predicate: #Predicate { $0.taskId == id })) if records.isEmpty { - persistence.insert(VisitRecord(taskId: taskId, at: at)) + persistence.insert(VisitRecord(taskId: id, at: at)) } else { records[0].at = at for record in records.dropFirst() { diff --git a/mac/Sources/Byre/Switcher.swift b/mac/Sources/Byre/Switcher.swift index 2bcd49a..91167ae 100644 --- a/mac/Sources/Byre/Switcher.swift +++ b/mac/Sources/Byre/Switcher.swift @@ -234,19 +234,19 @@ final class SwitcherModel { } return a.i < b.i } + let focused = store.focusedProject()?.id + let used = store.projects.enumerated().map { i, p in + (i: i, project: p, at: p.id == focused ? Double.infinity : ((store.tasks[p.id] ?? []).map { visits[$0.id] ?? 0 } + [visits[p.id] ?? 0]).max()!) + } + let recent = used.sorted { $0.at != $1.at ? $0.at > $1.at : $0.i < $1.i }.map(\.project) let images = store.images.images(imageKey).count var rows: [SwitcherRow] = [] if images == 0 { rows = matches.map { SwitcherRow(id: "task:\($0.task.id)", kind: .task($0.project, $0.task, $0.count)) } - for p in (targets ?? store.projects) where includes("\(p.name) project".lowercased(), q) { + for p in (targets ?? recent) where includes("\(p.name) project".lowercased(), q) { rows.append(SwitcherRow(id: "project:\(p.id)", kind: .project(p))) } } - let focused = store.focusedProject()?.id - let used = store.projects.enumerated().map { i, p in - (i: i, project: p, at: p.id == focused ? Double.infinity : (store.tasks[p.id] ?? []).map { visits[$0.id] ?? 0 }.max() ?? 0) - } - let recent = used.sorted { $0.at != $1.at ? $0.at > $1.at : $0.i < $1.i }.map(\.project) let workflow = images == 0 ? workflowMatch(title) : nil for project in targets ?? recent { if title.isEmpty && images == 0 {