5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-12 15:09:33 +08:00
wails/v2/internal/wv2installer/wv2installer.go
Nan0 2065600096
Feature: set browser path (#1448)
* Added option to specify webview2 path

* Added `manual` webview strategy

* Update documentation

* Fixed build with manual tag

* Check for browser directory existence

* Added version check for manually specified webview, removed fallback for installed webview in manual strategy

* Update WebviewBrowserPath documentation

* Replaced deprecated StringToUTF16Ptr

* Return on error

* Removed manual strategy, return error in wv2installer for fixed runtime

* Removed manual strategy from CLI
2022-06-25 07:49:00 +10:00

60 lines
1.5 KiB
Go

//go:build windows
package wv2installer
import (
"fmt"
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/go-webview2/webviewloader"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
const MinimumRuntimeVersion string = "94.0.992.31" // Webview2 SDK 1.0.992.28
type installationStatus int
const (
needsInstalling installationStatus = iota
needsUpdating
)
func Process(appoptions *options.App) (string, error) {
messages := windows.DefaultMessages()
if appoptions.Windows != nil && appoptions.Windows.Messages != nil {
messages = appoptions.Windows.Messages
}
installStatus := needsInstalling
// Override version check for manually specified webview path if present
var webviewPath = ""
if opts := appoptions.Windows; opts != nil && opts.WebviewBrowserPath != "" {
webviewPath = opts.WebviewBrowserPath
}
installedVersion, err := webviewloader.GetWebviewVersion(webviewPath)
if err != nil {
return "", err
}
if installedVersion != "" {
installStatus = needsUpdating
compareResult, err := webviewloader.CompareBrowserVersions(installedVersion, MinimumRuntimeVersion)
if err != nil {
return "", err
}
updateRequired := compareResult < 0
// Installed and does not require updating
if !updateRequired {
return installedVersion, nil
}
}
// Force error strategy if webview is manually specified
if webviewPath != "" {
return installedVersion, fmt.Errorf(messages.InvalidFixedWebview2)
}
return installedVersion, doInstallationStrategy(installStatus, messages)
}