9
9
"os"
10
10
"os/user"
11
11
"path/filepath"
12
+ "runtime"
12
13
"time"
13
14
14
15
astilectron "github.com/asticode/go-astilectron"
@@ -22,8 +23,6 @@ import (
22
23
type GUI struct {
23
24
// window is the main Astilectron window
24
25
window * astilectron.Window
25
- // // minerCmd is a reference to the xmr-stak miner process
26
- // minerCmd *exec.Cmd
27
26
// astilectronOptions holds the Astilectron options
28
27
astilectronOptions bootstrap.Options
29
28
// config for the miner
@@ -51,21 +50,13 @@ func New(
51
50
asset bootstrap.Asset ,
52
51
restoreAssets bootstrap.RestoreAssets ,
53
52
apiEndpoint string ,
53
+ workingDir string ,
54
54
isDebug bool ) (* GUI , error ) {
55
55
56
56
if apiEndpoint == "" {
57
57
return nil , errors .New ("The API Endpoint must be specified" )
58
58
}
59
59
60
- workingDir , err := os .Getwd ()
61
- if err != nil {
62
- return nil , fmt .Errorf ("Can't read current directory: %s" , err )
63
- }
64
- workingDir , err = filepath .Abs (workingDir )
65
- if err != nil {
66
- return nil , fmt .Errorf ("Can't read current directory: %s" , err )
67
- }
68
-
69
60
gui := GUI {
70
61
config : config ,
71
62
workingDir : workingDir ,
@@ -89,6 +80,65 @@ func New(
89
80
Mid : uuid .New ().String (),
90
81
}
91
82
}
83
+ var menu []* astilectron.MenuItemOptions
84
+
85
+ // Setup the logging, by default we log to stdout
86
+ logrus .SetFormatter (& logrus.TextFormatter {
87
+ FullTimestamp : true ,
88
+ TimestampFormat : "Jan 02 15:04:05" ,
89
+ })
90
+ logrus .SetLevel (logrus .InfoLevel )
91
+
92
+ logrus .SetOutput (os .Stdout )
93
+ if isDebug {
94
+ logrus .SetLevel (logrus .DebugLevel )
95
+ debugLog , err := os .OpenFile (
96
+ filepath .Join (gui .workingDir , "debug.log" ),
97
+ os .O_CREATE | os .O_TRUNC | os .O_WRONLY ,
98
+ 0644 )
99
+ if err != nil {
100
+ panic (err )
101
+ }
102
+ logrus .SetOutput (debugLog )
103
+
104
+ // We only show the menu bar in debug mode
105
+ menu = append (menu , & astilectron.MenuItemOptions {
106
+ Label : astilectron .PtrStr ("File" ),
107
+ SubMenu : []* astilectron.MenuItemOptions {
108
+ {
109
+ Role : astilectron .MenuItemRoleClose ,
110
+ },
111
+ },
112
+ })
113
+ }
114
+ // To make copy and paste work on Mac, the copy and paste entries need to
115
+ // be defined, the alternative is to implement the clipboard API
116
+ // https://github.com/electron/electron/blob/master/docs/api/clipboard.md
117
+ if runtime .GOOS == "darwin" {
118
+ menu = append (menu , & astilectron.MenuItemOptions {
119
+ Label : astilectron .PtrStr ("Edit" ),
120
+ SubMenu : []* astilectron.MenuItemOptions {
121
+ {
122
+ Role : astilectron .MenuItemRoleCut ,
123
+ },
124
+ {
125
+ Role : astilectron .MenuItemRoleCopy ,
126
+ },
127
+ {
128
+ Role : astilectron .MenuItemRolePaste ,
129
+ },
130
+ {
131
+ Role : astilectron .MenuItemRoleSelectAll ,
132
+ },
133
+ },
134
+ })
135
+ }
136
+
137
+ // Setting the WithFields now will ensure all log entries from this point
138
+ // includes the fields
139
+ gui .logger = logrus .WithFields (logrus.Fields {
140
+ "service" : "stellite-gui-miner" ,
141
+ })
92
142
93
143
gui .astilectronOptions = bootstrap.Options {
94
144
Debug : isDebug ,
@@ -101,20 +151,20 @@ func New(
101
151
AppIconDefaultPath : "resources/icon.png" ,
102
152
},
103
153
WindowOptions : & astilectron.WindowOptions {
104
- Title : astilectron .PtrStr ("Stellite GUI Miner" ),
154
+ // TODO: Frameless looks amazing, first I'd need to implement draggable
155
+ // sections and control buttons
156
+ //Frame: astilectron.PtrBool(false),
105
157
BackgroundColor : astilectron .PtrStr ("#0B0C22" ),
106
158
Center : astilectron .PtrBool (true ),
107
159
Height : astilectron .PtrInt (700 ),
108
160
Width : astilectron .PtrInt (1175 ),
109
161
},
110
- MenuOptions : []* astilectron.MenuItemOptions {{
111
- Label : astilectron .PtrStr ("File" ),
112
- SubMenu : []* astilectron.MenuItemOptions {
113
- {
114
- Role : astilectron .MenuItemRoleClose ,
115
- },
116
- },
117
- }},
162
+ // TODO: Fix this tray to display nicely
163
+ /*TrayOptions: &astilectron.TrayOptions{
164
+ Image: astilectron.PtrStr("/static/i/miner-logo.png"),
165
+ Tooltip: astilectron.PtrStr(appName),
166
+ },*/
167
+ MenuOptions : menu ,
118
168
// OnWait is triggered as soon as the electron window is ready and running
119
169
OnWait : func (
120
170
_ * astilectron.Astilectron ,
@@ -139,32 +189,6 @@ func New(
139
189
MessageHandler : gui .handleElectronCommands ,
140
190
}
141
191
142
- // Setup the logging, by default we log to stdout
143
- logrus .SetFormatter (& logrus.TextFormatter {
144
- FullTimestamp : true ,
145
- TimestampFormat : "Jan 02 15:04:05" ,
146
- })
147
- logrus .SetLevel (logrus .InfoLevel )
148
-
149
- logrus .SetOutput (os .Stdout )
150
- if isDebug {
151
- logrus .SetLevel (logrus .DebugLevel )
152
- // TODO: Handle this debug log better
153
- debugLog , err := os .OpenFile (
154
- fmt .Sprintf (".%c%s" , os .PathSeparator , "debug.log" ),
155
- os .O_CREATE | os .O_TRUNC | os .O_WRONLY ,
156
- 0644 )
157
- if err != nil {
158
- panic (err )
159
- }
160
- logrus .SetOutput (debugLog )
161
- }
162
- // Setting the WithFields now will ensure all log entries from this point
163
- // includes the fields
164
- gui .logger = logrus .WithFields (logrus.Fields {
165
- "service" : "stellite-gui-miner" ,
166
- })
167
-
168
192
gui .logger .Info ("Setup complete" )
169
193
return & gui , nil
170
194
}
@@ -315,10 +339,10 @@ func (gui *GUI) configureMiner(command bootstrap.MessageIn) {
315
339
gui .logger .Fatalf ("Unable to configure miner: '%s'" , err )
316
340
}
317
341
scanPath := filepath .Join (gui .workingDir , "miner" )
318
- if gui . config . Miner . Path != "" {
319
- // TODO: Fix own miner paths option
342
+ // TODO: Fix own miner paths option
343
+ /*if gui.config.Miner.Path != "" {
320
344
//scanPath = path.Base(gui.config.Miner.Path)
321
- }
345
+ }*/
322
346
gui .logger .WithField (
323
347
"scan_path" , scanPath ,
324
348
).Debug ("Determining miner type" )
0 commit comments