Skip to content

Commit 28c44ac

Browse files
committed
Warn the user if a previous installation exists in $HOME/Applications/
1 parent 34ec33d commit 28c44ac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

main.go

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"encoding/json"
2424
"flag"
2525
"os"
26+
"os/exec"
2627
"runtime"
2728
"runtime/debug"
2829
"strconv"
@@ -168,6 +169,15 @@ func loop() {
168169
log.SetLevel(log.InfoLevel)
169170
log.SetOutput(os.Stdout)
170171

172+
// We used to install the agent in $HOME/Applications before versions <= 1.2.7-ventura
173+
// With version > 1.3.0 we changed the install path of the agent in /Applications.
174+
// If we are updating manually from 1.2.7 to 1.3.0 we have to uninstall the old agent manually first.
175+
// This check will inform the user if he needs to run the uninstall first
176+
if runtime.GOOS == "darwin" && oldInstallExists() {
177+
printDialog("Old agent installation of the Arduino Create Agent found, please uninstall it before launching the new one")
178+
os.Exit(0)
179+
}
180+
171181
// Instantiate Tools
172182
Tools = tools.Tools{
173183
Directory: config.GetDataDir().String(),
@@ -434,6 +444,18 @@ func loop() {
434444
}()
435445
}
436446

447+
// oldInstallExixts will return true if an old installation of the agent exixts (on macos)
448+
func oldInstallExists() bool {
449+
oldAgentPath := config.GetDefaultHomeDir().Join("Applications", "ArduinoCreateAgent")
450+
return oldAgentPath.Exist()
451+
}
452+
453+
// printDialog will print a GUI error dialog on macos
454+
func printDialog(dialogText string) {
455+
oscmd := exec.Command("osascript", "-e", "display dialog \""+dialogText+"\" buttons \"OK\" with title \"Error\"")
456+
_ = oscmd.Run()
457+
}
458+
437459
func parseIni(filename string) (args []string, err error) {
438460
cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename)
439461
if err != nil {

0 commit comments

Comments
 (0)