diff --git a/client.so b/client.so deleted file mode 100644 index cb43ef8..0000000 Binary files a/client.so and /dev/null differ diff --git a/pkg/model/client/client.go b/pkg/model/client/client.go index 9ffe880..63cb14d 100644 --- a/pkg/model/client/client.go +++ b/pkg/model/client/client.go @@ -28,8 +28,10 @@ func (i GameID) String() string { type State struct { // TODO: store user's login key - GameState []GameState `json:"gameState"` - ActiveGameID GameID `json:"activeGameId"` + ClientCurrentVersion string `json:"clientCurrentVersion"` + ClientNextVersion *string `json:"clientNextVersion,omitempty"` + GameState []GameState `json:"gameState"` + ActiveGameID GameID `json:"activeGameId"` } type GameState struct { diff --git a/pkg/storage/fs/fs.go b/pkg/storage/fs/fs.go index e608f9c..e333ce8 100644 --- a/pkg/storage/fs/fs.go +++ b/pkg/storage/fs/fs.go @@ -100,7 +100,7 @@ func NewFS(storageRoot string) (*fsStorage, error) { }, nil } -func (s *fsStorage) StateExists(callback func(bool, error)) { +func (s *fsStorage) StateExistsAsync(callback func(bool, error)) { go func() { exists, err := s.FileExists(stateFileName) if callback != nil { @@ -109,7 +109,7 @@ func (s *fsStorage) StateExists(callback func(bool, error)) { }() } -func (s *fsStorage) LoadState(callback func(client.State, error)) { +func (s *fsStorage) LoadStateAsync(callback func(client.State, error)) { go func() { state, err := s.loadStateSync() if callback != nil { @@ -118,7 +118,7 @@ func (s *fsStorage) LoadState(callback func(client.State, error)) { }() } -func (s *fsStorage) SaveState(state client.State, callback func(error)) { +func (s *fsStorage) SaveStateAsync(state client.State, callback func(error)) { go func() { err := s.saveStateSync(state) if callback != nil { @@ -127,7 +127,7 @@ func (s *fsStorage) SaveState(state client.State, callback func(error)) { }() } -func (s *fsStorage) LoadReport(id client.GameID, turn uint, callback func(report.Report, error)) { +func (s *fsStorage) LoadReportAsync(id client.GameID, turn uint, callback func(report.Report, error)) { go func() { rep, err := s.loadReportSync(id, turn) if callback != nil { @@ -136,7 +136,7 @@ func (s *fsStorage) LoadReport(id client.GameID, turn uint, callback func(report }() } -func (s *fsStorage) SaveReport(id client.GameID, turn uint, rep report.Report, callback func(error)) { +func (s *fsStorage) SaveReportAsync(id client.GameID, turn uint, rep report.Report, callback func(error)) { go func() { err := s.saveReportSync(id, turn, rep) if callback != nil { @@ -145,7 +145,7 @@ func (s *fsStorage) SaveReport(id client.GameID, turn uint, rep report.Report, c }() } -func (s *fsStorage) LoadOrder(id client.GameID, turn uint, callback func(order.Order, error)) { +func (s *fsStorage) LoadOrderAsync(id client.GameID, turn uint, callback func(order.Order, error)) { go func() { o, err := s.loadOrderSync(id, turn) if callback != nil { @@ -154,7 +154,7 @@ func (s *fsStorage) LoadOrder(id client.GameID, turn uint, callback func(order.O }() } -func (s *fsStorage) SaveOrder(id client.GameID, turn uint, o order.Order, callback func(error)) { +func (s *fsStorage) SaveOrderAsync(id client.GameID, turn uint, o order.Order, callback func(error)) { go func() { err := s.saveOrderSync(id, turn, o) if callback != nil { diff --git a/pkg/storage/fs/fs_test.go b/pkg/storage/fs/fs_test.go index b3e82ca..21345de 100644 --- a/pkg/storage/fs/fs_test.go +++ b/pkg/storage/fs/fs_test.go @@ -27,7 +27,7 @@ func TestStateRoundTripAsync(t *testing.T) { want := sampleState() saveDone := make(chan error, 1) - s.SaveState(want, func(err error) { + s.SaveStateAsync(want, func(err error) { saveDone <- err }) if err := waitError(t, saveDone); err != nil { @@ -35,7 +35,7 @@ func TestStateRoundTripAsync(t *testing.T) { } existsDone := make(chan callbackResult[bool], 1) - s.StateExists(func(ok bool, err error) { + s.StateExistsAsync(func(ok bool, err error) { existsDone <- callbackResult[bool]{value: ok, err: err} }) exists := waitResult(t, existsDone) @@ -47,7 +47,7 @@ func TestStateRoundTripAsync(t *testing.T) { } loadDone := make(chan callbackResult[client.State], 1) - s.LoadState(func(state client.State, err error) { + s.LoadStateAsync(func(state client.State, err error) { loadDone <- callbackResult[client.State]{value: state, err: err} }) got := waitResult(t, loadDone) @@ -68,7 +68,7 @@ func TestReportAndOrderRoundTripAsync(t *testing.T) { wantOrder := sampleOrder() saveReportDone := make(chan error, 1) - s.SaveReport(id, turn, initialReport, func(err error) { + s.SaveReportAsync(id, turn, initialReport, func(err error) { saveReportDone <- err }) if err := waitError(t, saveReportDone); err != nil { @@ -76,7 +76,7 @@ func TestReportAndOrderRoundTripAsync(t *testing.T) { } saveOrderDone := make(chan error, 1) - s.SaveOrder(id, turn, wantOrder, func(err error) { + s.SaveOrderAsync(id, turn, wantOrder, func(err error) { saveOrderDone <- err }) if err := waitError(t, saveOrderDone); err != nil { @@ -84,7 +84,7 @@ func TestReportAndOrderRoundTripAsync(t *testing.T) { } saveUpdatedReportDone := make(chan error, 1) - s.SaveReport(id, turn, updatedReport, func(err error) { + s.SaveReportAsync(id, turn, updatedReport, func(err error) { saveUpdatedReportDone <- err }) if err := waitError(t, saveUpdatedReportDone); err != nil { @@ -92,7 +92,7 @@ func TestReportAndOrderRoundTripAsync(t *testing.T) { } loadReportDone := make(chan callbackResult[report.Report], 1) - s.LoadReport(id, turn, func(rep report.Report, err error) { + s.LoadReportAsync(id, turn, func(rep report.Report, err error) { loadReportDone <- callbackResult[report.Report]{value: rep, err: err} }) gotReport := waitResult(t, loadReportDone) @@ -104,7 +104,7 @@ func TestReportAndOrderRoundTripAsync(t *testing.T) { } loadOrderDone := make(chan callbackResult[order.Order], 1) - s.LoadOrder(id, turn, func(got order.Order, err error) { + s.LoadOrderAsync(id, turn, func(got order.Order, err error) { loadOrderDone <- callbackResult[order.Order]{value: got, err: err} }) gotOrder := waitResult(t, loadOrderDone) @@ -120,7 +120,7 @@ func TestSaveOrderBeforeReportReturnsNotExist(t *testing.T) { s := newTestStorage(t) done := make(chan error, 1) - s.SaveOrder("game-2", 3, sampleOrder(), func(err error) { + s.SaveOrderAsync("game-2", 3, sampleOrder(), func(err error) { done <- err }) err := waitError(t, done) @@ -390,7 +390,7 @@ func TestSaveStateIsNonBlockingAndCallbackBased(t *testing.T) { } callbacks := make(chan error, 2) - s.SaveState(sampleState(), func(err error) { + s.SaveStateAsync(sampleState(), func(err error) { callbacks <- err }) diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 5f41e06..0c28a7a 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -13,40 +13,42 @@ type Storage interface { WriteFile(string, []byte) error DeleteFile(string) error ListFiles() ([]string, error) + + // StateExistss() (bool, error) } // UIStorage manages Client's data local storing and retrieval. // It performs all I/O operations asynchronously to avoid UI main thread blocking. type UIStorage interface { - // StateExists check asynchronously for previously saved [model.State] exists on the filesystem. + // StateExistsAsync check asynchronously for previously saved [model.State] exists on the filesystem. // Passed callback func will will accept false and non-nil error in case of I/O or decoding errors occuried, // otherwise bool parameter will indicate existence of previously stores state - StateExists(func(bool, error)) + StateExistsAsync(func(bool, error)) - // LoadState loads Client's [model.State] from filesystem data asynchronously. + // LoadStateAsync loads Client's [model.State] from filesystem data asynchronously. // Passed callback func will accept non-nil error in case of I/O or decoding errors occuried, // otherwise callback func accepts loaded [model.State]. - LoadState(func(client.State, error)) + LoadStateAsync(func(client.State, error)) - // SaveState stores Client's state at the filesystem asynchronously. + // SaveStateAsync stores Client's state at the filesystem asynchronously. // I/O or encoding error may occur, it that case callback func will be called with non-nil error. - SaveState(client.State, func(error)) + SaveStateAsync(client.State, func(error)) - // LoadReport loads a [report.Report] for a given [model.GameID] and turn number from filesystem asynchronously. + // LoadReportAsync loads a [report.Report] for a given [model.GameID] and turn number from filesystem asynchronously. // Passed callback func will will accept non-nil error in case of I/O or decoding errors occuried, // otherwise callback func accepts loaded [report.Report]. - LoadReport(client.GameID, uint, func(report.Report, error)) + LoadReportAsync(client.GameID, uint, func(report.Report, error)) - // SaveReport stores given [report.Report] for a given [model.GameID] and turn number at the filesystem asynchronously. + // SaveReportAsync stores given [report.Report] for a given [model.GameID] and turn number at the filesystem asynchronously. // I/O or encoding error may occur, it that case callback func will be called with non-nil error. - SaveReport(client.GameID, uint, report.Report, func(error)) + SaveReportAsync(client.GameID, uint, report.Report, func(error)) - // LoadOrder loads a [order.Order] for a given [model.GameID] and turn number from filesystem asynchronously. + // LoadOrderAsync loads a [order.Order] for a given [model.GameID] and turn number from filesystem asynchronously. // Passed callback func will will accept non-nil error in case of I/O or decoding errors occuried, // otherwise callback func accepts loaded [order.Order]. - LoadOrder(client.GameID, uint, func(order.Order, error)) + LoadOrderAsync(client.GameID, uint, func(order.Order, error)) - // SaveOrder stores given [order.Order] for a given [model.GameID] and turn number at the filesystem asynchronously. + // SaveOrderAsync stores given [order.Order] for a given [model.GameID] and turn number at the filesystem asynchronously. // I/O or encoding error may occur, it that case callback func will be called with non-nil error. - SaveOrder(client.GameID, uint, order.Order, func(error)) + SaveOrderAsync(client.GameID, uint, order.Order, func(error)) }