@@ -4,7 +4,7 @@ import Browser
44import ColorHelper exposing (colorForSessionType , computeCurrentColor , fromCSSHexToRGB , fromRGBToCSSHex )
55import Html exposing (Html , div )
66import Html.Attributes exposing (id )
7- import Json exposing (configEncoder , elmMessageBuilder , elmMessageEncoder , externalMessageDecoder , sessionTypeDecoder , soundMessageEncoder )
7+ import Json exposing (configEncoder , currentStateEncoder , elmMessageBuilder , elmMessageEncoder , externalMessageDecoder , sessionTypeDecoder , soundMessageEncoder )
88import Json.Decode as Decode
99import Json.Encode as Encode
1010import ListWithCurrent exposing (ListWithCurrent (..) )
@@ -13,7 +13,6 @@ import TimeHelper exposing (getCurrentMaxTime)
1313import Types
1414 exposing
1515 ( Config
16- , CurrentState
1716 , Defaults
1817 , ExternalMessage (..)
1918 , Model
@@ -44,19 +43,6 @@ main =
4443 }
4544
4645
47- sessionStatusToString : SessionStatus -> String
48- sessionStatusToString sessionStatus =
49- case sessionStatus of
50- Paused ->
51- " paused"
52-
53- Running ->
54- " running"
55-
56- NotStarted ->
57- " not_started"
58-
59-
6046type alias Flags =
6147 { alwaysOnTop : Bool
6248 , appVersion : String
@@ -102,6 +88,7 @@ init flags =
10288 { color = theme. colors. focusRound
10389 , percentage = 1
10490 , paused = False
91+ , sessionStatus = NotStarted
10592 }
10693 in
10794 ( { appVersion = flags. appVersion
@@ -152,8 +139,7 @@ init flags =
152139 , volumeSliderHidden = True
153140 }
154141 , Cmd . batch
155- [ updateCurrentState currentState
156- , updateSessionStatus ( NotStarted |> sessionStatusToString)
142+ [ sendMessageFromElm ( elmMessageBuilder " update_current_state" currentState currentStateEncoder)
157143 , sendMessageFromElm ( elmMessageEncoder { name = " get_init_data" , value = Nothing } )
158144 , setThemeColors <| theme. colors
159145 ]
@@ -204,7 +190,7 @@ update msg ({ config } as model) =
204190 , Cmd . batch
205191 [ setThemeColors theme. colors
206192 , sendMessageFromElm ( elmMessageBuilder " update_config" newConfig configEncoder)
207- , updateCurrentState newState
193+ , sendMessageFromElm ( elmMessageBuilder " update_current_state " newState currentStateEncoder )
208194 ]
209195 )
210196
@@ -264,20 +250,16 @@ update msg ({ config } as model) =
264250 |> update ( ProcessExternalMessage ( RustStateMsg c. pomodoroState))
265251
266252 ( modelWithTheme, cmdWithTheme ) =
267- let
268- baseCmd =
269- [ newCmd, updateSessionStatus ( NotStarted |> sessionStatusToString) ]
270- in
271253 case newThemes |> ListWithCurrent . getCurrent of
272254 Just currentTheme ->
273255 let
274256 ( updatedModel, updatedCmd ) =
275257 update ( ChangeTheme currentTheme) newModel
276258 in
277- ( updatedModel, Cmd . batch ( updatedCmd :: baseCmd ) )
259+ ( updatedModel, Cmd . batch [ updatedCmd, newCmd ] )
278260
279261 _ ->
280- ( newModel, Cmd . batch baseCmd )
262+ ( newModel, newCmd )
281263 in
282264 -- Auto start if config is set
283265 if modelWithTheme. config. autoStartOnAppStartup then
@@ -353,6 +335,7 @@ update msg ({ config } as model) =
353335 , percentage = percent
354336 , paused =
355337 pomodoroState. currentSession. status == Paused
338+ , sessionStatus = pomodoroState. currentSession. status
356339 }
357340
358341 cmds =
@@ -412,7 +395,8 @@ update msg ({ config } as model) =
412395 , currentState = currentState
413396 , pomodoroState = Just pomodoroState
414397 }
415- , Cmd . batch ( updateCurrentState currentState :: cmds)
398+ , Cmd . batch
399+ ( sendMessageFromElm ( elmMessageBuilder " update_current_state" currentState currentStateEncoder) :: cmds)
416400 )
417401
418402 ProcessExternalMessage ( SoundFilePath sessionType path) ->
@@ -444,12 +428,12 @@ update msg ({ config } as model) =
444428 , percentage = 1
445429 , paused =
446430 model. pomodoroState |> Maybe . map ( \ state -> state. currentSession. status == Paused ) |> Maybe . withDefault False
431+ , sessionStatus = NotStarted
447432 }
448433 in
449434 ( model
450435 , Cmd . batch
451- [ updateCurrentState currentState
452- , updateSessionStatus ( NotStarted |> sessionStatusToString)
436+ [ sendMessageFromElm ( elmMessageBuilder " update_current_state" currentState currentStateEncoder)
453437 , sendMessageFromElm ( elmMessageEncoder { name = " reset" , value = Nothing } )
454438 ]
455439 )
@@ -467,10 +451,7 @@ update msg ({ config } as model) =
467451 ( { model
468452 | config = newConfig
469453 }
470- , Cmd . batch
471- [ updateSessionStatus ( NotStarted |> sessionStatusToString)
472- , sendMessageFromElm ( elmMessageEncoder { name = " reset" , value = Nothing } )
473- ]
454+ , sendMessageFromElm ( elmMessageEncoder { name = " reset" , value = Nothing } )
474455 )
475456
476457 ResetAudioFile sessionType ->
@@ -579,16 +560,17 @@ update msg ({ config } as model) =
579560 else
580561 1
581562 , paused = True
563+ , sessionStatus = Paused
582564 }
583565 in
584566 ( { model | currentState = currentState }
585567 , Cmd . batch
586- [ updateCurrentState currentState
568+ [ sendMessageFromElm ( elmMessageBuilder " update_current_state " currentState currentStateEncoder )
587569 , sendMessageFromElm ( elmMessageEncoder { name = " pause" , value = Nothing } )
588570 ]
589571 )
590572
591- _ ->
573+ status ->
592574 let
593575 maxTime =
594576 getCurrentMaxTime config state
@@ -607,11 +589,12 @@ update msg ({ config } as model) =
607589 else
608590 1
609591 , paused = False
592+ , sessionStatus = status
610593 }
611594 in
612595 ( { model | currentState = currentState }
613596 , Cmd . batch
614- [ updateCurrentState currentState
597+ [ sendMessageFromElm ( elmMessageBuilder " update_current_state " currentState currentStateEncoder )
615598 , sendMessageFromElm ( elmMessageEncoder { name = " play" , value = Nothing } )
616599 ]
617600 )
@@ -796,12 +779,6 @@ port minimizeWindow : () -> Cmd msg
796779port hideWindow : () -> Cmd msg
797780
798781
799- port updateCurrentState : CurrentState -> Cmd msg
800-
801-
802- port updateSessionStatus : String -> Cmd msg
803-
804-
805782port notify : Notification -> Cmd msg
806783
807784
0 commit comments