A music player that connects to your cloud/distributed storage.
at main 185 lines 6.4 kB view raw
1module UI.Adjunct exposing (..) 2 3import Keyboard 4import Maybe.Extra as Maybe 5import Return 6import UI.Alfred.State as Alfred 7import UI.Audio.State as Audio 8import UI.Commands.State as Commands 9import UI.Common.State as Common 10import UI.Interface.State exposing (hideOverlay) 11import UI.Page as Page 12import UI.Playlists.Page as Playlists 13import UI.Playlists.State as Playlists 14import UI.Queue.Page as Queue 15import UI.Queue.State as Queue 16import UI.Settings.Page as Settings 17import UI.Sources.Page as Sources 18import UI.Tracks.State as Tracks 19import UI.Types exposing (..) 20 21 22 23-- 📣 24 25 26keyboardInput : Keyboard.Msg -> Manager 27keyboardInput msg model = 28 (\m -> 29 let 30 skip = 31 Return.singleton m 32 in 33 if m.focusedOnInput && Maybe.isNothing model.alfred then 34 case m.pressedKeys of 35 [ Keyboard.Escape ] -> 36 hideOverlay m 37 38 _ -> 39 skip 40 41 else if Maybe.isJust model.alfred then 42 case m.pressedKeys of 43 [ Keyboard.ArrowDown ] -> 44 Alfred.selectNext m 45 46 [ Keyboard.ArrowUp ] -> 47 Alfred.selectPrevious m 48 49 [ Keyboard.Enter ] -> 50 Alfred.runSelectedAction m 51 52 [ Keyboard.Escape ] -> 53 hideOverlay m 54 55 -- Meta key 56 -- 57 [ Keyboard.Character "K", Keyboard.Meta ] -> 58 Commands.showPalette m 59 60 -- Ctrl key 61 -- 62 [ Keyboard.Character "K", Keyboard.Control ] -> 63 Commands.showPalette m 64 65 [ Keyboard.Character "L", Keyboard.Control ] -> 66 Playlists.assistWithSelectingPlaylist m 67 68 _ -> 69 skip 70 71 else 72 case m.pressedKeys of 73 [ Keyboard.Character "[", Keyboard.Control ] -> 74 Queue.rewind m 75 76 [ Keyboard.Character "]", Keyboard.Control ] -> 77 Queue.shift m 78 79 [ Keyboard.Character "{", Keyboard.Shift, Keyboard.Control ] -> 80 case m.nowPlaying of 81 Just { duration, item, playbackPosition } -> 82 case duration of 83 Just d -> 84 Audio.seek 85 { trackId = (Tuple.second item.identifiedTrack).id 86 , progress = (playbackPosition - 10) / d 87 } 88 m 89 90 Nothing -> 91 Return.singleton m 92 93 Nothing -> 94 Return.singleton m 95 96 [ Keyboard.Character "}", Keyboard.Shift, Keyboard.Control ] -> 97 case m.nowPlaying of 98 Just { duration, item, playbackPosition } -> 99 case duration of 100 Just d -> 101 Audio.seek 102 { trackId = (Tuple.second item.identifiedTrack).id 103 , progress = (playbackPosition + 10) / d 104 } 105 m 106 107 Nothing -> 108 Return.singleton m 109 110 Nothing -> 111 Return.singleton m 112 113 -- Meta key 114 -- 115 [ Keyboard.Character "K", Keyboard.Meta ] -> 116 Commands.showPalette m 117 118 -- Ctrl key 119 -- 120 [ Keyboard.Character "K", Keyboard.Control ] -> 121 Commands.showPalette m 122 123 [ Keyboard.Character "L", Keyboard.Control ] -> 124 Playlists.assistWithSelectingPlaylist m 125 126 [ Keyboard.Character "N", Keyboard.Control ] -> 127 Tracks.scrollToNowPlaying m 128 129 [ Keyboard.Character "P", Keyboard.Control ] -> 130 Audio.playPause m 131 132 [ Keyboard.Character "R", Keyboard.Control ] -> 133 Queue.toggleRepeat m 134 135 [ Keyboard.Character "S", Keyboard.Control ] -> 136 Queue.toggleShuffle m 137 138 -- 139 [ Keyboard.Character "1", Keyboard.Control ] -> 140 Common.changeUrlUsingPage Page.Index m 141 142 [ Keyboard.Character "2", Keyboard.Control ] -> 143 Common.changeUrlUsingPage (Page.Playlists Playlists.Index) m 144 145 [ Keyboard.Character "3", Keyboard.Control ] -> 146 Common.changeUrlUsingPage (Page.Queue Queue.Index) m 147 148 [ Keyboard.Character "8", Keyboard.Control ] -> 149 Common.changeUrlUsingPage (Page.Sources Sources.Index) m 150 151 [ Keyboard.Character "9", Keyboard.Control ] -> 152 Common.changeUrlUsingPage (Page.Settings Settings.Index) m 153 154 -- 155 [ Keyboard.Escape ] -> 156 if Maybe.isJust m.contextMenu then 157 Return.singleton { m | contextMenu = Nothing } 158 159 else if Maybe.isJust m.confirmation then 160 Return.singleton { m | confirmation = Nothing } 161 162 else if Maybe.isJust m.alfred then 163 Return.singleton { m | alfred = Nothing } 164 165 else if Maybe.isJust m.selectedCover then 166 Return.singleton { m | selectedCover = Nothing } 167 168 else 169 case m.page of 170 Page.Playlists Playlists.Index -> 171 Return.singleton { m | page = Page.Index } 172 173 Page.Playlists _ -> 174 Return.singleton { m | page = Page.Playlists Playlists.Index } 175 176 Page.Queue _ -> 177 Return.singleton { m | page = Page.Index } 178 179 _ -> 180 skip 181 182 _ -> 183 skip 184 ) 185 { model | pressedKeys = Keyboard.update msg model.pressedKeys }