5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 21:10:54 +08:00

Add webview2 to wails doctor, refactored IsAppleSilicon

This commit is contained in:
Lea Anthony 2021-09-03 05:55:51 +10:00
parent 0b71d64931
commit 1cd38d12f9
5 changed files with 39 additions and 27 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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"
}

View File

@ -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
}

View File

@ -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,
}
}