Squashed 'v2/' content from commit 72ef153

git-subtree-dir: v2
git-subtree-split: 72ef15359e36e42b18d9407f74c762f83eb9a099
This commit is contained in:
Travis McLane
2020-09-15 19:52:54 -05:00
commit a213e8bcd1
222 changed files with 25426 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
package apps
func Find() []Apps {
}

View File

@@ -0,0 +1,13 @@
package operatingsystem
// OS contains information about the operating system
type OS struct {
ID string
Name string
Version string
}
// Info retrieves information about the current platform
func Info() (*OS, error) {
return platformInfo()
}

View File

@@ -0,0 +1,51 @@
// +build linux
package operatingsystem
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
// platformInfo is the platform specific method to get system information
func platformInfo() (*OS, error) {
_, err := os.Stat("/etc/os-release")
if os.IsNotExist(err) {
return nil, fmt.Errorf("unable to read system information")
}
osRelease, _ := ioutil.ReadFile("/etc/os-release")
return parseOsRelease(string(osRelease)), nil
}
func parseOsRelease(osRelease string) *OS {
// Default value
var result OS
result.ID = "Unknown"
result.Name = "Unknown"
result.Version = "Unknown"
// Split into lines
lines := strings.Split(osRelease, "\n")
// Iterate lines
for _, line := range lines {
// Split each line by the equals char
splitLine := strings.SplitN(line, "=", 2)
// Check we have
if len(splitLine) != 2 {
continue
}
switch splitLine[0] {
case "ID":
result.ID = strings.ToLower(strings.Trim(splitLine[1], "\""))
case "NAME":
result.Name = strings.Trim(splitLine[1], "\"")
case "VERSION_ID":
result.Version = strings.Trim(splitLine[1], "\"")
}
}
return &result
}

View File

@@ -0,0 +1,97 @@
// +build linux
package packagemanager
import (
"regexp"
"strings"
"github.com/wailsapp/wails/v2/internal/shell"
)
// Apt represents the Apt manager
type Apt struct {
name string
osid string
}
// NewApt creates a new Apt instance
func NewApt(osid string) *Apt {
return &Apt{
name: "apt",
osid: osid,
}
}
// Packages returns the libraries that we need for Wails to compile
// They will potentially differ on different distributions or versions
func (a *Apt) Packages() packagemap {
return packagemap{
"libgtk-3": []*Package{
{Name: "libgtk-3-dev", SystemPackage: true, Library: true},
},
"libwebkit": []*Package{
{Name: "libwebkit2gtk-4.0-dev", SystemPackage: true, Library: true},
},
"gcc": []*Package{
{Name: "build-essential", SystemPackage: true},
},
"pkg-config": []*Package{
{Name: "pkg-config", SystemPackage: true},
},
"npm": []*Package{
{Name: "npm", SystemPackage: true},
},
"docker": []*Package{
{Name: "docker.io", SystemPackage: true, Optional: true},
},
}
}
// Name returns the name of the package manager
func (a *Apt) Name() string {
return a.name
}
// PackageInstalled tests if the given package name is installed
func (a *Apt) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "apt", "-qq", "list", pkg.Name)
return strings.Contains(stdout, "[installed]"), err
}
// PackageAvailable tests if the given package is available for installation
func (a *Apt) PackageAvailable(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "apt", "-qq", "list", pkg.Name)
// We add a space to ensure we get a full match, not partial match
output := a.removeEscapeSequences(stdout)
installed := strings.HasPrefix(output, pkg.Name)
a.getPackageVersion(pkg, output)
return installed, err
}
// InstallCommand returns the package manager specific command to install a package
func (a *Apt) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[a.osid]
}
return "sudo apt install " + pkg.Name
}
func (a *Apt) removeEscapeSequences(in string) string {
escapechars, _ := regexp.Compile(`\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])`)
return escapechars.ReplaceAllString(in, "")
}
func (a *Apt) getPackageVersion(pkg *Package, output string) {
splitOutput := strings.Split(output, " ")
if len(splitOutput) > 1 {
pkg.Version = splitOutput[1]
}
}

View File

@@ -0,0 +1,117 @@
// +build linux
package packagemanager
import (
"os/exec"
"regexp"
"strings"
"github.com/wailsapp/wails/v2/internal/shell"
)
// Emerge represents the Emerge package manager
type Emerge struct {
name string
osid string
}
// NewEmerge creates a new Emerge instance
func NewEmerge(osid string) *Emerge {
return &Emerge{
name: "emerge",
osid: osid,
}
}
// Packages returns the libraries that we need for Wails to compile
// They will potentially differ on different distributions or versions
func (e *Emerge) Packages() packagemap {
return packagemap{
"libgtk-3": []*Package{
{Name: "x11-libs/gtk+", SystemPackage: true, Library: true},
},
"libwebkit": []*Package{
{Name: "net-libs/webkit-gtk", SystemPackage: true, Library: true},
},
"gcc": []*Package{
{Name: "sys-devel/gcc", SystemPackage: true},
},
"pkg-config": []*Package{
{Name: "dev-util/pkgconf", SystemPackage: true},
},
"npm": []*Package{
{Name: "net-libs/nodejs", SystemPackage: true},
},
"docker": []*Package{
{Name: "app-emulation/docker", SystemPackage: true, Optional: true},
},
}
}
// Name returns the name of the package manager
func (e *Emerge) Name() string {
return e.name
}
// PackageInstalled tests if the given package name is installed
func (e *Emerge) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "emerge", "-s", pkg.Name+"$")
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
regex := `.*\*\s+` + regexp.QuoteMeta(pkg.Name) + `\n(?:\S|\s)+?Latest version installed: (.*)`
installedRegex := regexp.MustCompile(regex)
matches := installedRegex.FindStringSubmatch(stdout)
pkg.Version = ""
noOfMatches := len(matches)
installed := false
if noOfMatches > 1 && matches[1] != "[ Not Installed ]" {
installed = true
pkg.Version = strings.TrimSpace(matches[1])
}
return installed, err
}
// PackageAvailable tests if the given package is available for installation
func (e *Emerge) PackageAvailable(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "emerge", "-s", pkg.Name+"$")
// We add a space to ensure we get a full match, not partial match
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
installedRegex := regexp.MustCompile(`.*\*\s+` + regexp.QuoteMeta(pkg.Name) + `\n(?:\S|\s)+?Latest version available: (.*)`)
matches := installedRegex.FindStringSubmatch(stdout)
pkg.Version = ""
noOfMatches := len(matches)
available := false
if noOfMatches > 1 {
available = true
pkg.Version = strings.TrimSpace(matches[1])
}
return available, nil
}
// InstallCommand returns the package manager specific command to install a package
func (e *Emerge) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[e.osid]
}
return "sudo emerge " + pkg.Name
}

View File

@@ -0,0 +1,114 @@
// +build linux
package packagemanager
import (
"regexp"
"strings"
"github.com/wailsapp/wails/v2/internal/shell"
)
// Eopkg represents the Eopkg manager
type Eopkg struct {
name string
osid string
}
// NewEopkg creates a new Eopkg instance
func NewEopkg(osid string) *Eopkg {
result := &Eopkg{
name: "eopkg",
osid: osid,
}
result.intialiseName()
return result
}
// Packages returns the packages that we need for Wails to compile
// They will potentially differ on different distributions or versions
func (e *Eopkg) Packages() packagemap {
return packagemap{
"libgtk-3": []*Package{
{Name: "libgtk-3-devel", SystemPackage: true, Library: true},
},
"libwebkit": []*Package{
{Name: "libwebkit-gtk-devel", SystemPackage: true, Library: true},
},
"gcc": []*Package{
{Name: "gcc", SystemPackage: true},
},
"pkg-config": []*Package{
{Name: "pkg-config", SystemPackage: true},
},
"npm": []*Package{
{Name: "nodejs", SystemPackage: true},
},
"docker": []*Package{
{Name: "docker", SystemPackage: true, Optional: true},
},
}
}
// Name returns the name of the package manager
func (e *Eopkg) Name() string {
return e.name
}
// PackageInstalled tests if the given package is installed
func (e *Eopkg) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "eopkg", "info", pkg.Name)
return strings.HasPrefix(stdout, "Installed"), err
}
// PackageAvailable tests if the given package is available for installation
func (e *Eopkg) PackageAvailable(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "eopkg", "info", pkg.Name)
// We add a space to ensure we get a full match, not partial match
output := e.removeEscapeSequences(stdout)
installed := strings.Contains(output, "Package found in Solus repository")
e.getPackageVersion(pkg, output)
return installed, err
}
// InstallCommand returns the package manager specific command to install a package
func (e *Eopkg) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[e.osid]
}
return "sudo eopkg it " + pkg.Name
}
func (e *Eopkg) removeEscapeSequences(in string) string {
escapechars, _ := regexp.Compile(`\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])`)
return escapechars.ReplaceAllString(in, "")
}
func (e *Eopkg) intialiseName() {
result := "eopkg"
stdout, _, err := shell.RunCommand(".", "eopkg", "--version")
if err == nil {
result = strings.TrimSpace(stdout)
}
e.name = result
}
func (e *Eopkg) getPackageVersion(pkg *Package, output string) {
versionRegex := regexp.MustCompile(`.*Name.*version:\s+(.*)+, release: (.*)`)
matches := versionRegex.FindStringSubmatch(output)
pkg.Version = ""
noOfMatches := len(matches)
if noOfMatches > 1 {
pkg.Version = matches[1]
if noOfMatches > 2 {
pkg.Version += " (r" + matches[2] + ")"
}
}
}

View File

@@ -0,0 +1,231 @@
// +build linux
package packagemanager
import (
"sort"
"strings"
"github.com/wailsapp/wails/v2/internal/shell"
)
// PackageManager is a common interface across all package managers
type PackageManager interface {
Name() string
Packages() packagemap
PackageInstalled(*Package) (bool, error)
PackageAvailable(*Package) (bool, error)
InstallCommand(*Package) string
}
// Package contains information about a system package
type Package struct {
Name string
Version string
InstallCommand map[string]string
SystemPackage bool
Library bool
Optional bool
}
// A list of package manager commands
var pmcommands = []string{
"eopkg",
"apt",
"yum",
"pacman",
"emerge",
"zypper",
}
type packagemap = map[string][]*Package
// Find will attempt to find the system package manager
func Find(osid string) PackageManager {
// Loop over pmcommands
for _, pmname := range pmcommands {
if shell.CommandExists(pmname) {
return newPackageManager(pmname, osid)
}
}
return nil
}
func newPackageManager(pmname string, osid string) PackageManager {
switch pmname {
case "eopkg":
return NewEopkg(osid)
case "apt":
return NewApt(osid)
case "yum":
return NewYum(osid)
case "pacman":
return NewPacman(osid)
case "emerge":
return NewEmerge(osid)
case "zypper":
return NewZypper(osid)
}
return nil
}
// Dependancy represents a system package that we require
type Dependancy struct {
Name string
PackageName string
Installed bool
InstallCommand string
Version string
Optional bool
External bool
}
// DependencyList is a list of Dependency instances
type DependencyList []*Dependancy
// InstallAllRequiredCommand returns the command you need to use to install all required dependencies
func (d DependencyList) InstallAllRequiredCommand() string {
result := ""
for _, dependency := range d {
if dependency.PackageName != "" {
if !dependency.Installed && !dependency.Optional {
if result == "" {
result = dependency.InstallCommand
} else {
result += " " + dependency.PackageName
}
}
}
}
return result
}
// InstallAllOptionalCommand returns the command you need to use to install all optional dependencies
func (d DependencyList) InstallAllOptionalCommand() string {
result := ""
for _, dependency := range d {
if dependency.PackageName != "" {
if !dependency.Installed && dependency.Optional {
if result == "" {
result = dependency.InstallCommand
} else {
result += " " + dependency.PackageName
}
}
}
}
return result
}
// Dependancies scans the system for required dependancies
// Returns a list of dependancies search for, whether they were found
// and whether they were installed
func Dependancies(p PackageManager) (DependencyList, error) {
var dependencies DependencyList
for name, packages := range p.Packages() {
dependency := &Dependancy{Name: name}
for _, pkg := range packages {
dependency.Optional = pkg.Optional
dependency.External = !pkg.SystemPackage
dependency.InstallCommand = p.InstallCommand(pkg)
packageavailable, err := p.PackageAvailable(pkg)
if err != nil {
return nil, err
}
if packageavailable {
dependency.Version = pkg.Version
dependency.PackageName = pkg.Name
installed, err := p.PackageInstalled(pkg)
if err != nil {
return nil, err
}
if installed {
dependency.Installed = true
dependency.Version = pkg.Version
if !pkg.Library {
dependency.Version = AppVersion(name)
}
} else {
dependency.InstallCommand = p.InstallCommand(pkg)
}
break
}
}
dependencies = append(dependencies, dependency)
}
// Sort dependencies
sort.Slice(dependencies, func(i, j int) bool {
return dependencies[i].Name < dependencies[j].Name
})
return dependencies, nil
}
// AppVersion returns the version for application related to the given package
func AppVersion(name string) string {
if name == "gcc" {
return gccVersion()
}
if name == "pkg-config" {
return pkgConfigVersion()
}
if name == "npm" {
return npmVersion()
}
if name == "docker" {
return dockerVersion()
}
return ""
}
func gccVersion() string {
var version string
var err error
// Try "-dumpfullversion"
version, _, err = shell.RunCommand(".", "gcc", "-dumpfullversion")
if err != nil {
// Try -dumpversion
// We ignore the error as this function is not for testing whether the
// application exists, only that we can get the version number
dumpversion, _, err := shell.RunCommand(".", "gcc", "-dumpversion")
if err == nil {
version = dumpversion
}
}
return strings.TrimSpace(version)
}
func pkgConfigVersion() string {
version, _, _ := shell.RunCommand(".", "pkg-config", "--version")
return strings.TrimSpace(version)
}
func npmVersion() string {
version, _, _ := shell.RunCommand(".", "npm", "--version")
return strings.TrimSpace(version)
}
func dockerVersion() string {
version, _, _ := shell.RunCommand(".", "docker", "--version")
version = strings.TrimPrefix(version, "Docker version ")
version = strings.ReplaceAll(version, ", build ", " (")
version = strings.TrimSpace(version) + ")"
return version
}

View File

@@ -0,0 +1,114 @@
// +build linux
package packagemanager
import (
"os/exec"
"regexp"
"strings"
"github.com/wailsapp/wails/v2/internal/shell"
)
// Pacman represents the Pacman package manager
type Pacman struct {
name string
osid string
}
// NewPacman creates a new Pacman instance
func NewPacman(osid string) *Pacman {
return &Pacman{
name: "pacman",
osid: osid,
}
}
// Packages returns the libraries that we need for Wails to compile
// They will potentially differ on different distributions or versions
func (p *Pacman) Packages() packagemap {
return packagemap{
"libgtk-3": []*Package{
{Name: "gtk3", SystemPackage: true, Library: true},
},
"libwebkit": []*Package{
{Name: "webkit2gtk", SystemPackage: true, Library: true},
},
"gcc": []*Package{
{Name: "gcc", SystemPackage: true},
},
"pkg-config": []*Package{
{Name: "pkgconf", SystemPackage: true},
},
"npm": []*Package{
{Name: "npm", SystemPackage: true},
},
"docker": []*Package{
{Name: "docker", SystemPackage: true, Optional: true},
},
}
}
// Name returns the name of the package manager
func (p *Pacman) Name() string {
return p.name
}
// PackageInstalled tests if the given package name is installed
func (p *Pacman) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "pacman", "-Q", pkg.Name)
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
splitoutput := strings.Split(stdout, "\n")
for _, line := range splitoutput {
if strings.HasPrefix(line, pkg.Name) {
splitline := strings.Split(line, " ")
pkg.Version = strings.TrimSpace(splitline[1])
}
}
return true, err
}
// PackageAvailable tests if the given package is available for installation
func (p *Pacman) PackageAvailable(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
output, _, err := shell.RunCommand(".", "pacman", "-Si", pkg.Name)
// We add a space to ensure we get a full match, not partial match
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
reg := regexp.MustCompile(`.*Version.*?:\s+(.*)`)
matches := reg.FindStringSubmatch(output)
pkg.Version = ""
noOfMatches := len(matches)
if noOfMatches > 1 {
pkg.Version = strings.TrimSpace(matches[1])
}
return true, nil
}
// InstallCommand returns the package manager specific command to install a package
func (p *Pacman) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[p.osid]
}
return "sudo pacman -S " + pkg.Name
}

View File

@@ -0,0 +1,126 @@
// +build linux
package packagemanager
import (
"os/exec"
"strings"
"github.com/wailsapp/wails/v2/internal/shell"
)
// Yum represents the Yum manager
type Yum struct {
name string
osid string
}
// NewYum creates a new Yum instance
func NewYum(osid string) *Yum {
return &Yum{
name: "yum",
osid: osid,
}
}
// Packages returns the libraries that we need for Wails to compile
// They will potentially differ on different distributions or versions
func (y *Yum) Packages() packagemap {
return packagemap{
"libgtk-3": []*Package{
{Name: "gtk3-devel", SystemPackage: true, Library: true},
},
"libwebkit": []*Package{
{Name: "webkit2gtk3-devel", SystemPackage: true, Library: true},
// {Name: "webkitgtk3-devel", SystemPackage: true, Library: true},
},
"gcc": []*Package{
{Name: "gcc-c++", SystemPackage: true},
},
"pkg-config": []*Package{
{Name: "pkgconf-pkg-config", SystemPackage: true},
},
"npm": []*Package{
{Name: "npm", SystemPackage: true},
},
"docker": []*Package{
{
SystemPackage: false,
Optional: true,
InstallCommand: map[string]string{
"centos": "Follow the guide: https://docs.docker.com/engine/install/centos/",
"fedora": "Follow the guide: https://docs.docker.com/engine/install/fedora/",
},
},
},
}
}
// Name returns the name of the package manager
func (y *Yum) Name() string {
return y.name
}
// PackageInstalled tests if the given package name is installed
func (y *Yum) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "yum", "info", "installed", pkg.Name)
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
splitoutput := strings.Split(stdout, "\n")
for _, line := range splitoutput {
if strings.HasPrefix(line, "Version") {
splitline := strings.Split(line, ":")
pkg.Version = strings.TrimSpace(splitline[1])
}
}
return true, err
}
// PackageAvailable tests if the given package is available for installation
func (y *Yum) PackageAvailable(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "yum", "info", pkg.Name)
// We add a space to ensure we get a full match, not partial match
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
splitoutput := strings.Split(stdout, "\n")
for _, line := range splitoutput {
if strings.HasPrefix(line, "Version") {
splitline := strings.Split(line, ":")
pkg.Version = strings.TrimSpace(splitline[1])
}
}
return true, nil
}
// InstallCommand returns the package manager specific command to install a package
func (y *Yum) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[y.osid]
}
return "sudo yum install " + pkg.Name
}
func (y *Yum) getPackageVersion(pkg *Package, output string) {
splitOutput := strings.Split(output, " ")
if len(splitOutput) > 0 {
pkg.Version = splitOutput[1]
}
}

View File

@@ -0,0 +1,120 @@
// +build linux
package packagemanager
import (
"os/exec"
"regexp"
"strings"
"github.com/wailsapp/wails/v2/internal/shell"
)
// Zypper represents the Zypper package manager
type Zypper struct {
name string
osid string
}
// NewZypper creates a new Zypper instance
func NewZypper(osid string) *Zypper {
return &Zypper{
name: "zypper",
osid: osid,
}
}
// Packages returns the libraries that we need for Wails to compile
// They will potentially differ on different distributions or versions
func (z *Zypper) Packages() packagemap {
return packagemap{
"libgtk-3": []*Package{
{Name: "gtk3-devel", SystemPackage: true, Library: true},
},
"libwebkit": []*Package{
{Name: "webkit2gtk3-devel", SystemPackage: true, Library: true},
},
"gcc": []*Package{
{Name: "gcc-c++", SystemPackage: true},
},
"pkg-config": []*Package{
{Name: "pkg-config", SystemPackage: true},
},
"npm": []*Package{
{Name: "npm10", SystemPackage: true},
},
"docker": []*Package{
{Name: "docker", SystemPackage: true, Optional: true},
},
}
}
// Name returns the name of the package manager
func (z *Zypper) Name() string {
return z.name
}
// PackageInstalled tests if the given package name is installed
func (z *Zypper) PackageInstalled(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "zypper", "info", pkg.Name)
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
reg := regexp.MustCompile(`.*Installed\s*:\s*(Yes)\s*`)
matches := reg.FindStringSubmatch(stdout)
pkg.Version = ""
noOfMatches := len(matches)
if noOfMatches > 1 {
z.getPackageVersion(pkg, stdout)
}
return noOfMatches > 1, err
}
// PackageAvailable tests if the given package is available for installation
func (z *Zypper) PackageAvailable(pkg *Package) (bool, error) {
if pkg.SystemPackage == false {
return false, nil
}
stdout, _, err := shell.RunCommand(".", "zypper", "info", pkg.Name)
// We add a space to ensure we get a full match, not partial match
if err != nil {
_, ok := err.(*exec.ExitError)
if ok {
return false, nil
}
return false, err
}
available := strings.Contains(stdout, "Information for package")
if available {
z.getPackageVersion(pkg, stdout)
}
return available, nil
}
// InstallCommand returns the package manager specific command to install a package
func (z *Zypper) InstallCommand(pkg *Package) string {
if pkg.SystemPackage == false {
return pkg.InstallCommand[z.osid]
}
return "sudo zypper in " + pkg.Name
}
func (z *Zypper) getPackageVersion(pkg *Package, output string) {
reg := regexp.MustCompile(`.*Version.*:(.*)`)
matches := reg.FindStringSubmatch(output)
pkg.Version = ""
noOfMatches := len(matches)
if noOfMatches > 1 {
pkg.Version = strings.TrimSpace(matches[1])
}
}

26
internal/system/system.go Normal file
View File

@@ -0,0 +1,26 @@
package system
import (
"github.com/wailsapp/wails/v2/internal/system/operatingsystem"
"github.com/wailsapp/wails/v2/internal/system/packagemanager"
)
// Info holds information about the current operating system,
// package manager and required dependancies
type Info struct {
OS *operatingsystem.OS
PM packagemanager.PackageManager
Dependencies packagemanager.DependencyList
}
// GetInfo scans the system for operating system details,
// the system package manager and the status of required
// dependancies.
func GetInfo() (*Info, error) {
var result Info
err := result.discover()
if err != nil {
return nil, err
}
return &result, nil
}

View File

@@ -0,0 +1,29 @@
// +build linux
package system
import (
"github.com/wailsapp/wails/v2/internal/system/operatingsystem"
"github.com/wailsapp/wails/v2/internal/system/packagemanager"
)
func (i *Info) discover() error {
var err error
osinfo, err := operatingsystem.Info()
if err != nil {
return err
}
i.OS = osinfo
i.PM = packagemanager.Find(osinfo.ID)
if i.PM != nil {
dependencies, err := packagemanager.Dependancies(i.PM)
if err != nil {
return err
}
i.Dependencies = dependencies
}
return nil
}

View File

@@ -0,0 +1,15 @@
// +build windows
package system
import (
"fmt"
"syscall"
)
func (i *Info) discover() {
dll := syscall.MustLoadDLL("kernel32.dll")
p := dll.MustFindProc("GetVersion")
v, _, _ := p.Call()
fmt.Printf("Windows version %d.%d (Build %d)\n", byte(v), uint8(v>>8), uint16(v>>16))
}