From 1cd38d12f9ae35f3b67a4bdf63a5680477d6416e Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 3 Sep 2021 05:55:51 +1000 Subject: [PATCH] Add webview2 to wails doctor, refactored IsAppleSilicon --- v2/cmd/wails/internal/commands/build/build.go | 2 +- v2/internal/system/system.go | 4 +++ v2/internal/system/system_darwin.go | 27 +++++++++---------- v2/internal/system/system_linux.go | 8 +----- v2/internal/system/system_windows.go | 25 +++++++++++++---- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/v2/cmd/wails/internal/commands/build/build.go b/v2/cmd/wails/internal/commands/build/build.go index 2e5c89aa3..69c3678c2 100644 --- a/v2/cmd/wails/internal/commands/build/build.go +++ b/v2/cmd/wails/internal/commands/build/build.go @@ -162,7 +162,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { // Calculate platform and arch platformSplit := strings.Split(platform, "/") buildOptions.Platform = platformSplit[0] - if system.IsAppleSilicon() { + if system.IsAppleSilicon { buildOptions.Arch = "arm64" } else { buildOptions.Arch = runtime.GOARCH diff --git a/v2/internal/system/system.go b/v2/internal/system/system.go index b7061ea64..9d7650622 100644 --- a/v2/internal/system/system.go +++ b/v2/internal/system/system.go @@ -7,6 +7,10 @@ import ( "strings" ) +var ( + IsAppleSilicon bool +) + // Info holds information about the current operating system, // package manager and required dependancies type Info struct { diff --git a/v2/internal/system/system_darwin.go b/v2/internal/system/system_darwin.go index 63cf4138f..d7dfa7f7c 100644 --- a/v2/internal/system/system_darwin.go +++ b/v2/internal/system/system_darwin.go @@ -1,17 +1,27 @@ +//go:build darwin // +build darwin package system import ( + "github.com/wailsapp/wails/v2/internal/system/packagemanager" "os/exec" "strings" - "syscall" - - "github.com/wailsapp/wails/v2/internal/system/packagemanager" "github.com/wailsapp/wails/v2/internal/system/operatingsystem" ) +// Determine if the app is running on Apple Silicon +// Credit: https://www.yellowduck.be/posts/detecting-apple-silicon-via-go/ +func init() { + r, err := syscall.Sysctl("sysctl.proc_translated") + if err != nil { + return false + } + + IsAppleSilicon = r == "\x00\x00\x00" || r == "\x01\x00\x00" +} + func (i *Info) discover() error { var err error osinfo, err := operatingsystem.Info() @@ -45,14 +55,3 @@ func (i *Info) discover() error { i.Dependencies = append(i.Dependencies, checkUPX()) return nil } - -// IsAppleSilicon returns true if the app is running on Apple Silicon -// Credit: https://www.yellowduck.be/posts/detecting-apple-silicon-via-go/ -func IsAppleSilicon() bool { - r, err := syscall.Sysctl("sysctl.proc_translated") - if err != nil { - return false - } - - return r == "\x00\x00\x00" || r == "\x01\x00\x00" -} diff --git a/v2/internal/system/system_linux.go b/v2/internal/system/system_linux.go index de62b4726..5a08d96b7 100644 --- a/v2/internal/system/system_linux.go +++ b/v2/internal/system/system_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package system @@ -27,10 +28,3 @@ func (i *Info) discover() error { return nil } - -// IsAppleSilicon returns true if the app is running on Apple Silicon -// Credit: https://www.yellowduck.be/posts/detecting-apple-silicon-via-go/ -// NOTE: Not applicable to linux -func IsAppleSilicon() bool { - return false -} diff --git a/v2/internal/system/system_windows.go b/v2/internal/system/system_windows.go index 23071fbe5..b737bf382 100644 --- a/v2/internal/system/system_windows.go +++ b/v2/internal/system/system_windows.go @@ -1,9 +1,12 @@ +//go:build windows // +build windows package system import ( + "github.com/leaanthony/webview2runtime" "github.com/wailsapp/wails/v2/internal/system/operatingsystem" + "github.com/wailsapp/wails/v2/internal/system/packagemanager" ) func (i *Info) discover() error { @@ -15,6 +18,7 @@ func (i *Info) discover() error { } i.OS = osinfo + i.Dependencies = append(i.Dependencies, checkWebView2()) i.Dependencies = append(i.Dependencies, checkNPM()) i.Dependencies = append(i.Dependencies, checkUPX()) i.Dependencies = append(i.Dependencies, checkDocker()) @@ -22,9 +26,20 @@ func (i *Info) discover() error { return nil } -// IsAppleSilicon returns true if the app is running on Apple Silicon -// Credit: https://www.yellowduck.be/posts/detecting-apple-silicon-via-go/ -// NOTE: Not applicable to windows -func IsAppleSilicon() bool { - return false +func checkWebView2() *packagemanager.Dependancy { + + info := webview2runtime.GetInstalledVersion() + version := info.Version + installed := version != "" + + return &packagemanager.Dependancy{ + Name: "WebView2 ", + PackageName: "N/A", + Installed: installed, + InstallCommand: "Available at https://developer.microsoft.com/en-us/microsoft-edge/webview2/", + Version: version, + Optional: false, + External: true, + } + }