Skip to content

Commit 5b019e5

Browse files
committed
new load state intro + settings create root folder (fix android if data purge)
1 parent a345539 commit 5b019e5

File tree

8 files changed

+236
-73
lines changed

8 files changed

+236
-73
lines changed

animation/animation.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func NewAnimation(startImmediately bool, sequence *gween.Sequence) *Animation {
2828
return &Animation{
2929
Sequence: sequence,
3030
stop: !startImmediately,
31+
active: startImmediately,
3132
}
3233
}
3334

build_vars.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION="0.2.3"
1+
VERSION="0.3.0"
22
VERSION_INCREMENT=1
33

44
FLAGS="-X github.com/g45t345rt/g45w/settings.Version=v$VERSION"

integrated_node/integrated_node.go

-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ func NewNodeSize(d time.Duration) *NodeSize {
183183
}
184184
}()
185185

186-
nodedSize.update()
187186
return nodedSize
188187
}
189188

load_state.go

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package main
2+
3+
import (
4+
"time"
5+
6+
"gioui.org/app"
7+
"gioui.org/font"
8+
"gioui.org/layout"
9+
"gioui.org/op"
10+
"gioui.org/op/paint"
11+
"gioui.org/unit"
12+
"gioui.org/widget/material"
13+
"github.com/g45t345rt/g45w/animation"
14+
"github.com/g45t345rt/g45w/assets"
15+
"github.com/g45t345rt/g45w/components"
16+
"github.com/tanema/gween"
17+
"github.com/tanema/gween/ease"
18+
)
19+
20+
type LogoSplash struct {
21+
animation *animation.Animation
22+
image *components.Image
23+
}
24+
25+
func NewLogoSplash() *LogoSplash {
26+
animtation := animation.NewAnimation(false, gween.NewSequence(
27+
gween.New(0, 1, 1, ease.Linear),
28+
))
29+
animtation.Sequence.SetLoop(-1)
30+
31+
src, _ := assets.GetImage("dero.jpg")
32+
33+
image := &components.Image{
34+
Src: paint.NewImageOp(src),
35+
Fit: components.Cover,
36+
}
37+
38+
return &LogoSplash{
39+
animation: animtation,
40+
image: image,
41+
}
42+
}
43+
44+
func (l *LogoSplash) Layout(gtx layout.Context) layout.Dimensions {
45+
r := op.Record(gtx.Ops)
46+
dims := l.image.Layout(gtx)
47+
c := r.Stop()
48+
49+
gtx.Constraints.Min = dims.Size
50+
51+
{
52+
state := l.animation.Update(gtx)
53+
if state.Active {
54+
defer animation.TransformRotate(gtx, state.Value).Push(gtx.Ops).Pop()
55+
}
56+
}
57+
58+
c.Add(gtx.Ops)
59+
return dims
60+
}
61+
62+
type LoadState struct {
63+
status string
64+
err error
65+
window *app.Window
66+
loaded bool
67+
logoSplash *LogoSplash
68+
}
69+
70+
func NewLoadState(window *app.Window) *LoadState {
71+
logoSplash := NewLogoSplash()
72+
return &LoadState{
73+
logoSplash: logoSplash,
74+
window: window,
75+
}
76+
}
77+
78+
func (l *LoadState) Complete() {
79+
l.loaded = true
80+
81+
l.window.Invalidate()
82+
time.Sleep(50 * time.Millisecond)
83+
}
84+
85+
func (l *LoadState) SetStatus(status string, err error) {
86+
if err != nil {
87+
l.err = err
88+
} else {
89+
l.status = status
90+
}
91+
92+
l.window.Invalidate()
93+
time.Sleep(50 * time.Millisecond)
94+
}
95+
96+
func (l *LoadState) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions {
97+
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
98+
gtx.Constraints.Min.X = gtx.Constraints.Max.X
99+
return layout.UniformInset(unit.Dp(30)).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
100+
if l.err != nil {
101+
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
102+
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
103+
lbl := material.Label(th, unit.Sp(20), l.status)
104+
lbl.Font.Weight = font.Bold
105+
return lbl.Layout(gtx)
106+
}),
107+
layout.Rigid(layout.Spacer{Height: unit.Dp(5)}.Layout),
108+
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
109+
lbl := material.Label(th, unit.Sp(16), l.err.Error())
110+
return lbl.Layout(gtx)
111+
}),
112+
)
113+
} else {
114+
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
115+
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
116+
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
117+
gtx.Constraints.Max.X = gtx.Dp(100)
118+
gtx.Constraints.Max.Y = gtx.Dp(100)
119+
return l.logoSplash.Layout(gtx)
120+
})
121+
}),
122+
layout.Rigid(layout.Spacer{Height: unit.Dp(40)}.Layout),
123+
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
124+
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
125+
lbl := material.Label(th, unit.Sp(20), l.status)
126+
lbl.Font.Weight = font.Bold
127+
return lbl.Layout(gtx)
128+
})
129+
}),
130+
)
131+
}
132+
})
133+
})
134+
}

main.go

+70-41
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,68 @@ func runApp(th *material.Theme) error {
6161
window := app_instance.Window
6262
router := app_instance.Router
6363
explorer := app_instance.Explorer
64+
65+
loadState := NewLoadState(window)
66+
67+
go func() {
68+
loadState.logoSplash.animation.Start()
69+
loadState.SetStatus("Initiating", nil) // don't use lang.Translate - lang is not loaded
70+
71+
err := lang.Load()
72+
if err != nil {
73+
loadState.SetStatus("", err)
74+
return
75+
}
76+
77+
loadState.SetStatus(lang.Translate("Loading settings"), nil)
78+
err = settings.Load()
79+
if err != nil {
80+
loadState.SetStatus("", err)
81+
return
82+
}
83+
84+
loadState.SetStatus(lang.Translate("Loading lookup table"), nil)
85+
walletapi.Initialize_LookupTable(1, 1<<21)
86+
87+
loadState.SetStatus(lang.Translate("Loading app data"), nil)
88+
err = app_data.Load()
89+
if err != nil {
90+
loadState.SetStatus("", err)
91+
return
92+
}
93+
94+
loadState.SetStatus(lang.Translate("Loading wallets"), nil)
95+
err = wallet_manager.Load()
96+
if err != nil {
97+
loadState.SetStatus("", err)
98+
return
99+
}
100+
101+
loadState.SetStatus(lang.Translate("Checking node"), nil)
102+
err = node_manager.Load()
103+
if err != nil {
104+
loadState.SetStatus("", err)
105+
return
106+
}
107+
108+
loadState.SetStatus(lang.Translate("Loading pages"), nil)
109+
bottom_bar.LoadInstance()
110+
node_status_bar.LoadInstance()
111+
notification_modals.LoadInstance()
112+
recent_txs_modal.LoadInstance()
113+
build_tx_modal.LoadInstance()
114+
115+
router.Add(app_instance.PAGE_NODE, page_node.New())
116+
router.Add(app_instance.PAGE_WALLET, page_wallet.New())
117+
router.Add(app_instance.PAGE_WALLET_SELECT, page_wallet_select.New())
118+
router.Add(app_instance.PAGE_SETTINGS, page_settings.New())
119+
router.SetCurrent(app_instance.PAGE_WALLET_SELECT)
120+
121+
loadState.logoSplash.animation.Pause()
122+
loadState.SetStatus(lang.Translate("Done"), nil)
123+
loadState.Complete()
124+
}()
125+
64126
for {
65127
e := <-window.Events()
66128
explorer.ListenEvents(e)
@@ -69,7 +131,13 @@ func runApp(th *material.Theme) error {
69131
return e.Err
70132
case system.FrameEvent:
71133
gtx := layout.NewContext(&ops, e)
72-
router.Layout(gtx, th)
134+
135+
if loadState.loaded {
136+
router.Layout(gtx, th)
137+
} else {
138+
loadState.Layout(gtx, th)
139+
}
140+
73141
e.Frame(gtx.Ops)
74142
}
75143
}
@@ -83,41 +151,14 @@ func main() {
83151
globals.Arguments["--help"] = false
84152
globals.Arguments["--version"] = false
85153

86-
walletapi.Initialize_LookupTable(1, 1<<21)
87-
88-
err := settings.Load()
89-
if err != nil {
90-
log.Fatal(err)
91-
}
92-
93-
err = lang.Load()
94-
if err != nil {
95-
log.Fatal(err)
96-
}
97-
98-
err = app_data.Load()
99-
if err != nil {
100-
log.Fatal(err)
101-
}
102-
103-
err = wallet_manager.Load()
104-
if err != nil {
105-
log.Fatal(err)
106-
}
107-
108-
err = node_manager.Load()
109-
if err != nil {
110-
log.Fatal(err)
111-
}
112-
113154
// window
114155
minSizeX := unit.Dp(375)
115156
minSizeY := unit.Dp(600)
116157
maxSizeX := unit.Dp(500)
117158
maxSizeY := unit.Dp(1000)
118159

119160
window := app.NewWindow(
120-
app.Title("G45W"),
161+
app.Title(settings.Name),
121162
app.MinSize(minSizeX, minSizeY),
122163
app.Size(minSizeX, minSizeY),
123164
app.MaxSize(maxSizeX, maxSizeY),
@@ -151,18 +192,6 @@ func main() {
151192
app_instance.Router = appRouter
152193
app_instance.Explorer = explorer
153194

154-
bottom_bar.LoadInstance()
155-
node_status_bar.LoadInstance()
156-
notification_modals.LoadInstance()
157-
recent_txs_modal.LoadInstance()
158-
build_tx_modal.LoadInstance()
159-
160-
appRouter.Add(app_instance.PAGE_NODE, page_node.New())
161-
appRouter.Add(app_instance.PAGE_WALLET, page_wallet.New())
162-
appRouter.Add(app_instance.PAGE_WALLET_SELECT, page_wallet_select.New())
163-
appRouter.Add(app_instance.PAGE_SETTINGS, page_settings.New())
164-
appRouter.SetCurrent(app_instance.PAGE_WALLET_SELECT)
165-
166195
go func() {
167196
err := runApp(theme)
168197
if err != nil {

pages/wallet/receive_form.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package page_wallet
33
import (
44
"bytes"
55
"image"
6-
"log"
76

87
"gioui.org/font"
98
"gioui.org/layout"
@@ -16,6 +15,7 @@ import (
1615
"github.com/g45t345rt/g45w/animation"
1716
"github.com/g45t345rt/g45w/components"
1817
"github.com/g45t345rt/g45w/router"
18+
"github.com/g45t345rt/g45w/wallet_manager"
1919
qrcode "github.com/skip2/go-qrcode"
2020
"github.com/tanema/gween"
2121
"github.com/tanema/gween/ease"
@@ -71,18 +71,9 @@ func (p *PageReceiveForm) Enter() {
7171
p.animationLeave.Reset()
7272
}
7373

74-
// gio ui does not implement character break yet https://todo.sr.ht/~eliasnaur/gio/467
75-
addr := "dero1qyvzwypmgqrqpsr8xlz209mwr6sz8fu9a4fphkpnesg29du40zw22qqpm2nkv"
76-
77-
imgBytes, err := qrcode.Encode(addr, qrcode.Medium, 256)
78-
if err != nil {
79-
log.Fatal(err)
80-
}
81-
82-
img, _, err := image.Decode(bytes.NewBuffer(imgBytes))
83-
if err != nil {
84-
log.Fatal(err)
85-
}
74+
addr := wallet_manager.OpenedWallet.Info.Addr
75+
imgBytes, _ := qrcode.Encode(addr, qrcode.Medium, 256)
76+
img, _, _ := image.Decode(bytes.NewBuffer(imgBytes))
8677

8778
p.addrImage = &components.Image{
8879
Src: paint.NewImageOp(img),

prefabs/lang_selector.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package prefabs
33
import (
44
"fmt"
55
"image/color"
6-
"log"
76

87
"gioui.org/font"
98
"gioui.org/layout"
@@ -47,10 +46,7 @@ func NewLangSelector(defaultLangKey string) *LangSelector {
4746

4847
languages := lang.SupportedLanguages
4948
for _, language := range languages {
50-
img, err := assets.GetImage(language.ImgPath)
51-
if err != nil {
52-
log.Fatal(err)
53-
}
49+
img, _ := assets.GetImage(language.ImgPath)
5450

5551
langImg := &components.Image{
5652
Src: paint.NewImageOp(img),

0 commit comments

Comments
 (0)