webview2runtime

package module
Version: v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 10 Imported by: 0

README

WebView2Runtime

This package provides the following capabilities for managing and installing the WebView2 runtime:

  • Retrieve version of installed WebView2 runtime
  • Determine if the installed version is older than the required version
  • Download and run the official Microsoft Bootstrapper
  • Run an embedded version of the official Microsoft Bootstrapper
  • Open a browser to the WebView2 download page
  • Utility methods for user notifications and confirmations

Usage

The general workflow should be:

  • Check if there's a version installed using GetInstalledVersion()
  • If so, check it's new enough to support your application using IsOlderThan()
  • Decide what strategy you're comfortable with to inform the user / install the runtime.

Documentation

Please consult the package documentation.

Example
package mypackage

import "github.com/leaanthony/webview2runtime"

func BootstrapRuntime() error {
    var err error
    shouldInstall := true
    message := "The WebView2 runtime is required. Press Ok to install."
    installedVersion := webview2runtime.GetInstalledVersion()
    if installedVersion != nil {
        shouldInstall, err = installedVersion.IsOlderThan("90.0.818.66")
        if err != nil {
            _ = webview2runtime.Error(err.Error(), "Error")
            return err
        }
        if shouldInstall {
            message = "The WebView2 runtime needs updating. Press Ok to install."
        }
    }
    if shouldInstall {
        confirmed, err := webview2runtime.Confirm(message, "Missing Requirements")
        if err != nil {
            return err
        }
        if confirmed {
            installedCorrectly, err := webview2runtime.InstallUsingBootstrapper()
            if err != nil {
                _ = webview2runtime.Error(err.Error(), "Error")
                return err
            }
            if !installedCorrectly {
                err = webview2runtime.Error("The runtime failed to install correctly. Please try again.", "Error")
                return err
            }
        }
    }
    return nil
}

Documentation

Rendered for windows/amd64

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(caption string, title string) (bool, error)

Confirm will prompt the user with a message and OK / CANCEL buttons. Returns true if OK is selected by the user. Returns an error if something went wrong.

func Error

func Error(caption string, title string) error

Error will an error message to the user. Returns an error if something went wrong.

func InstallUsingBootstrapper

func InstallUsingBootstrapper() (bool, error)

InstallUsingBootstrapper will extract the embedded bootstrapper from Microsoft and run it to install the latest version of the runtime. Returns true if the installer ran successfully. Returns an error if something goes wrong

func InstallUsingEmbeddedBootstrapper

func InstallUsingEmbeddedBootstrapper() (bool, error)

InstallUsingEmbeddedBootstrapper will download the bootstrapper from Microsoft and run it to install the latest version of the runtime. Returns true if the installer ran successfully. Returns an error if something goes wrong

func MessageBox

func MessageBox(caption string, title string, flags uint) (int, error)

MessageBox prompts the user with the given caption and title. Flags may be provided to customise the dialog. Returns an error if something went wrong.

func OpenInstallerDownloadWebpage

func OpenInstallerDownloadWebpage() error

OpenInstallerDownloadWebpage will open the browser on the WebView2 download page

Types

type Info

type Info struct {
	Location        string
	Name            string
	Version         string
	SilentUninstall string
}

Info contains all the information about an installation of the webview2 runtime.

func GetInstalledVersion

func GetInstalledVersion() *Info

GetInstalledVersion returns the installed version of the webview2 runtime. If there is no version installed, a blank string is returned.

func (*Info) IsOlderThan

func (i *Info) IsOlderThan(requiredVersion string) (bool, error)

IsOlderThan returns true if the installed version is older than the given required version. Returns error if something goes wrong.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL