@@ -3,28 +3,30 @@ package app
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "os"
7
+ "path/filepath"
6
8
"sync"
7
9
8
10
"github.com/TrueBlocks/trueblocks-browse/pkg/daemons"
9
11
"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
10
12
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
11
13
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
12
14
coreConfig "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
13
- configTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes "
15
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file "
14
16
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
15
17
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
16
18
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
17
- coreUtils "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
19
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
18
20
sdk "github.com/TrueBlocks/trueblocks-sdk/v3"
19
21
"github.com/wailsapp/wails/v2/pkg/runtime"
20
22
)
21
23
22
24
type App struct {
23
25
sdk.Globals `json:",inline"`
24
26
25
- ctx context.Context
26
- cfg configTypes. Config
27
- meta coreTypes. MetaData
27
+ ctx context.Context
28
+ meta coreTypes. MetaData
29
+ dirty bool
28
30
29
31
renderCtxs map [base.Address ][]* output.RenderCtx
30
32
@@ -35,10 +37,15 @@ type App struct {
35
37
abis types.AbiContainer
36
38
indexes types.IndexContainer
37
39
manifests types.ManifestContainer
38
- settings types.SettingsGroup
39
- configs types.ConfigContainer
40
40
status types.StatusContainer
41
- sessions types.SessionContainer
41
+ settings types.SettingsGroup
42
+ session types.SessionContainer
43
+ config types.ConfigContainer
44
+
45
+ // Memory caches
46
+ HistoryCache * types.HistoryMap `json:"historyCache"`
47
+ EnsCache * sync.Map `json:"ensCache"`
48
+ BalanceCache * sync.Map `json:"balanceCache"`
42
49
43
50
// Controllers
44
51
ScraperController * daemons.DaemonScraper
@@ -50,9 +57,12 @@ func NewApp() *App {
50
57
a := App {
51
58
renderCtxs : make (map [base.Address ][]* output.RenderCtx ),
52
59
}
60
+ a .EnsCache = & sync.Map {}
61
+ a .BalanceCache = & sync.Map {}
62
+ a .HistoryCache = & types.HistoryMap {}
53
63
a .names .NamesMap = make (map [base.Address ]coreTypes.Name )
54
- a .projects = types .NewProjectContainer ("Untitled.tbx " , & types.HistoryMap {}, & sync. Map {}, & sync. Map {})
55
- a .sessions .LastSub = make (map [string ]string )
64
+ a .projects = types .NewProjectContainer ("" , [] types.HistoryContainer {})
65
+ a .session .LastSub = make (map [string ]string )
56
66
57
67
return & a
58
68
}
@@ -65,14 +75,21 @@ func (a *App) String() string {
65
75
func (a * App ) Startup (ctx context.Context ) {
66
76
a .ctx = ctx
67
77
a .loadSession ()
68
-
69
- go a .loadHistory (a .GetAddress (), nil , nil )
78
+ a .Chain = a .session .LastChain
70
79
71
80
a .FreshenController = daemons .NewFreshen (a , "freshen" , 3000 , a .IsShowing ("freshen" ))
72
81
a .ScraperController = daemons .NewScraper (a , "scraper" , 7000 , a .IsShowing ("scraper" ))
73
82
a .IpfsController = daemons .NewIpfs (a , "ipfs" , 10000 , a .IsShowing ("ipfs" ))
74
83
go a .startDaemons ()
75
84
85
+ fn := filepath .Join (a .session .LastFolder , a .session .LastFile )
86
+ if file .FileExists (fn ) {
87
+ a .LoadFile (fn )
88
+ a .dirty = false
89
+ } else {
90
+ a .dirty = true
91
+ }
92
+
76
93
logger .Info ("Starting freshen process..." )
77
94
_ = a .Refresh ()
78
95
}
@@ -83,12 +100,12 @@ func (a *App) DomReady(ctx context.Context) {
83
100
runtime .WindowSetSize (a .ctx , win .Width , win .Height )
84
101
runtime .WindowShow (a .ctx )
85
102
86
- if path , err := coreUtils .GetConfigFn ("" , "trueBlocks.toml" ); err != nil {
103
+ if path , err := utils .GetConfigFn ("" , "trueBlocks.toml" ); err != nil {
87
104
messages .EmitMessage (a .ctx , messages .Error , & messages.MessageMsg {
88
105
String1 : err .Error (),
89
106
})
90
107
} else {
91
- if err := coreConfig .ReadToml (path , & a .cfg ); err != nil {
108
+ if err := coreConfig .ReadToml (path , & a .config . Config ); err != nil {
92
109
messages .EmitMessage (a .ctx , messages .Error , & messages.MessageMsg {
93
110
String1 : err .Error (),
94
111
})
@@ -101,18 +118,26 @@ func (a *App) Shutdown(ctx context.Context) {
101
118
}
102
119
103
120
func (a * App ) saveSession () {
104
- a .sessions .Window .X , a .sessions .Window .Y = runtime .WindowGetPosition (a .ctx )
105
- a .sessions .Window .Width , a .sessions .Window .Height = runtime .WindowGetSize (a .ctx )
106
- a .sessions .Window .Y += 38 // TODO: This is a hack to account for the menu bar - not sure why it's needed
107
- _ = a .sessions .Save ()
121
+ if ! isTesting {
122
+ a .session .Window .X , a .session .Window .Y = runtime .WindowGetPosition (a .ctx )
123
+ a .session .Window .Width , a .session .Window .Height = runtime .WindowGetSize (a .ctx )
124
+ a .session .Window .Y += 38 // TODO: This is a hack to account for the menu bar - not sure why it's needed
125
+ }
126
+ _ = a .session .Save ()
108
127
}
109
128
110
129
func (a * App ) loadSession () {
111
- _ = a .sessions .Load ()
112
- a .sessions .CleanWindowSize (a .ctx )
113
- a .Chain = a .sessions .LastChain
130
+ _ = a .session .Load ()
131
+ a .session .CleanWindowSize (a .ctx )
132
+ a .Chain = a .session .LastChain
114
133
}
115
134
116
135
func (a * App ) Logger (msg string ) {
117
136
logger .Info (msg )
118
137
}
138
+
139
+ var isTesting bool
140
+
141
+ func init () {
142
+ isTesting = os .Getenv ("TB_TEST_MODE" ) == "true"
143
+ }
0 commit comments