mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-09 13:40:42 +08:00
153 lines
3.8 KiB
Go
153 lines
3.8 KiB
Go
package doctor
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/go-git/go-git/v5"
|
|
"github.com/pterm/pterm"
|
|
"github.com/samber/lo"
|
|
"github.com/wailsapp/wails/v3/internal/operatingsystem"
|
|
"github.com/wailsapp/wails/v3/internal/version"
|
|
"path/filepath"
|
|
"runtime"
|
|
"runtime/debug"
|
|
"slices"
|
|
)
|
|
|
|
func Run() (err error) {
|
|
|
|
pterm.DefaultSection = *pterm.DefaultSection.
|
|
WithBottomPadding(0).
|
|
WithStyle(pterm.NewStyle(pterm.FgBlue, pterm.Bold))
|
|
|
|
pterm.Println() // Spacer
|
|
pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println("Wails Doctor")
|
|
pterm.Println() // Spacer
|
|
|
|
spinner, _ := pterm.DefaultSpinner.WithRemoveWhenDone().Start("Scanning system - Please wait (this may take a long time)...")
|
|
|
|
defer func() {
|
|
if err != nil {
|
|
spinner.Fail()
|
|
}
|
|
}()
|
|
|
|
/** Build **/
|
|
|
|
// BuildSettings contains the build settings for the application
|
|
var BuildSettings map[string]string
|
|
|
|
// BuildInfo contains the build info for the application
|
|
var BuildInfo *debug.BuildInfo
|
|
|
|
var ok bool
|
|
BuildInfo, ok = debug.ReadBuildInfo()
|
|
if !ok {
|
|
return fmt.Errorf("could not read build info from binary")
|
|
}
|
|
BuildSettings = lo.Associate(BuildInfo.Settings, func(setting debug.BuildSetting) (string, string) {
|
|
return setting.Key, setting.Value
|
|
})
|
|
|
|
/** Operating System **/
|
|
|
|
// Get system info
|
|
info, err := operatingsystem.Info()
|
|
if err != nil {
|
|
pterm.Error.Println("Failed to get system information")
|
|
return err
|
|
}
|
|
|
|
/** Wails **/
|
|
wailsPackage, _ := lo.Find(BuildInfo.Deps, func(dep *debug.Module) bool {
|
|
return dep.Path == "github.com/wailsapp/wails/v3"
|
|
})
|
|
|
|
wailsVersion := version.VersionString
|
|
if wailsPackage != nil && wailsPackage.Replace != nil {
|
|
wailsVersion = "(local) => " + filepath.ToSlash(wailsPackage.Replace.Path)
|
|
// Get the latest commit hash
|
|
repo, err := git.PlainOpen(filepath.Join(wailsPackage.Replace.Path, ".."))
|
|
if err == nil {
|
|
head, err := repo.Head()
|
|
if err == nil {
|
|
wailsVersion += " (" + head.Hash().String()[:8] + ")"
|
|
}
|
|
}
|
|
}
|
|
|
|
platformExtras, ok := getInfo()
|
|
|
|
spinner.Success()
|
|
|
|
/** Output **/
|
|
|
|
pterm.DefaultSection.Println("Build Environment")
|
|
|
|
tableData := pterm.TableData{
|
|
{"Wails CLI", wailsVersion},
|
|
{"Go Version", runtime.Version()},
|
|
}
|
|
|
|
if buildInfo, _ := debug.ReadBuildInfo(); buildInfo != nil {
|
|
buildSettingToName := map[string]string{
|
|
"vcs.revision": "Revision",
|
|
"vcs.modified": "Modified",
|
|
}
|
|
for _, buildSetting := range buildInfo.Settings {
|
|
name := buildSettingToName[buildSetting.Key]
|
|
if name == "" {
|
|
continue
|
|
}
|
|
tableData = append(tableData, []string{name, buildSetting.Value})
|
|
}
|
|
}
|
|
|
|
mapKeys := lo.Keys(BuildSettings)
|
|
slices.Sort(mapKeys)
|
|
for _, key := range mapKeys {
|
|
tableData = append(tableData, []string{key, BuildSettings[key]})
|
|
}
|
|
|
|
//// Exit early if PM not found
|
|
//if info.PM != nil {
|
|
// wailsTableData = append(wailsTableData, []string{"Package Manager", info.PM.Name()})
|
|
//}
|
|
|
|
err = pterm.DefaultTable.WithData(tableData).Render()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pterm.DefaultSection.Println("System")
|
|
|
|
systemTabledata := pterm.TableData{
|
|
{pterm.Sprint("Name"), info.Name},
|
|
{pterm.Sprint("Version"), info.Version},
|
|
{pterm.Sprint("ID"), info.ID},
|
|
{pterm.Sprint("Branding"), info.Branding},
|
|
|
|
{pterm.Sprint("Platform"), runtime.GOOS},
|
|
{pterm.Sprint("Architecture"), runtime.GOARCH},
|
|
}
|
|
|
|
mapKeys = lo.Keys(platformExtras)
|
|
slices.Sort(mapKeys)
|
|
for _, key := range mapKeys {
|
|
systemTabledata = append(systemTabledata, []string{key, platformExtras[key]})
|
|
}
|
|
|
|
err = pterm.DefaultTable.WithData(systemTabledata).Render()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pterm.DefaultSection.Println("Diagnosis")
|
|
if !ok {
|
|
pterm.Warning.Println("There are some items above that need addressing!")
|
|
} else {
|
|
pterm.Success.Println("Your system is ready for Wails development!")
|
|
}
|
|
|
|
return nil
|
|
}
|