Skip to content

Commit 35b0685

Browse files
committed
Add Direction to Layout persistence
Debated about this a long time, but I feel conceptually reading direction is sort of the most primary layout choice so it should be part of the Layout that is persisted. Bumped the version number of the Layout format, but essentially this is just an addition, so the old behavior is preserved, unless the new data is present in the Layout file, in which case the program takes advantage of it.
1 parent 3c3ef48 commit 35b0685

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cmd/cbxv/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
const (
1515
NAME = "cbxv"
16-
VERSION = "0.5.6"
16+
VERSION = "0.5.7"
1717
)
1818

1919
// Update listens for messages on the message channel and
@@ -28,6 +28,7 @@ func update(m *model.Model, u *ui.UI, msgChan chan util.Message, msgHandlers *Me
2828
(msg.TypeName != "quit" &&
2929
msg.TypeName != "openFile" &&
3030
msg.TypeName != "openFileResult" &&
31+
msg.TypeName != "toggleDirection" &&
3132
msg.TypeName != "setFullscreen") {
3233
continue
3334
}

internal/model/model.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ const (
376376
type Layout struct {
377377
FormatVersion string `json:"formatVersion"`
378378
Comic ComicData `json:"comic"`
379+
Direction Direction `json:"direction"`
379380
Mode LayoutMode `json:"mode"`
380381
Pages []Page `json:"pages"`
381382
}
@@ -586,12 +587,13 @@ func (m *Model) PageToSpread(n int) int {
586587

587588
func (m *Model) StoreLayout() error {
588589
layout := Layout{
589-
FormatVersion: "0.1",
590+
FormatVersion: "0.2",
590591
}
591592
c := ComicData{}
592593
c.Hash = m.Hash
593594
c.FilePath = m.FilePath
594595
layout.Comic = c
596+
layout.Direction = m.Direction
595597
layout.Mode = m.LayoutMode
596598
layout.Pages = m.Pages
597599

@@ -618,6 +620,10 @@ func (m *Model) loadLayout(hash string) *Layout {
618620

619621
if data != nil {
620622
var lo Layout
623+
// default Direction to whatever it's currently
624+
// set too, because it was added in 0.2 and we
625+
// want to preserve existing behavior
626+
lo.Direction = m.Direction
621627
err := json.Unmarshal([]byte(*data), &lo)
622628
if err != nil {
623629
fmt.Printf("e:%s\n", err)
@@ -638,6 +644,10 @@ func (m *Model) joinAll() {
638644
}
639645

640646
func (m *Model) applyLayout(layout *Layout) {
647+
if m.Direction != layout.Direction {
648+
m.SendMessage(util.Message{TypeName: "toggleDirection"})
649+
}
650+
641651
for i := range layout.Pages {
642652
p := layout.Pages[i]
643653
mp := m.Pages[i]

0 commit comments

Comments
 (0)