-
Notifications
You must be signed in to change notification settings - Fork 138
/
main.go
120 lines (100 loc) · 2.85 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
117
118
119
120
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime/debug"
_ "embed"
"github.com/marcsauter/single"
"github.com/vertcoin-project/one-click-miner-vnext/backend"
"github.com/vertcoin-project/one-click-miner-vnext/logging"
"github.com/vertcoin-project/one-click-miner-vnext/networks"
"github.com/vertcoin-project/one-click-miner-vnext/tracking"
"github.com/vertcoin-project/one-click-miner-vnext/util"
"github.com/wailsapp/wails"
)
//nolint:all
//go:embed frontend/dist/app.js
var js string
//nolint:all
//go:embed frontend/dist/app.css
var css string
func main() {
defer func() {
if err := recover(); err != nil {
// Reopen log file, since it's closed now!
logging.SetLogLevel(int(logging.LogLevelDebug))
logFilePath := filepath.Join(util.DataDirectory(), "debug.log")
logFile, _ := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
logging.SetLogFile(logFile)
defer logFile.Close()
logging.Errorf("%v\n%s\n", err, string(debug.Stack()))
tracking.Track(tracking.TrackingRequest{
Category: "Lifecycle",
Action: "Crash",
Name: fmt.Sprintf("%v", err),
})
}
}()
tracking.StartTracker()
tracking.Track(tracking.TrackingRequest{
Category: "Lifecycle",
Action: "Startup",
Name: fmt.Sprintf("OCM/%s", tracking.GetVersion()),
})
logging.SetLogLevel(int(logging.LogLevelDebug))
if _, err := os.Stat(util.DataDirectory()); os.IsNotExist(err) {
logging.Infof("Creating data directory")
err = os.MkdirAll(util.DataDirectory(), 0700)
if err != nil && !os.IsExist(err) {
logging.Errorf("Error creating data directory, cannot continue")
os.Exit(1)
}
}
logFilePath := filepath.Join(util.DataDirectory(), "debug.log")
logFile, _ := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
logging.SetLogFile(logFile)
defer logFile.Close()
log.Printf("OCM v%s Started up\n", tracking.GetVersion())
app := wails.CreateApp(&wails.AppConfig{
Width: 800,
Height: 400,
Title: "Vertcoin One Click Miner",
JS: js,
CSS: css,
Colour: "#131313",
})
alreadyRunning := false
s := single.New("vertcoin-ocm")
if err := s.CheckLock(); err != nil && err == single.ErrAlreadyRunning {
alreadyRunning = true
} else if err == nil {
defer func() {
err := s.TryUnlock()
if err != nil {
logging.Errorf("Error unlocking OCM: %v", err)
}
}()
}
backend, err := backend.NewBackend(alreadyRunning)
if err != nil {
logging.Errorf("Error creating Backend: %s", err.Error())
panic(err)
}
networks.SetNetwork(backend.GetTestnet())
go backend.BackendServerSelector()
go backend.SelectP2PoolNode()
backend.ResetPool()
app.Bind(backend)
err = app.Run()
if err != nil {
logging.Errorf("Error running app: %v", err)
}
backend.StopMining()
tracking.Track(tracking.TrackingRequest{
Category: "Lifecycle",
Action: "Shutdown",
})
tracking.Stop()
}