feat: improve usability by including a progressbar while installing packages on windows and mac
This commit is contained in:
parent
26bdcd9a6a
commit
c903fa1803
2 changed files with 267 additions and 229 deletions
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"fyne.io/tools"
|
"fyne.io/tools"
|
||||||
|
|
@ -97,6 +98,29 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
|
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
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 {
|
switch index {
|
||||||
case 0: // VSCode
|
case 0: // VSCode
|
||||||
cmd = tools.CommandInShell("winget", "install", "-e", "--id",
|
cmd = tools.CommandInShell("winget", "install", "-e", "--id",
|
||||||
|
|
@ -105,22 +129,23 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
wslCheckCmd := tools.CommandInShell("wsl", "--status")
|
wslCheckCmd := tools.CommandInShell("wsl", "--status")
|
||||||
err := wslCheckCmd.Run()
|
err := wslCheckCmd.Run()
|
||||||
if err != nil {
|
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()
|
err = wslInstallCmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := fmt.Errorf("error: installing WSL: %v", err)
|
errMsg := fmt.Errorf("error: installing WSL: %v", err)
|
||||||
dialog.ShowError(errMsg, mainWindow)
|
return nil, errMsg
|
||||||
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)
|
return nil, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = tools.CommandInShell("winget", "install", "-e", "--id",
|
cmd = tools.CommandInShell("winget", "install", "-e", "--id",
|
||||||
"Docker.DockerDesktop")
|
"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")
|
brewCheckCmd := tools.CommandInShell("which", "brew")
|
||||||
err := brewCheckCmd.Run()
|
err := brewCheckCmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -128,8 +153,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
err := brewInstallCmd.Run()
|
err := brewInstallCmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := fmt.Errorf("error: installing homebrew falied: %v", err)
|
errMsg := fmt.Errorf("error: installing homebrew falied: %v", err)
|
||||||
dialog.ShowError(errMsg, mainWindow)
|
return nil, errMsg
|
||||||
log.Error(errMsg.Error())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch index {
|
switch index {
|
||||||
|
|
@ -138,12 +162,14 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
case 1: // Docker
|
case 1: // Docker
|
||||||
cmd = tools.CommandInShell("brew", "install", "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()
|
osInfo, err := osinfo.GetLinuxDistribution()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
errMsg := fmt.Errorf("error getting OS info: %v", err)
|
||||||
dialog.ShowError(fmt.Errorf("error getting OS info: %v", err), mainWindow)
|
return errMsg
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadURL, fileName string
|
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"
|
downloadURL = "https://code.visualstudio.com/sha/download?build=stable&os=linux-rpm-x64"
|
||||||
fileName = "vscode.rpm"
|
fileName = "vscode.rpm"
|
||||||
default:
|
default:
|
||||||
dialog.ShowInformation("Nicht unterstützt", fmt.Sprintf("Automatische Installation für dieses OS %v nicht verfügbar", osInfo), mainWindow)
|
dialog.ShowInformation("Nicht unterstützt", fmt.Sprintf("Automatische Installation für dieses OS %v nicht verfügbar", osInfo), *mainWindow)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
progressBar := widget.NewProgressBar()
|
progressBar := widget.NewProgressBar()
|
||||||
progressDialog := dialog.NewCustomWithoutButtons("Download in progress", progressBar, mainWindow)
|
progressDialog := dialog.NewCustomWithoutButtons("Download in progress", progressBar, *mainWindow)
|
||||||
|
|
||||||
progressDialog.Show()
|
progressDialog.Show()
|
||||||
|
|
||||||
|
|
@ -175,7 +201,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
dialog.ShowError(err, mainWindow)
|
dialog.ShowError(err, *mainWindow)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,31 +216,31 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
cmd := exec.Command("sh", "-c", installCmd)
|
cmd := exec.Command("sh", "-c", installCmd)
|
||||||
cmd.Stdin = strings.NewReader(sudoPassword + "\n")
|
cmd.Stdin = strings.NewReader(sudoPassword + "\n")
|
||||||
|
|
||||||
dialog.ShowInformation("Installation gestartet",
|
dialog.ShowInformation("Installation started",
|
||||||
"Die Installation von VSCode wurde gestartet.", mainWindow)
|
"Installation of VSCode started.", *mainWindow)
|
||||||
|
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := fmt.Errorf("installation failed:\n%s", output)
|
errMsg := fmt.Errorf("installation failed:\n%s", output)
|
||||||
dialog.ShowError(errMsg, mainWindow)
|
dialog.ShowError(errMsg, *mainWindow)
|
||||||
log.Error(errMsg.Error())
|
log.Error(errMsg.Error())
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
dialog.ShowInformation("Erfolg", "VSCode erfolgreich installiert!", mainWindow)
|
dialog.ShowInformation("Success", "VSCode succesfully installed!", *mainWindow)
|
||||||
CheckDependencies(dependencies)
|
CheckDependencies(dependencies)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
case 1: // Docker
|
case 1: // Docker
|
||||||
go func() {
|
go func() {
|
||||||
progressBar := widget.NewProgressBar()
|
progressBar := widget.NewProgressBar()
|
||||||
progressDialog := dialog.NewCustomWithoutButtons("Docker Installation läuft...", progressBar, mainWindow)
|
progressDialog := dialog.NewCustomWithoutButtons("Docker installation in progress...", progressBar, *mainWindow)
|
||||||
progressDialog.Show()
|
progressDialog.Show()
|
||||||
|
|
||||||
osInfo, err := osinfo.GetLinuxDistribution()
|
osInfo, err := osinfo.GetLinuxDistribution()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
progressDialog.Hide()
|
progressDialog.Hide()
|
||||||
errMsg := fmt.Errorf("error getting os infos: %v", err)
|
errMsg := fmt.Errorf("error getting os infos: %v", err)
|
||||||
dialog.ShowError(errMsg, mainWindow)
|
dialog.ShowError(errMsg, *mainWindow)
|
||||||
log.Error(errMsg.Error())
|
log.Error(errMsg.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -253,7 +279,6 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
totalSteps = len(commands) + len(cleanupCommands)
|
totalSteps = len(commands) + len(cleanupCommands)
|
||||||
|
|
||||||
case "fedora":
|
case "fedora":
|
||||||
// Fedora Commands
|
|
||||||
fedoraVer := "$(rpm -E %fedora)"
|
fedoraVer := "$(rpm -E %fedora)"
|
||||||
commands = []string{
|
commands = []string{
|
||||||
"dnf install -y wget",
|
"dnf install -y wget",
|
||||||
|
|
@ -272,7 +297,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
|
|
||||||
default:
|
default:
|
||||||
progressDialog.Hide()
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,7 +311,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
if output, err := command.CombinedOutput(); err != nil {
|
if output, err := command.CombinedOutput(); err != nil {
|
||||||
progressDialog.Hide()
|
progressDialog.Hide()
|
||||||
errMsg := fmt.Errorf("error at %s:\n%s", cmd, output)
|
errMsg := fmt.Errorf("error at %s:\n%s", cmd, output)
|
||||||
dialog.ShowError(errMsg, mainWindow)
|
dialog.ShowError(errMsg, *mainWindow)
|
||||||
log.Error(errMsg.Error())
|
log.Error(errMsg.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -302,7 +327,7 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
if output, err := command.CombinedOutput(); err != nil {
|
if output, err := command.CombinedOutput(); err != nil {
|
||||||
progressDialog.Hide()
|
progressDialog.Hide()
|
||||||
errMsg := fmt.Errorf("cleanup error at %s:\n%s", cmd, output)
|
errMsg := fmt.Errorf("cleanup error at %s:\n%s", cmd, output)
|
||||||
dialog.ShowError(errMsg, mainWindow)
|
dialog.ShowError(errMsg, *mainWindow)
|
||||||
log.Error(errMsg.Error())
|
log.Error(errMsg.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -316,23 +341,36 @@ func InstallDependency(index int, sudoPassword string, dependencies []Dependency
|
||||||
dialog.ShowInformation(
|
dialog.ShowInformation(
|
||||||
"Installation finished",
|
"Installation finished",
|
||||||
"Docker was succesfully installed! Please re-start your system to let the changes take effect.",
|
"Docker was succesfully installed! Please re-start your system to let the changes take effect.",
|
||||||
mainWindow,
|
*mainWindow,
|
||||||
)
|
)
|
||||||
|
|
||||||
CheckDependencies(dependencies)
|
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 {
|
if err != nil {
|
||||||
errMsg := fmt.Errorf("error starting installation process: %v", err)
|
errMsg := fmt.Errorf("error during installation of %s: %v", depName, err)
|
||||||
dialog.ShowError(errMsg, mainWindow)
|
dialog.ShowError(errMsg, window)
|
||||||
log.Error(errMsg.Error())
|
log.Error(errMsg.Error())
|
||||||
} else {
|
} else {
|
||||||
dialog.ShowInformation("Installation started",
|
dialog.ShowInformation("Installation finished", fmt.Sprintf("%s successfully installed!", depName), window)
|
||||||
fmt.Sprintf("Installation of %s was started", depName), mainWindow)
|
CheckDependencies(dependencies)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func ShowDependencyScreen() {
|
||||||
ShowProjectScreen()
|
ShowProjectScreen()
|
||||||
} else {
|
} else {
|
||||||
dialog.ShowInformation("dependencies missing",
|
dialog.ShowInformation("dependencies missing",
|
||||||
"Bitte installieren Sie alle erforderlichen Abhängigkeiten, bevor Sie fortfahren.", mainWindow)
|
"Please install all required dependencies before proceeding.", mainWindow)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue