github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/wv2installer/wv2installer.go (about)

     1  //go:build windows
     2  
     3  package wv2installer
     4  
     5  import (
     6  	"fmt"
     7  
     8  	"github.com/AlpineAIO/wails/v2/pkg/options"
     9  	"github.com/AlpineAIO/wails/v2/pkg/options/windows"
    10  	"github.com/wailsapp/go-webview2/webviewloader"
    11  )
    12  
    13  const MinimumRuntimeVersion string = "94.0.992.31" // WebView2 SDK 1.0.992.28
    14  
    15  type installationStatus int
    16  
    17  const (
    18  	needsInstalling installationStatus = iota
    19  	needsUpdating
    20  )
    21  
    22  func Process(appoptions *options.App) (string, error) {
    23  	messages := windows.DefaultMessages()
    24  	if appoptions.Windows != nil && appoptions.Windows.Messages != nil {
    25  		messages = appoptions.Windows.Messages
    26  	}
    27  
    28  	installStatus := needsInstalling
    29  
    30  	// Override version check for manually specified webview path if present
    31  	var webviewPath = ""
    32  	if opts := appoptions.Windows; opts != nil && opts.WebviewBrowserPath != "" {
    33  		webviewPath = opts.WebviewBrowserPath
    34  	}
    35  
    36  	installedVersion, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(webviewPath)
    37  	if err != nil {
    38  		return "", err
    39  	}
    40  
    41  	if installedVersion != "" {
    42  		installStatus = needsUpdating
    43  		compareResult, err := webviewloader.CompareBrowserVersions(installedVersion, MinimumRuntimeVersion)
    44  		if err != nil {
    45  			return "", err
    46  		}
    47  		updateRequired := compareResult < 0
    48  		// Installed and does not require updating
    49  		if !updateRequired {
    50  			return installedVersion, nil
    51  		}
    52  	}
    53  
    54  	// Force error strategy if webview is manually specified
    55  	if webviewPath != "" {
    56  		return installedVersion, fmt.Errorf(messages.InvalidFixedWebview2)
    57  	}
    58  
    59  	return installedVersion, doInstallationStrategy(installStatus, messages)
    60  }