 import Silica
 import SwiftyJSON
 
+fileprivate let mouseDragRaceThresholdSeconds = 0.15
+
 enum WindowChange {
     case add(window: SIWindow)
     case remove(window: SIWindow)

        return _addObservers().retry(.exponentialDelayed(maxCount: 4, initial: 0.1, multiplier: 2))
    }

    private func _addObservers() -> Observable<Bool> {
        let application = self.application
        let windowManager = self.windowManager

        return Observable.create { observer in
            var success: Bool = false

                    return
                }

                // if mouse button is down, record window and wait for mouse up
                guard let lmbUpMoment = leftMouseButtonUpMoment else {
                    windowBeingDragged = focusedWindow
                    return
                }

                // if mouse button recently came up, assume window move is related
                let dragEndInterval = NSDate().timeIntervalSince(lmbUpMoment as Date)
                if dragEndInterval < mouseDragRaceThresholdSeconds {
                    self.swapDraggedWindowWithDropzone(focusedWindow)
                    leftMouseButtonUpMoment = nil
                }
            }

            application.observeNotification(kAXWindowResizedNotification as CFString!, with: application) { accessibilityElement in
                guard let window = accessibilityElement as? SIWindow else {
                    return
                }

                guard let focusedWindow = SIWindow.focused(), let screen = focusedWindow.screen() else {
                    return
                }

            }
            observer.on(.next(true))
            observer.on(.completed)
