1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Tidy up more of the window handling

This commit is contained in:
Daniel Barber 2019-05-03 10:54:15 -04:00
parent 49269ca21b
commit c01a662c84
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
6 changed files with 33 additions and 6 deletions

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -144,7 +144,7 @@
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController showSeguePresentationStyle="single" id="B8D-0N-5wS" customClass="WindowController" customModule="Persephone" customModuleProvider="target" sceneMemberID="viewController">
<window key="window" title="Persephone" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA" customClass="MainWindow" customModule="Persephone" customModuleProvider="target">
<window key="window" title="Persephone" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" tabbingMode="disallowed" id="IQv-IB-iLA" customClass="MainWindow" customModule="Persephone" customModuleProvider="target">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="207" y="570" width="960" height="560"/>
@ -278,7 +278,7 @@
<scene sceneID="Rpk-bo-5kf">
<objects>
<windowController showSeguePresentationStyle="single" id="xYu-7w-E5x" customClass="PreferencesWindowController" customModule="Persephone" customModuleProvider="target" sceneMemberID="viewController">
<window key="window" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" titleVisibility="hidden" id="3FN-my-6kU">
<window key="window" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="3FN-my-6kU">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<rect key="contentRect" x="245" y="301" width="416" height="100"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>

View File

@ -12,6 +12,8 @@ struct MainWindowDidOpenAction: Action {}
struct MainWindowDidCloseAction: Action {}
struct MainWindowDidMinimizeAction: Action {}
struct DatabaseUpdateStartedAction: Action {}
struct DatabaseUpdateFinishedAction: Action {}

View File

@ -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

View File

@ -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
}