diff --git a/Persephone/AppDelegate.swift b/Persephone/AppDelegate.swift index ecabd69..d237c0e 100644 --- a/Persephone/AppDelegate.swift +++ b/Persephone/AppDelegate.swift @@ -85,6 +85,14 @@ class AppDelegate: NSObject, return dockMenu } + func setMainWindowStateMenuItem(state: MainWindowState) { + switch state { + case .open: mainWindowMenuItem.state = .on + case .closed: mainWindowMenuItem.state = .off + case .minimised: mainWindowMenuItem.state = .mixed + } + } + func handle(mediaKey: MediaKey, event: KeyEvent) { switch mediaKey { case .playPause: @@ -122,6 +130,6 @@ extension AppDelegate: StoreSubscriber { func newState(state: UIState) { updateDatabaseMenuItem.isEnabled = !state.databaseUpdating - mainWindowMenuItem.state = state.mainWindowOpen ? .on : .off + setMainWindowStateMenuItem(state: state.mainWindowState) } } diff --git a/Persephone/Controllers/WindowController.swift b/Persephone/Controllers/WindowController.swift index d5ec195..7ff5f21 100644 --- a/Persephone/Controllers/WindowController.swift +++ b/Persephone/Controllers/WindowController.swift @@ -149,6 +149,14 @@ extension WindowController: NSWindowDelegate { func windowWillClose(_ notification: Notification) { App.store.dispatch(MainWindowDidCloseAction()) } + + func windowWillMiniaturize(_ notification: Notification) { + App.store.dispatch(MainWindowDidMinimizeAction()) + } + + func windowDidDeminiaturize(_ notification: Notification) { + App.store.dispatch(MainWindowDidOpenAction()) + } } extension WindowController: StoreSubscriber { diff --git a/Persephone/Resources/Base.lproj/Main.storyboard b/Persephone/Resources/Base.lproj/Main.storyboard index a50c07b..16394ae 100644 --- a/Persephone/Resources/Base.lproj/Main.storyboard +++ b/Persephone/Resources/Base.lproj/Main.storyboard @@ -144,7 +144,7 @@ - + @@ -278,7 +278,7 @@ - + diff --git a/Persephone/State/Actions/UIActions.swift b/Persephone/State/Actions/UIActions.swift index 3e2adeb..39702ba 100644 --- a/Persephone/State/Actions/UIActions.swift +++ b/Persephone/State/Actions/UIActions.swift @@ -12,6 +12,8 @@ struct MainWindowDidOpenAction: Action {} struct MainWindowDidCloseAction: Action {} +struct MainWindowDidMinimizeAction: Action {} + struct DatabaseUpdateStartedAction: Action {} struct DatabaseUpdateFinishedAction: Action {} diff --git a/Persephone/State/Reducers/UIReducer.swift b/Persephone/State/Reducers/UIReducer.swift index 8508789..d767c07 100644 --- a/Persephone/State/Reducers/UIReducer.swift +++ b/Persephone/State/Reducers/UIReducer.swift @@ -13,10 +13,13 @@ func uiReducer(action: Action, state: UIState?) -> UIState { switch action { case is MainWindowDidOpenAction: - state.mainWindowOpen = true + state.mainWindowState = .open case is MainWindowDidCloseAction: - state.mainWindowOpen = false + state.mainWindowState = .closed + + case is MainWindowDidMinimizeAction: + state.mainWindowState = .minimised case is DatabaseUpdateStartedAction: state.databaseUpdating = true diff --git a/Persephone/State/UIState.swift b/Persephone/State/UIState.swift index e086696..9a63edc 100644 --- a/Persephone/State/UIState.swift +++ b/Persephone/State/UIState.swift @@ -8,7 +8,13 @@ import ReSwift +enum MainWindowState { + case open + case closed + case minimised +} + struct UIState: StateType { - var mainWindowOpen: Bool = false + var mainWindowState: MainWindowState = .closed var databaseUpdating: Bool = false }