1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-26 23:36:08 +03:00

Better queue handling

This commit is contained in:
Tae Won Ha 2020-01-17 19:03:51 +01:00
parent c21abb2272
commit c52a0e077d
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 31 additions and 11 deletions

View File

@ -16,10 +16,6 @@ class FileMonitorReducer: ReducerType {
switch tuple.action {
case let .change(in: url):
if let fileItem = FileItemUtils.item(for: url, root: state.openQuickly.root, create: false) {
fileItem.needsScanChildren = true
}
state.mainWindows
.filter { (uuid, mainWindow) in url == mainWindow.cwd || url.isContained(in: mainWindow.cwd) }
.map { $0.0 }

View File

@ -17,7 +17,6 @@ class OpenQuicklyReducer: ReducerType {
var appState = pair.state
appState.openQuickly.open = false
appState.openQuickly.flatFileItems = Observable.empty()
appState.openQuickly.cwd = FileUtils.userHomeUrl
switch pair.action {

View File

@ -7,6 +7,7 @@ import Cocoa
import RxSwift
import RxCocoa
import PureLayout
import os
class OpenQuicklyWindow: NSObject,
UiComponent,
@ -31,8 +32,6 @@ class OpenQuicklyWindow: NSObject,
.throttle(.milliseconds(2 * 500), latest: true, scheduler: MainScheduler.instance)
.distinctUntilChanged()
self.fileService = FileService(root: self.cwd)
super.init()
self.window.delegate = self
@ -42,6 +41,8 @@ class OpenQuicklyWindow: NSObject,
source
.observeOn(MainScheduler.instance)
.subscribe(onNext: { state in
self.updateRootUrls(state: state)
guard state.openQuickly.open else {
self.windowController.close()
return
@ -81,6 +82,9 @@ class OpenQuicklyWindow: NSObject,
private(set) var cwd = FileUtils.userHomeUrl
private var cwdPathCompsCount = 0
private var fileServicesPerRootUrl: [URL: FileService] = [:]
private var rootUrls: Set<URL> { Set(self.fileServicesPerRootUrl.map { url, _ in url }) }
// FIXME: migrate to State later...
private(set) var pattern = ""
@objc private(set) var fileViewItems = [ScoredUrl]()
@ -96,12 +100,36 @@ class OpenQuicklyWindow: NSObject,
private let fileView = NSTableView.standardTableView()
private let searchStream: Observable<String>
private let fileService: FileService
private let log = OSLog(subsystem: Defs.loggerSubsystem,
category: Defs.LoggerCategory.uiComponents)
private var window: NSWindow {
return self.windowController.window!
}
private func updateRootUrls(state: AppState) {
let urlsToMonitor = Set(state.mainWindows.map { $1.cwd })
let newUrls = urlsToMonitor.subtracting(self.rootUrls)
let obsoleteUrls = self.rootUrls.subtracting(urlsToMonitor)
newUrls.forEach { url in
self.log.info("Adding \(url) and its service.")
guard let service = try? FileService(root: url) else {
self.log.error("Could not create FileService for \(url)")
return
}
self.fileServicesPerRootUrl[url] = service
}
obsoleteUrls.forEach { url in
self.log.info("Removing \(url) and its service.")
self.fileServicesPerRootUrl.removeValue(forKey: url)
}
}
private func addViews() {
let searchField = self.searchField
searchField.rx.delegate.setForwardToDelegate(self, retainDelegate: false)

View File

@ -80,9 +80,6 @@ extension OpenQuicklyWindow {
case ignorePatterns = "ignore-patterns"
}
let root = FileItem(URL(fileURLWithPath: "/", isDirectory: true))
var flatFileItems = Observable<[FileItem]>.empty()
var cwd = FileUtils.userHomeUrl
var ignorePatterns = State.defaultIgnorePatterns
var ignoreToken = Token()