feat: improve docker installation process by adding wsl feature activation

This commit is contained in:
Patryk Hegenberg 2025-03-20 20:59:36 +01:00
parent f1f2a8d2c5
commit 9d581e18a2

View file

@ -126,11 +126,26 @@ func installWindowsDependencies(index int, cmd *exec.Cmd, mainWindow *fyne.Windo
cmd = tools.CommandInShell("winget", "install", "-e", "--id",
"Microsoft.VisualStudioCode")
case 1: // Docker Desktop
wslEnabled, err := checkWslFeaturesEnabled()
if err != nil {
return nil, fmt.Errorf("error checking WSL features: %v", err)
}
if !wslEnabled {
dialog.ShowInformation("activate wsl", "WSL has to be activated. Please confirm to active necessary features.", *mainWindow)
err = enableWslFeatures()
if err != nil {
return nil, fmt.Errorf("error enabling WSL features: %v", err)
}
dialog.ShowInformation("reboot required", "Please reboot your PC to finish wsl activation and reopen 'jws'.", *mainWindow)
return nil, fmt.Errorf("reboot required")
}
wslCheckCmd := tools.CommandInShell("wsl", "--status")
err := wslCheckCmd.Run()
err = wslCheckCmd.Run()
if err != nil {
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)
dialog.ShowInformation("installing wsl", "WSL will be installed. Please wait untill installation is finished and reopen 'jws'.", *mainWindow)
err = wslInstallCmd.Run()
if err != nil {
errMsg := fmt.Errorf("error: installing WSL: %v", err)
@ -145,6 +160,31 @@ func installWindowsDependencies(index int, cmd *exec.Cmd, mainWindow *fyne.Windo
return cmd, nil
}
func checkWslFeaturesEnabled() (bool, error) {
cmd := tools.CommandInShell("powershell", "-Command",
"[bool](Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform).State -and [bool](Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State")
output, err := cmd.CombinedOutput()
if err != nil {
return false, fmt.Errorf("error executing PowerShell command: %v\nOutput: %s", err, string(output))
}
enabled := strings.TrimSpace(string(output)) == "True"
return enabled, nil
}
func enableWslFeatures() error {
cmd := tools.CommandInShell("powershell", "-Command",
"Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart; Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart")
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error executing PowerShell command: %v\nOutput: %s", err, string(output))
}
return nil
}
func installDarwinDependencies(index int, cmd *exec.Cmd, mainWindow *fyne.Window) (*exec.Cmd, error) {
brewCheckCmd := tools.CommandInShell("which", "brew")
err := brewCheckCmd.Run()