mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 18:00:02 +08:00
Support platform list in templates
This commit is contained in:
parent
84f407278c
commit
e8a85d4cd6
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@ -163,6 +164,23 @@ type ProjectOptions struct {
|
||||
Architecture string
|
||||
LdFlags string
|
||||
GoPath string
|
||||
|
||||
// Supported platforms
|
||||
Platforms []string `json:"platforms,omitempty"`
|
||||
}
|
||||
|
||||
// PlatformSupported returns true if the template is supported
|
||||
// on the current platform
|
||||
func (po *ProjectOptions) PlatformSupported() bool {
|
||||
|
||||
// Default is all platforms supported
|
||||
if len(po.Platforms) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check that the platform is in the list
|
||||
platformsSupported := slicer.String(po.Platforms)
|
||||
return platformsSupported.Contains(runtime.GOOS)
|
||||
}
|
||||
|
||||
// Defaults sets the default project template
|
||||
@ -233,13 +251,16 @@ func (po *ProjectOptions) PromptForInputs() error {
|
||||
for _, k := range keys {
|
||||
templateDetail := templateDetails[k]
|
||||
templateList.Add(templateDetail)
|
||||
if !templateDetail.Metadata.PlatformSupported() {
|
||||
templateDetail.Metadata.Name = "* " + templateDetail.Metadata.Name
|
||||
}
|
||||
options.Add(fmt.Sprintf("%s - %s", templateDetail.Metadata.Name, templateDetail.Metadata.ShortDescription))
|
||||
}
|
||||
|
||||
templateIndex := 0
|
||||
|
||||
if len(options.AsSlice()) > 1 {
|
||||
templateIndex = PromptSelection("Please select a template", options.AsSlice(), 0)
|
||||
templateIndex = PromptSelection("Please select a template (* means unsupported on current platform)", options.AsSlice(), 0)
|
||||
}
|
||||
|
||||
if len(templateList.AsSlice()) == 0 {
|
||||
@ -250,6 +271,10 @@ func (po *ProjectOptions) PromptForInputs() error {
|
||||
po.selectedTemplate = templateList.AsSlice()[templateIndex].(*TemplateDetails)
|
||||
}
|
||||
|
||||
po.selectedTemplate.Metadata.Name = strings.TrimPrefix(po.selectedTemplate.Metadata.Name, "* ")
|
||||
if !po.selectedTemplate.Metadata.PlatformSupported() {
|
||||
println("WARNING: This template is unsupported on this platform!")
|
||||
}
|
||||
fmt.Println("Template: " + po.selectedTemplate.Metadata.Name)
|
||||
|
||||
// Setup NPM Project name
|
||||
@ -372,5 +397,9 @@ func processTemplateMetadata(templateMetadata *TemplateMetadata, po *ProjectOpti
|
||||
}
|
||||
po.FrontEnd.Serve = templateMetadata.Serve
|
||||
}
|
||||
|
||||
// Save platforms
|
||||
po.Platforms = templateMetadata.Platforms
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@ -29,6 +30,26 @@ type TemplateMetadata struct {
|
||||
Bridge string `json:"bridge"`
|
||||
WailsDir string `json:"wailsdir"`
|
||||
TemplateDependencies []*TemplateDependency `json:"dependencies,omitempty"`
|
||||
|
||||
// List of platforms that this template is supported on.
|
||||
// No value means all platforms. A platform name is the same string
|
||||
// as `runtime.GOOS` will return, eg: "darwin". NOTE: This is
|
||||
// case sensitive.
|
||||
Platforms []string `json:"platforms,omitempty"`
|
||||
}
|
||||
|
||||
// PlatformSupported returns true if this template supports the
|
||||
// currently running platform
|
||||
func (m *TemplateMetadata) PlatformSupported() bool {
|
||||
|
||||
// Default is all platforms supported
|
||||
if len(m.Platforms) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check that the platform is in the list
|
||||
platformsSupported := slicer.String(m.Platforms)
|
||||
return platformsSupported.Contains(runtime.GOOS)
|
||||
}
|
||||
|
||||
// TemplateDependency defines a binary dependency for the template
|
||||
@ -128,11 +149,11 @@ func (t *TemplateHelper) GetTemplateDetails() (map[string]*TemplateDetails, erro
|
||||
result[name] = &TemplateDetails{
|
||||
Path: dir,
|
||||
}
|
||||
_ = &TemplateMetadata{}
|
||||
metadata, err := t.LoadMetadata(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result[name].Metadata = metadata
|
||||
if metadata.Name != "" {
|
||||
result[name].Name = metadata.Name
|
||||
|
@ -78,6 +78,11 @@ func init() {
|
||||
return fmt.Errorf("Unable to find 'project.json'. Please check you are in a Wails project directory")
|
||||
}
|
||||
|
||||
// Check that this platform is supported
|
||||
if !projectOptions.PlatformSupported() {
|
||||
logger.Yellow("WARNING: This project is unsupported on %s - it probably won't work!\n Valid platforms: %s\n", runtime.GOOS, strings.Join(projectOptions.Platforms, ", "))
|
||||
}
|
||||
|
||||
// Set cross-compile
|
||||
projectOptions.Platform = runtime.GOOS
|
||||
if len(platform) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user