feat: add config and structured logging
This commit is contained in:
parent
902a8bb7d1
commit
fe83dc1f33
9 changed files with 275 additions and 31 deletions
|
|
@ -2,9 +2,10 @@ package dependency
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"jws/internal/logger"
|
||||
osinfo "jws/internal/os"
|
||||
"jws/pkg/download"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
|
@ -17,6 +18,12 @@ import (
|
|||
"fyne.io/tools"
|
||||
)
|
||||
|
||||
var log *slog.Logger
|
||||
|
||||
func init() {
|
||||
log = logger.GetChildLogger("dependency")
|
||||
}
|
||||
|
||||
type Dependency struct {
|
||||
Name string
|
||||
Installed bool
|
||||
|
|
@ -24,6 +31,7 @@ type Dependency struct {
|
|||
}
|
||||
|
||||
func CheckDependencies(dependencies []Dependency) {
|
||||
log.Info("Checking dependencies")
|
||||
// Check VSCode
|
||||
dependencies[0].Installed = checkVSCode()
|
||||
|
||||
|
|
@ -100,7 +108,9 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
wslInstallCmd := tools.CommandInShell("wsl", "--install")
|
||||
err = wslInstallCmd.Run()
|
||||
if err != nil {
|
||||
dialog.ShowError(fmt.Errorf("error: installing WSL: %v", err), mainWindow)
|
||||
errMsg := fmt.Errorf("error: installing WSL: %v", err)
|
||||
dialog.ShowError(errMsg, mainWindow)
|
||||
log.Error(errMsg.Error())
|
||||
return
|
||||
}
|
||||
dialog.ShowInformation("WSL wird installiert", "WSL wird installiert. Bitte warten Sie, bis die Installation abgeschlossen ist und starten Sie die Anwendung neu.", mainWindow)
|
||||
|
|
@ -117,7 +127,9 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
brewInstallCmd := tools.CommandInShell("bin/bash", "-c", "\"$(curl -fsSl https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"")
|
||||
err := brewInstallCmd.Run()
|
||||
if err != nil {
|
||||
dialog.ShowError(fmt.Errorf("error: installing homebrew falied: %v", err), mainWindow)
|
||||
errMsg := fmt.Errorf("error: installing homebrew falied: %v", err)
|
||||
dialog.ShowError(errMsg, mainWindow)
|
||||
log.Error(errMsg.Error())
|
||||
}
|
||||
}
|
||||
switch index {
|
||||
|
|
@ -129,7 +141,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
case "linux":
|
||||
osInfo, err := osinfo.GetLinuxDistribution()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err.Error())
|
||||
dialog.ShowError(fmt.Errorf("error getting OS info: %v", err), mainWindow)
|
||||
return
|
||||
}
|
||||
|
|
@ -162,6 +174,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
progressDialog.Hide()
|
||||
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
dialog.ShowError(err, mainWindow)
|
||||
return
|
||||
}
|
||||
|
|
@ -182,7 +195,9 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
dialog.ShowError(fmt.Errorf("installation failed:\n%s", output), mainWindow)
|
||||
errMsg := fmt.Errorf("installation failed:\n%s", output)
|
||||
dialog.ShowError(errMsg, mainWindow)
|
||||
log.Error(errMsg.Error())
|
||||
return
|
||||
} else {
|
||||
dialog.ShowInformation("Erfolg", "VSCode erfolgreich installiert!", mainWindow)
|
||||
|
|
@ -198,7 +213,9 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
osInfo, err := osinfo.GetLinuxDistribution()
|
||||
if err != nil {
|
||||
progressDialog.Hide()
|
||||
dialog.ShowError(fmt.Errorf("error getting os infos: %v", err), mainWindow)
|
||||
errMsg := fmt.Errorf("error getting os infos: %v", err)
|
||||
dialog.ShowError(errMsg, mainWindow)
|
||||
log.Error(errMsg.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -268,7 +285,9 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
|
||||
if output, err := command.CombinedOutput(); err != nil {
|
||||
progressDialog.Hide()
|
||||
dialog.ShowError(fmt.Errorf("error at %s:\n%s", cmd, output), mainWindow)
|
||||
errMsg := fmt.Errorf("error at %s:\n%s", cmd, output)
|
||||
dialog.ShowError(errMsg, mainWindow)
|
||||
log.Error(errMsg.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +301,9 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
|
||||
if output, err := command.CombinedOutput(); err != nil {
|
||||
progressDialog.Hide()
|
||||
dialog.ShowError(fmt.Errorf("cleanup error at %s:\n%s", cmd, output), mainWindow)
|
||||
errMsg := fmt.Errorf("cleanup error at %s:\n%s", cmd, output)
|
||||
dialog.ShowError(errMsg, mainWindow)
|
||||
log.Error(errMsg.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -306,7 +327,9 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
|||
if cmd != nil {
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
dialog.ShowError(fmt.Errorf("error starting installation process: %v", err), mainWindow)
|
||||
errMsg := fmt.Errorf("error starting installation process: %v", err)
|
||||
dialog.ShowError(errMsg, mainWindow)
|
||||
log.Error(errMsg.Error())
|
||||
} else {
|
||||
dialog.ShowInformation("Installation started",
|
||||
fmt.Sprintf("Installation of %s was started", depName), mainWindow)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue