1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-07 21:37:04 +09:00

GO-5635 fix deviceState

This commit is contained in:
Roman Khafizianov 2025-05-15 17:28:14 +02:00
parent 0e5a3fa109
commit 2a52231bfa
No known key found for this signature in database
GPG key ID: F07A7D55A2684852
3 changed files with 9 additions and 10 deletions

View file

@ -71,11 +71,7 @@ func (s *Service) stop() error {
defer task.End()
if s != nil && s.app != nil {
s.app.IterateComponents(func(c app.Component) {
if c, ok := c.(app.ComponentStatable); ok {
c.StateChange(int(domain.CompStateAppClosingInitiated))
}
})
s.app.SetDeviceState(int(domain.CompStateAppClosingInitiated))
err := s.app.Close(ctx)
if err != nil {
log.Warnf("error while stop anytype: %v", err)

View file

@ -1,7 +1,11 @@
package domain
import "github.com/anyproto/anytype-heart/pb"
type CompState int
const (
CompStateAppClosingInitiated CompState = 1
CompStateAppWentBackground CompState = CompState(pb.RpcAppSetDeviceStateRequest_BACKGROUND) // 0
CompStateAppWentForeground CompState = CompState(pb.RpcAppSetDeviceStateRequest_FOREGROUND) // 1
CompStateAppClosingInitiated CompState = 2 // triggered by app
)

View file

@ -21,7 +21,6 @@ import (
"github.com/anyproto/anytype-heart/core/domain"
"github.com/anyproto/anytype-heart/core/files"
"github.com/anyproto/anytype-heart/core/files/fileobject"
"github.com/anyproto/anytype-heart/pb"
"github.com/anyproto/anytype-heart/pkg/lib/logging"
"github.com/anyproto/anytype-heart/util/constant"
"github.com/anyproto/anytype-heart/util/svg"
@ -130,10 +129,10 @@ func (g *gateway) Addr() string {
}
func (g *gateway) StateChange(state int) {
switch pb.RpcAppSetDeviceStateRequestDeviceState(state) {
case pb.RpcAppSetDeviceStateRequest_FOREGROUND:
switch domain.CompState(state) {
case domain.CompStateAppWentForeground:
g.startServer()
case pb.RpcAppSetDeviceStateRequest_BACKGROUND:
case domain.CompStateAppWentBackground, domain.CompStateAppClosingInitiated:
if err := g.stopServer(); err != nil {
log.Errorf("err gateway close: %+v", err)
}