mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 14:29:50 +08:00
fix: config errors
This commit is contained in:
parent
8aa97f64ef
commit
a2af626477
6
app.go
6
app.go
@ -20,7 +20,7 @@ var BuildMode = cmd.BuildModeProd
|
|||||||
|
|
||||||
// App defines the main application struct
|
// App defines the main application struct
|
||||||
type App struct {
|
type App struct {
|
||||||
config *Config // The Application configuration object
|
config *AppConfig // The Application configuration object
|
||||||
cli *cmd.Cli // In debug mode, we have a cli
|
cli *cmd.Cli // In debug mode, we have a cli
|
||||||
renderer interfaces.Renderer // The renderer is what we will render the app to
|
renderer interfaces.Renderer // The renderer is what we will render the app to
|
||||||
logLevel string // The log level of the app
|
logLevel string // The log level of the app
|
||||||
@ -33,8 +33,8 @@ type App struct {
|
|||||||
|
|
||||||
// CreateApp creates the application window with the given configuration
|
// CreateApp creates the application window with the given configuration
|
||||||
// If none given, the defaults are used
|
// If none given, the defaults are used
|
||||||
func CreateApp(optionalConfig ...*Config) *App {
|
func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||||
var userConfig *Config
|
var userConfig *AppConfig
|
||||||
if len(optionalConfig) > 0 {
|
if len(optionalConfig) > 0 {
|
||||||
userConfig = optionalConfig[0]
|
userConfig = optionalConfig[0]
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
// Version - Wails version
|
// Version - Wails version
|
||||||
const Version = "v0.17.3-pre"
|
const Version = "v0.17.4-pre"
|
||||||
|
62
config.go
62
config.go
@ -1,14 +1,8 @@
|
|||||||
package wails
|
package wails
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/dchest/htmlmin"
|
// AppConfig is the configuration structure used when creating a Wails App object
|
||||||
// "github.com/leaanthony/mewn"
|
type AppConfig struct {
|
||||||
)
|
|
||||||
|
|
||||||
// Config is the configuration structure used when creating a Wails App object
|
|
||||||
type Config struct {
|
|
||||||
Width, Height int
|
Width, Height int
|
||||||
Title string
|
Title string
|
||||||
defaultHTML string
|
defaultHTML string
|
||||||
@ -18,87 +12,60 @@ type Config struct {
|
|||||||
Colour string
|
Colour string
|
||||||
Resizable bool
|
Resizable bool
|
||||||
DisableInspector bool
|
DisableInspector bool
|
||||||
// isHTMLFragment bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWidth returns the desired width
|
// GetWidth returns the desired width
|
||||||
func (a *Config) GetWidth() int {
|
func (a *AppConfig) GetWidth() int {
|
||||||
return a.Width
|
return a.Width
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHeight returns the desired height
|
// GetHeight returns the desired height
|
||||||
func (a *Config) GetHeight() int {
|
func (a *AppConfig) GetHeight() int {
|
||||||
return a.Height
|
return a.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTitle returns the desired window title
|
// GetTitle returns the desired window title
|
||||||
func (a *Config) GetTitle() string {
|
func (a *AppConfig) GetTitle() string {
|
||||||
return a.Title
|
return a.Title
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDefaultHTML returns the desired window title
|
// GetDefaultHTML returns the desired window title
|
||||||
func (a *Config) GetDefaultHTML() string {
|
func (a *AppConfig) GetDefaultHTML() string {
|
||||||
return a.defaultHTML
|
return a.defaultHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResizable returns true if the window should be resizable
|
// GetResizable returns true if the window should be resizable
|
||||||
func (a *Config) GetResizable() bool {
|
func (a *AppConfig) GetResizable() bool {
|
||||||
return a.Resizable
|
return a.Resizable
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDisableInspector returns true if the inspector should be disabled
|
// GetDisableInspector returns true if the inspector should be disabled
|
||||||
func (a *Config) GetDisableInspector() bool {
|
func (a *AppConfig) GetDisableInspector() bool {
|
||||||
return a.DisableInspector
|
return a.DisableInspector
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetColour returns the colour
|
// GetColour returns the colour
|
||||||
func (a *Config) GetColour() string {
|
func (a *AppConfig) GetColour() string {
|
||||||
return a.Colour
|
return a.Colour
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCSS returns the user CSS
|
// GetCSS returns the user CSS
|
||||||
func (a *Config) GetCSS() string {
|
func (a *AppConfig) GetCSS() string {
|
||||||
return a.CSS
|
return a.CSS
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJS returns the user Javascript
|
// GetJS returns the user Javascript
|
||||||
func (a *Config) GetJS() string {
|
func (a *AppConfig) GetJS() string {
|
||||||
return a.JS
|
return a.JS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Config) merge(in *Config) error {
|
func (a *AppConfig) merge(in *AppConfig) error {
|
||||||
if in.CSS != "" {
|
if in.CSS != "" {
|
||||||
a.CSS = in.CSS
|
a.CSS = in.CSS
|
||||||
}
|
}
|
||||||
if in.Title != "" {
|
if in.Title != "" {
|
||||||
a.Title = in.Title
|
a.Title = in.Title
|
||||||
}
|
}
|
||||||
// if in.HTML != "" {
|
|
||||||
// minified, err := htmlmin.Minify([]byte(in.HTML), &htmlmin.Options{
|
|
||||||
// MinifyScripts: true,
|
|
||||||
// })
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// inlineHTML := string(minified)
|
|
||||||
// inlineHTML = strings.Replace(inlineHTML, "'", "\\'", -1)
|
|
||||||
// inlineHTML = strings.Replace(inlineHTML, "\n", " ", -1)
|
|
||||||
// a.HTML = strings.TrimSpace(inlineHTML)
|
|
||||||
|
|
||||||
// // Deduce whether this is a full html page or a fragment
|
|
||||||
// // The document is determined to be a fragment if an HTML
|
|
||||||
// // tag exists and is located before the first div tag
|
|
||||||
// HTMLTagIndex := strings.Index(a.HTML, "<html")
|
|
||||||
// DivTagIndex := strings.Index(a.HTML, "<div")
|
|
||||||
|
|
||||||
// if HTMLTagIndex == -1 {
|
|
||||||
// a.isHTMLFragment = true
|
|
||||||
// } else {
|
|
||||||
// if DivTagIndex < HTMLTagIndex {
|
|
||||||
// a.isHTMLFragment = true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if in.Colour != "" {
|
if in.Colour != "" {
|
||||||
a.Colour = in.Colour
|
a.Colour = in.Colour
|
||||||
@ -121,14 +88,13 @@ func (a *Config) merge(in *Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates the default configuration
|
// Creates the default configuration
|
||||||
func newConfig(userConfig *Config) (*Config, error) {
|
func newConfig(userConfig *AppConfig) (*AppConfig, error) {
|
||||||
result := &Config{
|
result := &AppConfig{
|
||||||
Width: 800,
|
Width: 800,
|
||||||
Height: 600,
|
Height: 600,
|
||||||
Resizable: true,
|
Resizable: true,
|
||||||
Title: "My Wails App",
|
Title: "My Wails App",
|
||||||
Colour: "#FFF", // White by default
|
Colour: "#FFF", // White by default
|
||||||
// HTML: mewn.String("./runtime/assets/default.html"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if userConfig != nil {
|
if userConfig != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user