feat: improve usability by including a progressbar while installing packages on windows and mac

This commit is contained in:
Patryk Hegenberg 2025-03-20 20:16:22 +01:00
parent 26bdcd9a6a
commit c903fa1803
2 changed files with 267 additions and 229 deletions

View file

@ -13,6 +13,7 @@ import (
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"fyne.io/tools"
@ -97,6 +98,29 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
switch runtime.GOOS {
case "windows":
cmd, err = installWindowsDependencies(index, cmd, &mainWindow)
if err != nil {
dialog.ShowError(err, mainWindow)
log.Error(err.Error())
}
case "darwin":
cmd, err = installDarwinDependencies(index, cmd, &mainWindow)
dialog.ShowError(err, mainWindow)
log.Error(err.Error())
case "linux":
err = installLinuxDependencies(index, sudoPassword, cmd, dependencies, &mainWindow)
if err != nil {
log.Error(err.Error())
dialog.ShowError(err, mainWindow)
}
}
if cmd != nil {
showInstallProgressBar(mainWindow, fmt.Sprintf("installing %v", depName), cmd, depName, dependencies)
}
}
func installWindowsDependencies(index int, cmd *exec.Cmd, mainWindow *fyne.Window) (*exec.Cmd, error) {
switch index {
case 0: // VSCode
cmd = tools.CommandInShell("winget", "install", "-e", "--id",
@ -105,22 +129,23 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
wslCheckCmd := tools.CommandInShell("wsl", "--status")
err := wslCheckCmd.Run()
if err != nil {
wslInstallCmd := tools.CommandInShell("wsl", "--install")
wslInstallCmd := tools.CommandInShell("wsl", "--install", "ubuntu")
dialog.ShowInformation("WSL wird installiert", "WSL wird installiert. Bitte warten Sie, bis die Installation abgeschlossen ist und starten Sie die Anwendung neu.", *mainWindow)
err = wslInstallCmd.Run()
if err != nil {
errMsg := fmt.Errorf("error: installing WSL: %v", err)
dialog.ShowError(errMsg, mainWindow)
log.Error(errMsg.Error())
return
return nil, errMsg
}
dialog.ShowInformation("WSL wird installiert", "WSL wird installiert. Bitte warten Sie, bis die Installation abgeschlossen ist und starten Sie die Anwendung neu.", mainWindow)
return
return nil, err
}
cmd = tools.CommandInShell("winget", "install", "-e", "--id",
"Docker.DockerDesktop")
}
case "darwin":
return cmd, nil
}
func installDarwinDependencies(index int, cmd *exec.Cmd, mainWindow *fyne.Window) (*exec.Cmd, error) {
brewCheckCmd := tools.CommandInShell("which", "brew")
err := brewCheckCmd.Run()
if err != nil {
@ -128,8 +153,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
err := brewInstallCmd.Run()
if err != nil {
errMsg := fmt.Errorf("error: installing homebrew falied: %v", err)
dialog.ShowError(errMsg, mainWindow)
log.Error(errMsg.Error())
return nil, errMsg
}
}
switch index {
@ -138,12 +162,14 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
case 1: // Docker
cmd = tools.CommandInShell("brew", "install", "docker")
}
case "linux":
return cmd, nil
}
func installLinuxDependencies(index int, sudoPassword string, cmd *exec.Cmd, dependencies []Dependency, mainWindow *fyne.Window) error {
osInfo, err := osinfo.GetLinuxDistribution()
if err != nil {
log.Error(err.Error())
dialog.ShowError(fmt.Errorf("error getting OS info: %v", err), mainWindow)
return
errMsg := fmt.Errorf("error getting OS info: %v", err)
return errMsg
}
var downloadURL, fileName string
@ -157,12 +183,12 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
downloadURL = "https://code.visualstudio.com/sha/download?build=stable&os=linux-rpm-x64"
fileName = "vscode.rpm"
default:
dialog.ShowInformation("Nicht unterstützt", fmt.Sprintf("Automatische Installation für dieses OS %v nicht verfügbar", osInfo), mainWindow)
return
dialog.ShowInformation("Nicht unterstützt", fmt.Sprintf("Automatische Installation für dieses OS %v nicht verfügbar", osInfo), *mainWindow)
return nil
}
go func() {
progressBar := widget.NewProgressBar()
progressDialog := dialog.NewCustomWithoutButtons("Download in progress", progressBar, mainWindow)
progressDialog := dialog.NewCustomWithoutButtons("Download in progress", progressBar, *mainWindow)
progressDialog.Show()
@ -175,7 +201,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
if err != nil {
log.Error(err.Error())
dialog.ShowError(err, mainWindow)
dialog.ShowError(err, *mainWindow)
return
}
@ -190,31 +216,31 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
cmd := exec.Command("sh", "-c", installCmd)
cmd.Stdin = strings.NewReader(sudoPassword + "\n")
dialog.ShowInformation("Installation gestartet",
"Die Installation von VSCode wurde gestartet.", mainWindow)
dialog.ShowInformation("Installation started",
"Installation of VSCode started.", *mainWindow)
output, err := cmd.CombinedOutput()
if err != nil {
errMsg := fmt.Errorf("installation failed:\n%s", output)
dialog.ShowError(errMsg, mainWindow)
dialog.ShowError(errMsg, *mainWindow)
log.Error(errMsg.Error())
return
} else {
dialog.ShowInformation("Erfolg", "VSCode erfolgreich installiert!", mainWindow)
dialog.ShowInformation("Success", "VSCode succesfully installed!", *mainWindow)
CheckDependencies(dependencies)
}
}()
case 1: // Docker
go func() {
progressBar := widget.NewProgressBar()
progressDialog := dialog.NewCustomWithoutButtons("Docker Installation läuft...", progressBar, mainWindow)
progressDialog := dialog.NewCustomWithoutButtons("Docker installation in progress...", progressBar, *mainWindow)
progressDialog.Show()
osInfo, err := osinfo.GetLinuxDistribution()
if err != nil {
progressDialog.Hide()
errMsg := fmt.Errorf("error getting os infos: %v", err)
dialog.ShowError(errMsg, mainWindow)
dialog.ShowError(errMsg, *mainWindow)
log.Error(errMsg.Error())
return
}
@ -253,7 +279,6 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
totalSteps = len(commands) + len(cleanupCommands)
case "fedora":
// Fedora Commands
fedoraVer := "$(rpm -E %fedora)"
commands = []string{
"dnf install -y wget",
@ -272,7 +297,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
default:
progressDialog.Hide()
dialog.ShowInformation("not supported", "Automatic Docker installation not supported for your OS.", mainWindow)
dialog.ShowInformation("not supported", "Automatic Docker installation not supported for your OS.", *mainWindow)
return
}
@ -286,7 +311,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
if output, err := command.CombinedOutput(); err != nil {
progressDialog.Hide()
errMsg := fmt.Errorf("error at %s:\n%s", cmd, output)
dialog.ShowError(errMsg, mainWindow)
dialog.ShowError(errMsg, *mainWindow)
log.Error(errMsg.Error())
return
}
@ -302,7 +327,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
if output, err := command.CombinedOutput(); err != nil {
progressDialog.Hide()
errMsg := fmt.Errorf("cleanup error at %s:\n%s", cmd, output)
dialog.ShowError(errMsg, mainWindow)
dialog.ShowError(errMsg, *mainWindow)
log.Error(errMsg.Error())
return
}
@ -316,23 +341,36 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
dialog.ShowInformation(
"Installation finished",
"Docker was succesfully installed! Please re-start your system to let the changes take effect.",
mainWindow,
*mainWindow,
)
CheckDependencies(dependencies)
}()
}
}
return nil
}
func showInstallProgressBar(window fyne.Window, message string, cmd *exec.Cmd, depName string, dependencies []Dependency) {
progress := widget.NewProgressBarInfinite()
content := container.NewVBox(
widget.NewLabel(message),
progress,
)
popup := widget.NewModalPopUp(content, window.Canvas())
popup.Show()
go func() {
err := cmd.Run()
popup.Hide()
if cmd != nil {
err = cmd.Start()
if err != nil {
errMsg := fmt.Errorf("error starting installation process: %v", err)
dialog.ShowError(errMsg, mainWindow)
errMsg := fmt.Errorf("error during installation of %s: %v", depName, err)
dialog.ShowError(errMsg, window)
log.Error(errMsg.Error())
} else {
dialog.ShowInformation("Installation started",
fmt.Sprintf("Installation of %s was started", depName), mainWindow)
}
dialog.ShowInformation("Installation finished", fmt.Sprintf("%s successfully installed!", depName), window)
CheckDependencies(dependencies)
}
}()
}

View file

@ -64,7 +64,7 @@ func ShowDependencyScreen() {
ShowProjectScreen()
} else {
dialog.ShowInformation("dependencies missing",
"Bitte installieren Sie alle erforderlichen Abhängigkeiten, bevor Sie fortfahren.", mainWindow)
"Please install all required dependencies before proceeding.", mainWindow)
}
})