mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-01 01:32:04 +03:00
GH-653 Add a quit action
- Since the AppDelegate is the last subscriber to the AppState changes, AppDelegate.hasMainWindows is not yet updated when UiRoot.prepareQuit() is called. It seems that Completable.concat([]) does not complete. By not emitting a quit action in UiRoot in case "Quit after last window closes"-option is turned on, we defer the NSapp.terminate() call to the next tick such that AppDelegate had the time to update AppDelegate.hasMainWindows.
This commit is contained in:
parent
35a992c054
commit
6f21044af5
@ -64,6 +64,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
self.useSnapshot = appState.useSnapshotUpdate
|
||||
self.setSparkleUrl(self.useSnapshot)
|
||||
}
|
||||
|
||||
if appState.quit {
|
||||
NSApp.terminate(self)
|
||||
}
|
||||
})
|
||||
.disposed(by: self.disposeBag)
|
||||
|
||||
|
@ -25,6 +25,7 @@ class Context {
|
||||
|
||||
let previewService = PreviewService()
|
||||
let httpService: HttpServerService = HttpServerService(port: baseServerUrl.port!)
|
||||
let uiRootReducer = UiRootReducer()
|
||||
|
||||
// AppState
|
||||
Observable
|
||||
@ -33,7 +34,7 @@ class Context {
|
||||
.reduce(by: AppDelegateReducer(baseServerUrl: baseServerUrl).reduce)
|
||||
.filterMapPair(),
|
||||
self.actionSourceForAppState()
|
||||
.reduce(by: UiRootReducer().reduce)
|
||||
.reduce(by: uiRootReducer.reduceMainWindow)
|
||||
.reduce(by: openQuicklyReducer.reduceMainWindow)
|
||||
.filter { $0.modified }
|
||||
.apply(self.prefService.applyMainWindow)
|
||||
@ -43,6 +44,9 @@ class Context {
|
||||
.filterMapPair(),
|
||||
self.actionSourceForAppState()
|
||||
.reduce(by: openQuicklyReducer.reduceOpenQuicklyWindow)
|
||||
.filterMapPair(),
|
||||
self.actionSourceForAppState()
|
||||
.reduce(by: uiRootReducer.reduceUiRoot)
|
||||
.filterMapPair()
|
||||
)
|
||||
.merge()
|
||||
|
@ -33,6 +33,8 @@ struct AppState: SerializableState {
|
||||
|
||||
var openQuickly = OpenQuicklyWindow.State.default
|
||||
|
||||
var quit = false
|
||||
|
||||
init() {
|
||||
|
||||
}
|
||||
|
@ -10,9 +10,15 @@ class UiRoot: UiComponent {
|
||||
|
||||
typealias StateType = AppState
|
||||
|
||||
enum Action {
|
||||
|
||||
case quit
|
||||
}
|
||||
|
||||
required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
|
||||
self.source = source
|
||||
self.emitter = emitter
|
||||
self.emit = emitter.typedEmit()
|
||||
|
||||
self.fileMonitor = FileMonitor(source: source, emitter: emitter, state: state)
|
||||
self.openQuicklyWindow = OpenQuicklyWindow(source: source, emitter: emitter, state: state)
|
||||
@ -50,7 +56,7 @@ class UiRoot: UiComponent {
|
||||
|
||||
case .doNothing: return
|
||||
case .hide: NSApp.hide(self)
|
||||
case .quit: NSApp.terminate(self)
|
||||
case .quit: self.emit(.quit)
|
||||
|
||||
}
|
||||
})
|
||||
@ -66,6 +72,7 @@ class UiRoot: UiComponent {
|
||||
|
||||
private let source: Observable<AppState>
|
||||
private let emitter: ActionEmitter
|
||||
private let emit: (Action) -> Void
|
||||
private let disposeBag = DisposeBag()
|
||||
|
||||
private let fileMonitor: FileMonitor
|
||||
|
@ -7,9 +7,23 @@ import Foundation
|
||||
|
||||
class UiRootReducer {
|
||||
|
||||
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
||||
typealias UiRootPair = StateActionPair<AppState, UiRoot.Action>
|
||||
typealias MainWindowPair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
||||
|
||||
func reduce(_ pair: Pair) -> Pair {
|
||||
func reduceUiRoot(_ pair: UiRootPair) -> UiRootPair {
|
||||
var appState = pair.state
|
||||
|
||||
switch pair.action {
|
||||
|
||||
case .quit:
|
||||
appState.quit = true
|
||||
|
||||
}
|
||||
|
||||
return StateActionPair(state: appState, action: pair.action)
|
||||
}
|
||||
|
||||
func reduceMainWindow(_ pair: MainWindowPair) -> MainWindowPair {
|
||||
var appState = pair.state
|
||||
let uuid = pair.action.uuid
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user