mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 00:22:57 +08:00
commit
fb081b4876
23
app.go
23
app.go
@ -7,8 +7,8 @@ import (
|
||||
|
||||
// -------------------------------- Compile time Flags ------------------------------
|
||||
|
||||
// ReleaseMode indicates if we are in Release Mode
|
||||
var ReleaseMode = false
|
||||
// DebugMode indicates if we are in debug Mode
|
||||
var DebugMode = "true"
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
@ -40,7 +40,7 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
}
|
||||
|
||||
result := &App{
|
||||
logLevel: "debug",
|
||||
logLevel: "info",
|
||||
renderer: &webViewRenderer{},
|
||||
ipc: newIPCManager(),
|
||||
bindingManager: newBindingManager(),
|
||||
@ -55,12 +55,10 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
result.config = appconfig
|
||||
|
||||
// Set up the CLI if not in release mode
|
||||
if !ReleaseMode {
|
||||
if DebugMode == "true" {
|
||||
result.cli = result.setupCli()
|
||||
}
|
||||
|
||||
// Disable Inspector in release mode
|
||||
if ReleaseMode {
|
||||
} else {
|
||||
// Disable Inspector in release mode
|
||||
result.config.DisableInspector = true
|
||||
}
|
||||
|
||||
@ -68,8 +66,13 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
}
|
||||
|
||||
// Run the app
|
||||
func (a *App) Run() {
|
||||
a.cli.Run()
|
||||
func (a *App) Run() error {
|
||||
if DebugMode == "true" {
|
||||
return a.cli.Run()
|
||||
} else {
|
||||
a.logLevel = "error"
|
||||
return a.start()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) start() error {
|
||||
|
15
app_cli.go
15
app_cli.go
@ -6,21 +6,15 @@ import (
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
|
||||
// setupCli creates a new cli handler for the application
|
||||
func (app *App) setupCli() *cmd.Cli {
|
||||
|
||||
// var apiFilename string
|
||||
|
||||
// Create a new cli
|
||||
result := cmd.NewCli(app.config.Title, "Debug build")
|
||||
|
||||
// Gen API
|
||||
// result.Command("genapi", "Generate JS stubs for the registered Go plugins").
|
||||
// StringFlag("o", "Output filename", &apiFilename).
|
||||
// Action(func() error {
|
||||
// app.renderer = N
|
||||
// })
|
||||
|
||||
// Setup cli to handle loglevel and headless flags
|
||||
result.
|
||||
StringFlag("loglevel", "Sets the log level [info|debug|error|panic|fatal]. Default debug", &app.logLevel).
|
||||
StringFlag("loglevel", "Sets the log level [debug|info|error|panic|fatal]. Default debug", &app.logLevel).
|
||||
BoolFlag("headless", "Runs the app in headless mode", &app.headless).
|
||||
Action(app.start)
|
||||
|
||||
@ -29,7 +23,6 @@ func (app *App) setupCli() *cmd.Cli {
|
||||
log := cmd.NewLogger()
|
||||
log.PrintBanner()
|
||||
fmt.Println()
|
||||
result.PrintHelp()
|
||||
log.YellowUnderline(app.config.Title + " - Debug Build")
|
||||
return nil
|
||||
})
|
||||
|
@ -85,7 +85,7 @@ func newAppConfig(userConfig *AppConfig) (*AppConfig, error) {
|
||||
Resizable: true,
|
||||
Title: "My Wails App",
|
||||
Colour: "#FFF", // White by default
|
||||
HTML: defaultAssets.String("default.html"),
|
||||
HTML: BoxString(&defaultAssets, "default.html"),
|
||||
}
|
||||
|
||||
if userConfig != nil {
|
||||
|
@ -105,6 +105,7 @@ func NewCommand(name string, description string, app *Cli, parentCommandPath str
|
||||
Shortdescription: description,
|
||||
SubCommandsMap: make(map[string]*Command),
|
||||
App: app,
|
||||
log: NewLogger(),
|
||||
}
|
||||
|
||||
// Set up command path
|
||||
@ -181,6 +182,7 @@ func (c *Command) Run(args []string) error {
|
||||
|
||||
// Nothing left we can do
|
||||
c.PrintHelp()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ func init() {
|
||||
assets := packr.NewBox("./bootstrap4default/assets")
|
||||
FrameworkToUse = &Framework{
|
||||
Name: "Bootstrap 4",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ func init() {
|
||||
assets := packr.NewBox("./assets")
|
||||
frameworks.FrameworkToUse = &frameworks.Framework{
|
||||
Name: "Bootstrap 4",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ func init() {
|
||||
assets := packr.NewBox("./bootstrap4lux/assets")
|
||||
FrameworkToUse = &Framework{
|
||||
Name: "Bootstrap 4 (Lux)",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ func init() {
|
||||
assets := packr.NewBox("./assets")
|
||||
frameworks.FrameworkToUse = &frameworks.Framework{
|
||||
Name: "Bootstrap 4 (Lux)",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
@ -103,6 +103,11 @@ func (p *ProgramHelper) InstallGoPackage(packageName string) error {
|
||||
// RunCommand runs the given command
|
||||
func (p *ProgramHelper) RunCommand(command string) error {
|
||||
args := strings.Split(command, " ")
|
||||
return p.RunCommandArray(args)
|
||||
}
|
||||
|
||||
// RunCommandArray runs the command specified in the array
|
||||
func (p *ProgramHelper) RunCommandArray(args []string) error {
|
||||
program := args[0]
|
||||
// TODO: Run FindProgram here and get the full path to the exe
|
||||
program, err := exec.LookPath(program)
|
||||
|
@ -220,6 +220,8 @@ func (sc *SystemConfig) load(filename string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckDependenciesSilent checks for dependencies but
|
||||
// only outputs if there's an error
|
||||
func CheckDependenciesSilent(logger *Logger) (bool, error) {
|
||||
logger.SetErrorOnly(true)
|
||||
result, err := CheckDependencies(logger)
|
||||
|
@ -13,8 +13,8 @@ func main() {
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Title: "{{.Name}}",
|
||||
JS: assets.String("app.js"),
|
||||
CSS: assets.String("app.css"),
|
||||
JS: BoxString(&assets, "app.js"),
|
||||
CSS: BoxString(&assets, "app.css"),
|
||||
})
|
||||
app.Bind(newQuotesCollection())
|
||||
app.Run()
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/leaanthony/slicer"
|
||||
"github.com/leaanthony/spinner"
|
||||
"github.com/wailsapp/wails/cmd"
|
||||
)
|
||||
@ -14,6 +14,7 @@ func init() {
|
||||
|
||||
var bundle = false
|
||||
var forceRebuild = false
|
||||
var releaseMode = false
|
||||
buildSpinner := spinner.NewSpinner()
|
||||
buildSpinner.SetSpinSpeed(50)
|
||||
|
||||
@ -21,7 +22,8 @@ func init() {
|
||||
initCmd := app.Command("build", "Builds your Wails project").
|
||||
LongDescription(commandDescription).
|
||||
BoolFlag("b", "Bundle application on successful build", &bundle).
|
||||
BoolFlag("f", "Force rebuild of application components", &forceRebuild)
|
||||
BoolFlag("f", "Force rebuild of application components", &forceRebuild).
|
||||
BoolFlag("r", "Build in Release mode", &releaseMode)
|
||||
|
||||
initCmd.Action(func() error {
|
||||
log := cmd.NewLogger()
|
||||
@ -186,27 +188,40 @@ func init() {
|
||||
}
|
||||
depSpinner.Success()
|
||||
|
||||
packSpinner := spinner.New("Packing + Compiling project...")
|
||||
compileMessage := "Packing + Compiling project"
|
||||
if releaseMode {
|
||||
compileMessage += " (Release Mode)"
|
||||
}
|
||||
|
||||
packSpinner := spinner.New(compileMessage + "...")
|
||||
packSpinner.SetSpinSpeed(50)
|
||||
packSpinner.Start()
|
||||
|
||||
buildCommand := "packr build"
|
||||
buildCommand := slicer.String()
|
||||
buildCommand.AddSlice([]string{"packr", "build"})
|
||||
|
||||
// Add build tags
|
||||
if len(buildTags) > 0 {
|
||||
buildCommand += fmt.Sprintf(" --tags '%s'", strings.Join(buildTags, " "))
|
||||
buildCommand.Add("--tags")
|
||||
buildCommand.AddSlice(buildTags)
|
||||
|
||||
}
|
||||
|
||||
if projectOptions.BinaryName != "" {
|
||||
buildCommand += " -o " + projectOptions.BinaryName
|
||||
buildCommand.Add("-o")
|
||||
buildCommand.Add(projectOptions.BinaryName)
|
||||
}
|
||||
|
||||
// If we are forcing a rebuild
|
||||
if forceRebuild {
|
||||
buildCommand += " -a"
|
||||
buildCommand.Add(" -a")
|
||||
}
|
||||
|
||||
err = program.RunCommand(buildCommand)
|
||||
// Release mode
|
||||
if releaseMode {
|
||||
buildCommand.AddSlice([]string{"-ldflags","-X github.com/wailsapp/wails.DebugMode=false"})
|
||||
}
|
||||
err = program.RunCommandArray(buildCommand.AsSlice())
|
||||
if err != nil {
|
||||
packSpinner.Error()
|
||||
return err
|
||||
|
1
go.mod
1
go.mod
@ -12,6 +12,7 @@ require (
|
||||
github.com/gorilla/websocket v1.4.0
|
||||
github.com/jackmordaunt/icns v1.0.0
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/leaanthony/slicer v0.0.0-20190110113548-aa9ea12f976a
|
||||
github.com/leaanthony/spinner v0.4.0
|
||||
github.com/leaanthony/synx v0.0.0-20180923230033-60efbd9984b0 // indirect
|
||||
github.com/leaanthony/wincursor v0.0.0-20180705115120-056510f32d15 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -216,6 +216,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/leaanthony/slicer v0.0.0-20190110113548-aa9ea12f976a h1:+nH6CKt4ZdMj+AabQrU0SLtZWYyQ1ovzLCA21se+raw=
|
||||
github.com/leaanthony/slicer v0.0.0-20190110113548-aa9ea12f976a/go.mod h1:VMB/HGvr3uR3MRpFWHWAm0w+DHQLzPHYe2pKfpFlQIQ=
|
||||
github.com/leaanthony/spinner v0.4.0 h1:y/7FqQqqObRKYI+33bg9DGhHIY7cQHicm+Vz0Uda0Ik=
|
||||
github.com/leaanthony/spinner v0.4.0/go.mod h1:2Mmv+8Brcw3NwPT1DdOLmW6+zWpSamDDFFsUvVHo2cc=
|
||||
github.com/leaanthony/spinner v0.5.0 h1:OJKn+0KP6ilHxwCEOv5Lo0wPM4PgWZWLJTeUprGJK0g=
|
||||
|
2
log.go
2
log.go
@ -29,6 +29,8 @@ func setLogLevel(level string) {
|
||||
logger.SetLevel(log.DebugLevel)
|
||||
case "warn":
|
||||
logger.SetLevel(log.WarnLevel)
|
||||
case "error":
|
||||
logger.SetLevel(log.ErrorLevel)
|
||||
case "fatal":
|
||||
logger.SetLevel(log.FatalLevel)
|
||||
case "panic":
|
||||
|
@ -1,7 +1,9 @@
|
||||
package wails
|
||||
|
||||
// CustomLogger is a wrapper object to logrus
|
||||
type CustomLogger struct {
|
||||
prefix string
|
||||
prefix string
|
||||
errorOnly bool
|
||||
}
|
||||
|
||||
func newCustomLogger(prefix string) *CustomLogger {
|
||||
@ -10,73 +12,92 @@ func newCustomLogger(prefix string) *CustomLogger {
|
||||
}
|
||||
}
|
||||
|
||||
// Info level message
|
||||
func (c *CustomLogger) Info(message string) {
|
||||
logger.Info(c.prefix + message)
|
||||
}
|
||||
|
||||
// Infof - formatted message
|
||||
func (c *CustomLogger) Infof(message string, args ...interface{}) {
|
||||
logger.Infof(c.prefix+message, args...)
|
||||
}
|
||||
|
||||
// InfoFields - message with fields
|
||||
func (c *CustomLogger) InfoFields(message string, fields Fields) {
|
||||
logger.WithFields(map[string]interface{}(fields)).Info(c.prefix + message)
|
||||
}
|
||||
|
||||
// Debug level message
|
||||
func (c *CustomLogger) Debug(message string) {
|
||||
logger.Debug(c.prefix + message)
|
||||
}
|
||||
|
||||
// Debugf - formatted message
|
||||
func (c *CustomLogger) Debugf(message string, args ...interface{}) {
|
||||
logger.Debugf(c.prefix+message, args...)
|
||||
}
|
||||
|
||||
// DebugFields - message with fields
|
||||
func (c *CustomLogger) DebugFields(message string, fields Fields) {
|
||||
logger.WithFields(map[string]interface{}(fields)).Debug(c.prefix + message)
|
||||
}
|
||||
|
||||
// Warn level message
|
||||
func (c *CustomLogger) Warn(message string) {
|
||||
logger.Warn(c.prefix + message)
|
||||
}
|
||||
|
||||
// Warnf - formatted message
|
||||
func (c *CustomLogger) Warnf(message string, args ...interface{}) {
|
||||
logger.Warnf(c.prefix+message, args...)
|
||||
}
|
||||
|
||||
// WarnFields - message with fields
|
||||
func (c *CustomLogger) WarnFields(message string, fields Fields) {
|
||||
logger.WithFields(map[string]interface{}(fields)).Warn(c.prefix + message)
|
||||
}
|
||||
|
||||
// Error level message
|
||||
func (c *CustomLogger) Error(message string) {
|
||||
logger.Error(c.prefix + message)
|
||||
}
|
||||
|
||||
// Errorf - formatted message
|
||||
func (c *CustomLogger) Errorf(message string, args ...interface{}) {
|
||||
logger.Errorf(c.prefix+message, args...)
|
||||
}
|
||||
|
||||
// ErrorFields - message with fields
|
||||
func (c *CustomLogger) ErrorFields(message string, fields Fields) {
|
||||
logger.WithFields(map[string]interface{}(fields)).Error(c.prefix + message)
|
||||
}
|
||||
|
||||
// Fatal level message
|
||||
func (c *CustomLogger) Fatal(message string) {
|
||||
logger.Fatal(c.prefix + message)
|
||||
}
|
||||
|
||||
// Fatalf - formatted message
|
||||
func (c *CustomLogger) Fatalf(message string, args ...interface{}) {
|
||||
logger.Fatalf(c.prefix+message, args...)
|
||||
}
|
||||
|
||||
// FatalFields - message with fields
|
||||
func (c *CustomLogger) FatalFields(message string, fields Fields) {
|
||||
logger.WithFields(map[string]interface{}(fields)).Fatal(c.prefix + message)
|
||||
}
|
||||
|
||||
// Panic level message
|
||||
func (c *CustomLogger) Panic(message string) {
|
||||
logger.Panic(c.prefix + message)
|
||||
}
|
||||
|
||||
// Panicf - formatted message
|
||||
func (c *CustomLogger) Panicf(message string, args ...interface{}) {
|
||||
logger.Panicf(c.prefix+message, args...)
|
||||
}
|
||||
|
||||
// PanicFields - message with fields
|
||||
func (c *CustomLogger) PanicFields(message string, fields Fields) {
|
||||
logger.WithFields(map[string]interface{}(fields)).Panic(c.prefix + message)
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
var headlessAssets = packr.NewBox("./assets/headless")
|
||||
var defaultAssets = packr.NewBox("./assets/default")
|
||||
|
||||
// Window defines the main application window
|
||||
// Default values in []
|
||||
// Headless is a backend that opens a local web server
|
||||
// and renders the files over a websocket
|
||||
type Headless struct {
|
||||
// Common
|
||||
log *CustomLogger
|
||||
@ -34,6 +34,7 @@ type Headless struct {
|
||||
theConnection *websocket.Conn
|
||||
}
|
||||
|
||||
// Initialise the Headless Renderer
|
||||
func (h *Headless) Initialise(appConfig *AppConfig, ipcManager *ipcManager, eventManager *eventManager) error {
|
||||
h.ipcManager = ipcManager
|
||||
h.appConfig = appConfig
|
||||
@ -68,7 +69,7 @@ func (h *Headless) injectCSS(css string) {
|
||||
}
|
||||
|
||||
func (h *Headless) rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
indexHTML := headlessAssets.String("index.html")
|
||||
indexHTML := BoxString(&headlessAssets, "index.html")
|
||||
fmt.Fprintf(w, "%s", indexHTML)
|
||||
}
|
||||
|
||||
@ -102,11 +103,11 @@ func (h *Headless) start(conn *websocket.Conn) {
|
||||
// for the html() function
|
||||
if h.appConfig.isHTMLFragment {
|
||||
// Inject jquery
|
||||
jquery := defaultAssets.String("jquery.3.3.1.min.js")
|
||||
jquery := BoxString(&defaultAssets, "jquery.3.3.1.min.js")
|
||||
h.evalJS(jquery)
|
||||
}
|
||||
|
||||
wailsRuntime := defaultAssets.String("wails.js")
|
||||
wailsRuntime := BoxString(&defaultAssets, "wails.js")
|
||||
h.evalJS(wailsRuntime)
|
||||
|
||||
// Inject the initial JS
|
||||
@ -177,12 +178,13 @@ func (h *Headless) start(conn *websocket.Conn) {
|
||||
continue
|
||||
}
|
||||
|
||||
h.log.Infof("Got message: %#v\n", string(buffer))
|
||||
h.log.Debugf("Got message: %#v\n", string(buffer))
|
||||
|
||||
h.ipcManager.Dispatch(string(buffer))
|
||||
}
|
||||
}
|
||||
|
||||
// Run the app in headless mode!
|
||||
func (h *Headless) Run() error {
|
||||
h.server = &http.Server{Addr: ":34115"}
|
||||
http.HandleFunc("/ws", h.wsHandler)
|
||||
@ -198,32 +200,49 @@ func (h *Headless) Run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// NewBinding creates a new binding with the frontend
|
||||
func (h *Headless) NewBinding(methodName string) error {
|
||||
objectCode := fmt.Sprintf("window.wails._.newBinding(`%s`);", methodName)
|
||||
h.bindingCache = append(h.bindingCache, objectCode)
|
||||
return nil
|
||||
}
|
||||
|
||||
// InjectFramework sets up what JS/CSS should be injected
|
||||
// at startup
|
||||
func (h *Headless) InjectFramework(js, css string) {
|
||||
h.frameworkJS = js
|
||||
h.frameworkCSS = css
|
||||
}
|
||||
|
||||
// SelectFile is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SelectFile() string {
|
||||
h.log.Error("SelectFile() unsupported in headless mode")
|
||||
return ""
|
||||
}
|
||||
|
||||
// SelectDirectory is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SelectDirectory() string {
|
||||
h.log.Error("SelectDirectory() unsupported in headless mode")
|
||||
return ""
|
||||
}
|
||||
|
||||
// SelectSaveFile is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SelectSaveFile() string {
|
||||
h.log.Error("SelectSaveFile() unsupported in headless mode")
|
||||
return ""
|
||||
}
|
||||
|
||||
// AddJSList adds a slice of JS strings to the list of js
|
||||
// files injected at startup
|
||||
func (h *Headless) AddJSList(jsCache []string) {
|
||||
h.jsCache = jsCache
|
||||
}
|
||||
|
||||
// AddCSSList adds a slice of CSS strings to the list of css
|
||||
// files injected at startup
|
||||
func (h *Headless) AddCSSList(cssCache []string) {
|
||||
h.cssCache = cssCache
|
||||
}
|
||||
@ -234,6 +253,7 @@ func (h *Headless) Callback(data string) error {
|
||||
return h.evalJS(callbackCMD)
|
||||
}
|
||||
|
||||
// NotifyEvent notifies the frontend of an event
|
||||
func (h *Headless) NotifyEvent(event *eventData) error {
|
||||
|
||||
// Look out! Nils about!
|
||||
@ -261,19 +281,33 @@ func (h *Headless) NotifyEvent(event *eventData) error {
|
||||
return h.evalJS(message)
|
||||
}
|
||||
|
||||
// SetColour is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SetColour(colour string) error {
|
||||
h.log.WarnFields("SetColour ignored for headless more", Fields{"col": colour})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fullscreen is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) Fullscreen() {
|
||||
h.log.Warn("Fullscreen() unsupported in headless mode")
|
||||
}
|
||||
|
||||
// UnFullscreen is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) UnFullscreen() {
|
||||
h.log.Warn("UnFullscreen() unsupported in headless mode")
|
||||
}
|
||||
|
||||
// SetTitle is currently unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SetTitle(title string) {
|
||||
h.log.WarnFields("SetTitle() unsupported in headless mode", Fields{"title": title})
|
||||
}
|
||||
|
||||
// Close is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) Close() {
|
||||
h.log.Warn("Close() unsupported in headless mode")
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ func (w *webViewRenderer) Run() error {
|
||||
// Runtime assets
|
||||
assets := packr.NewBox("./assets/default")
|
||||
|
||||
wailsRuntime := assets.String("wails.js")
|
||||
wailsRuntime := BoxString(&assets, "wails.js")
|
||||
w.evalJS(wailsRuntime)
|
||||
|
||||
// Ping the wait channel when the wails runtime is loaded
|
||||
@ -173,7 +173,7 @@ func (w *webViewRenderer) Run() error {
|
||||
go func() {
|
||||
// Will we mount a custom component
|
||||
// Inject jquery
|
||||
jquery := assets.String("jquery.3.3.1.min.js")
|
||||
jquery := BoxString(&assets, "jquery.3.3.1.min.js")
|
||||
w.evalJSSync(jquery)
|
||||
|
||||
// Inject Bindings
|
||||
|
12
utils.go
12
utils.go
@ -1,7 +1,10 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
func escapeJS(js string) (string, error) {
|
||||
@ -10,3 +13,12 @@ func escapeJS(js string) (string, error) {
|
||||
result = strings.Replace(result, "\n", "\\n", -1)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// BoxString wraps packr.FindString
|
||||
func BoxString(box *packr.Box, filename string) string {
|
||||
result, err := box.FindString(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user