5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 04:59:38 +08:00

Added release mode flag

fixed logging
logging info level by default
This commit is contained in:
Lea Anthony 2019-01-10 22:48:54 +11:00
parent aaa425724c
commit 49e4f00b62
11 changed files with 78 additions and 31 deletions

23
app.go
View File

@ -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 {

View File

@ -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
})

View File

@ -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
}

View File

@ -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)

View File

@ -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)

View File

@ -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
View File

@ -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
View File

@ -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
View File

@ -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":

View File

@ -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)
}

View File

@ -177,12 +177,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)