Skip to content

Commit 55ca9e5

Browse files
committedJan 22, 2025
remove global systray
1 parent c41b815 commit 55ca9e5

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed
 

‎hub.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ func checkCmd(m []byte) {
223223
go logAction(sl)
224224
} else if strings.HasPrefix(sl, "restart") {
225225
log.Println("Received restart from the daemon. Why? Boh")
226-
Systray.Restart()
226+
// TODO enable them
227+
// Systray.Restart()
227228
} else if strings.HasPrefix(sl, "exit") {
228-
Systray.Quit()
229+
// Systray.Quit()
229230
} else if strings.HasPrefix(sl, "memstats") {
230231
memoryStats()
231232
} else if strings.HasPrefix(sl, "gc") {

‎info.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"runtime"
2020
"strings"
2121

22+
"github.com/arduino/arduino-create-agent/systray"
2223
"github.com/gin-gonic/gin"
2324
"go.bug.st/serial"
2425
)
@@ -40,14 +41,16 @@ func infoHandler(c *gin.Context) {
4041
})
4142
}
4243

43-
func pauseHandler(c *gin.Context) {
44-
go func() {
45-
ports, _ := serial.GetPortsList()
46-
for _, element := range ports {
47-
spClose(element)
48-
}
49-
*hibernate = true
50-
Systray.Pause()
51-
}()
52-
c.JSON(200, nil)
44+
func PauseHandler(s *systray.Systray) func(c *gin.Context) {
45+
return func(c *gin.Context) {
46+
go func() {
47+
ports, _ := serial.GetPortsList()
48+
for _, element := range ports {
49+
spClose(element)
50+
}
51+
*hibernate = true
52+
s.Pause()
53+
}()
54+
c.JSON(200, nil)
55+
}
5356
}

‎main.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ var homeTemplateHTML string
103103

104104
// global clients
105105
var (
106-
Tools *tools.Tools
107-
Systray systray.Systray
108-
Index *index.Resource
106+
Tools *tools.Tools
107+
Index *index.Resource
109108
)
110109

111110
type logWriter struct{}
@@ -145,12 +144,10 @@ func main() {
145144
configPath := config.GetConfigPath()
146145
fmt.Println("configPath: ", configPath)
147146

148-
// Launch main loop in a goroutine
149-
go loop(configPath)
150-
151147
// SetupSystray is the main thread
152148
configDir := config.GetDefaultConfigDir()
153-
Systray = systray.Systray{
149+
150+
stray := &systray.Systray{
154151
Hibernate: *hibernate,
155152
Version: version + "-" + commit,
156153
DebugURL: func() string {
@@ -159,18 +156,21 @@ func main() {
159156
AdditionalConfig: *additionalConfig,
160157
ConfigDir: configDir,
161158
}
162-
Systray.SetCurrentConfigFile(configPath)
159+
stray.SetCurrentConfigFile(configPath)
160+
161+
// Launch main loop in a goroutine
162+
go loop(stray, configPath)
163163

164164
if src, err := os.Executable(); err != nil {
165165
panic(err)
166166
} else if restartPath := updater.Start(src); restartPath != "" {
167-
Systray.RestartWith(restartPath)
167+
stray.RestartWith(restartPath)
168168
} else {
169-
Systray.Start()
169+
stray.Start()
170170
}
171171
}
172172

173-
func loop(configPath *paths.Path) {
173+
func loop(stray *systray.Systray, configPath *paths.Path) {
174174
if *hibernate {
175175
return
176176
}
@@ -435,8 +435,8 @@ func loop(configPath *paths.Path) {
435435
r.Handle("WS", "/socket.io/", socketHandler)
436436
r.Handle("WSS", "/socket.io/", socketHandler)
437437
r.GET("/info", infoHandler)
438-
r.POST("/pause", pauseHandler)
439-
r.POST("/update", updateHandler)
438+
r.POST("/pause", PauseHandler(stray))
439+
r.POST("/update", UpdateHandler(stray))
440440

441441
// Mount goa handlers
442442
goa := v2.Server(config.GetDataDir().String(), Index)

‎update.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,23 @@
3030
package main
3131

3232
import (
33+
"github.com/arduino/arduino-create-agent/systray"
3334
"github.com/arduino/arduino-create-agent/updater"
3435
"github.com/gin-gonic/gin"
3536
)
3637

37-
func updateHandler(c *gin.Context) {
38-
restartPath, err := updater.CheckForUpdates(version, *updateURL, *appName)
39-
if err != nil {
40-
c.JSON(500, gin.H{"error": err.Error()})
41-
return
42-
}
43-
c.JSON(200, gin.H{"success": "Please wait a moment while the agent reboots itself"})
44-
if restartPath == "quit" {
45-
Systray.Quit()
46-
} else {
47-
Systray.RestartWith(restartPath)
38+
func UpdateHandler(s *systray.Systray) func(c *gin.Context) {
39+
return func(c *gin.Context) {
40+
restartPath, err := updater.CheckForUpdates(version, *updateURL, *appName)
41+
if err != nil {
42+
c.JSON(500, gin.H{"error": err.Error()})
43+
return
44+
}
45+
c.JSON(200, gin.H{"success": "Please wait a moment while the agent reboots itself"})
46+
if restartPath == "quit" {
47+
s.Quit()
48+
} else {
49+
s.RestartWith(restartPath)
50+
}
4851
}
4952
}

0 commit comments

Comments
 (0)
Please sign in to comment.