8
8
"os"
9
9
"path/filepath"
10
10
11
+ log "github.com/sirupsen/logrus"
12
+
11
13
"github.com/arduino/arduino-create-agent/icon"
12
14
"github.com/getlantern/systray"
13
15
"github.com/go-ini/ini"
@@ -41,6 +43,10 @@ func (s *Systray) start() {
41
43
mUrl := systray .AddMenuItem ("Go to Arduino Create" , "Arduino Create" )
42
44
mDebug := systray .AddMenuItem ("Open Debug Console" , "Debug console" )
43
45
46
+ // Remove crash-reports
47
+ mRmCrashes := systray .AddMenuItem ("Remove crash reports" , "" )
48
+ s .updateMenuItem (mRmCrashes , s .CrashesIsEmpty ())
49
+
44
50
// Add pause/quit
45
51
mPause := systray .AddMenuItem ("Pause Plugin" , "" )
46
52
systray .AddSeparator ()
@@ -57,6 +63,9 @@ func (s *Systray) start() {
57
63
_ = open .Start ("https://create.arduino.cc" )
58
64
case <- mDebug .ClickedCh :
59
65
_ = open .Start (s .DebugURL ())
66
+ case <- mRmCrashes .ClickedCh :
67
+ s .RemoveCrashes ()
68
+ s .updateMenuItem (mRmCrashes , s .CrashesIsEmpty ())
60
69
case <- mPause .ClickedCh :
61
70
s .Pause ()
62
71
case <- mQuit .ClickedCh :
@@ -66,6 +75,43 @@ func (s *Systray) start() {
66
75
}()
67
76
}
68
77
78
+ // updateMenuItem will enable or disable an item in the tray icon menu id disable is true
79
+ func (s * Systray ) updateMenuItem (item * systray.MenuItem , disable bool ) {
80
+ if disable {
81
+ item .Disable ()
82
+ } else {
83
+ item .Enable ()
84
+ }
85
+ }
86
+
87
+ // CrashesIsEmpty checks if the folder containing crash-reports is empty
88
+ func (s * Systray ) CrashesIsEmpty () bool {
89
+ currDir , err := osext .ExecutableFolder ()
90
+ if err != nil {
91
+ log .Error ("Cannot determine executable path: " , err )
92
+ }
93
+ logsDir := filepath .Join (currDir , "logs" )
94
+ if _ , err := os .Stat (string (logsDir )); os .IsNotExist (err ) {
95
+ return true
96
+ }
97
+ return false
98
+ }
99
+
100
+ // RemoveCrashes removes the crash-reports from `logs` folder
101
+ func (s * Systray ) RemoveCrashes () {
102
+ currDir , err := osext .ExecutableFolder ()
103
+ if err != nil {
104
+ log .Error ("Cannot determine executable path: " , err )
105
+ }
106
+ logsDir := filepath .Join (currDir , "logs" )
107
+ pathErr := os .RemoveAll (logsDir )
108
+ if pathErr != nil {
109
+ log .Error ("Cannot remove crashreports: " , pathErr )
110
+ } else {
111
+ log .Info ("Removed crashreports inside: " , logsDir )
112
+ }
113
+ }
114
+
69
115
// starthibernate creates a systray icon with menu options to resume/quit the agent
70
116
func (s * Systray ) startHibernate () {
71
117
systray .SetIcon (icon .GetIconHiber ())
0 commit comments