forked from crypto-power/cryptopower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
116 lines (99 loc) · 2.63 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
"time"
"gioui.org/app"
"github.com/crypto-power/cryptopower/libwallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/logger"
"github.com/crypto-power/cryptopower/ui"
_ "github.com/crypto-power/cryptopower/ui/assets"
)
const (
devBuild = "dev"
prodBuild = "prod"
)
var (
// Version is the application version. It is set using the -ldflags
Version = "1.7.0"
// BuildDate is the date the application was built. It is set using the -ldflags
BuildDate string
// BuildEnv is the build environment. It is set using the -ldflags
BuildEnv = devBuild
)
func main() {
cfg, err := loadConfig()
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
// before the asset manager is initialized use command line debuglevel option if passed or
// default to log level info for startup logs.
if cfg.DebugLevel == "" {
logger.SetLogLevels(utils.LogLevelInfo)
} else {
logger.SetLogLevels(cfg.DebugLevel)
}
if cfg.Profile > 0 {
go func() {
log.Info(fmt.Sprintf("Starting profiling server on port %d", cfg.Profile))
log.Error(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", cfg.Profile), nil))
}()
}
var buildDate time.Time
if BuildEnv == prodBuild {
buildDate, err = time.Parse(time.RFC3339, BuildDate)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
} else {
buildDate = time.Now()
}
var net string
switch cfg.Network {
case "testnet":
net = "testnet3"
default:
net = cfg.Network
}
logDir := filepath.Join(cfg.LogDir, net)
assetsManager, err := libwallet.NewAssetsManager(cfg.HomeDir, logDir, net)
if err != nil {
log.Errorf("init assetsManager error: %v", err)
return
}
// if debuglevel is passed at commandLine persist the option.
if cfg.DebugLevel != "" && assetsManager.IsAssetManagerDB() {
assetsManager.SetLogLevels(cfg.DebugLevel)
}
if assetsManager.IsAssetManagerDB() {
// now that assets manager is up, set stored debuglevel
logger.SetLogLevels(assetsManager.GetLogLevels())
}
win, err := ui.CreateWindow(assetsManager, Version, buildDate)
if err != nil {
log.Errorf("Could not initialize window: %s\ns", err)
return
}
go func() {
// Wait until we receive the shutdown request.
<-win.Quit
// Terminate all the backend processes safely.
assetsManager.Shutdown()
// Backend process terminated safely trigger app shutdown now.
win.IsShutdown <- struct{}{}
}()
go func() {
// blocks until the backend processes terminate.
win.HandleEvents()
// Exit the app.
os.Exit(0)
}()
// Start the GUI frontend.
app.Main()
}