You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
//
|
|
// WindowController.swift
|
|
// MastoSearch
|
|
//
|
|
// Created by Shadowfacts on 12/14/21.
|
|
//
|
|
|
|
import Cocoa
|
|
import Combine
|
|
import MastoSearchCore
|
|
|
|
class WindowController: NSWindowController {
|
|
|
|
@IBOutlet weak var searchField: NSSearchField!
|
|
|
|
private var querySubject = PassthroughSubject<String, Never>()
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
private var viewController: ViewController {
|
|
contentViewController as! ViewController
|
|
}
|
|
|
|
override func windowDidLoad() {
|
|
super.windowDidLoad()
|
|
|
|
querySubject
|
|
.debounce(for: .seconds(0.5), scheduler: RunLoop.main)
|
|
.sink { [unowned self] (val) in
|
|
self.viewController.search(val)
|
|
}
|
|
.store(in: &cancellables)
|
|
|
|
SyncController.shared.onSync
|
|
.sink { [unowned self] in self.updateSubtitle() }
|
|
.store(in: &cancellables)
|
|
|
|
DatabaseController.shared.onInitialize
|
|
.sink { [unowned self] in self.updateSubtitle() }
|
|
.store(in: &cancellables)
|
|
}
|
|
|
|
private func updateSubtitle() {
|
|
guard let window = window,
|
|
DatabaseController.shared.isInitialized else {
|
|
return
|
|
}
|
|
window.subtitle = "\(DatabaseController.shared.countStatuses().formatted(.number.grouping(.automatic))) statuses"
|
|
}
|
|
|
|
@IBAction func searchFieldTextChanged(_ sender: Any) {
|
|
querySubject.send(searchField.stringValue)
|
|
}
|
|
|
|
@IBAction func searchMenuItemActivated(_ sender: Any) {
|
|
searchField.becomeFirstResponder()
|
|
}
|
|
|
|
}
|