@@ -22,11 +22,13 @@ package systray
22
22
import (
23
23
"fmt"
24
24
"os"
25
+ "os/user"
25
26
"path/filepath"
26
27
27
28
log "github.com/sirupsen/logrus"
28
29
29
30
"github.com/arduino/arduino-create-agent/icon"
31
+ "github.com/arduino/go-paths-helper"
30
32
"github.com/getlantern/systray"
31
33
"github.com/go-ini/ini"
32
34
"github.com/skratchdot/open-golang/open"
@@ -101,32 +103,29 @@ func (s *Systray) updateMenuItem(item *systray.MenuItem, disable bool) {
101
103
102
104
// CrashesIsEmpty checks if the folder containing crash-reports is empty
103
105
func (s * Systray ) CrashesIsEmpty () bool {
104
- currDir , err := os .Getwd ()
105
- if err != nil {
106
- log .Error ("Cannot determine executable path: " , err )
107
- }
108
- logsDir := filepath .Join (currDir , "logs" )
109
- if _ , err := os .Stat (string (logsDir )); os .IsNotExist (err ) {
110
- return true
111
- }
112
- return false
106
+ logsDir := getLogsDir ()
107
+ return logsDir .NotExist () // if the logs directory is empty we assume there are no crashreports
113
108
}
114
109
115
110
// RemoveCrashes removes the crash-reports from `logs` folder
116
111
func (s * Systray ) RemoveCrashes () {
117
- currDir , err := os .Getwd ()
118
- if err != nil {
119
- log .Error ("Cannot determine executable path: " , err )
120
- }
121
- logsDir := filepath .Join (currDir , "logs" )
122
- pathErr := os .RemoveAll (logsDir )
112
+ logsDir := getLogsDir ()
113
+ pathErr := logsDir .RemoveAll ()
123
114
if pathErr != nil {
124
- log .Error ("Cannot remove crashreports: " , pathErr )
115
+ log .Errorf ("Cannot remove crashreports: %s " , pathErr )
125
116
} else {
126
- log .Info ("Removed crashreports inside: " , logsDir )
117
+ log .Infof ("Removed crashreports inside: %s " , logsDir )
127
118
}
128
119
}
129
120
121
+ // getLogsDir simply returns the folder containing the logs
122
+ func getLogsDir () * paths.Path {
123
+ usr , _ := user .Current ()
124
+ usrDir := paths .New (usr .HomeDir ) // The user folder, on linux/macos /home/<usr>/
125
+ agentDir := usrDir .Join (".arduino-create" )
126
+ return agentDir .Join ("logs" )
127
+ }
128
+
130
129
// starthibernate creates a systray icon with menu options to resume/quit the agent
131
130
func (s * Systray ) startHibernate () {
132
131
systray .SetIcon (icon .GetIconHiber ())
@@ -189,7 +188,7 @@ type configIni struct {
189
188
// getconfigs parses all config files in the executable folder
190
189
func getConfigs () []configIni {
191
190
// config.ini must be there, so call it Default
192
- src , _ := os .Executable ()
191
+ src , _ := os .Executable () // TODO change path
193
192
dest := filepath .Dir (src )
194
193
195
194
var configs []configIni
0 commit comments