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

* resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com>
175 lines
4.3 KiB
Go
175 lines
4.3 KiB
Go
package wails
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
|
|
"github.com/syossan27/tebata"
|
|
"github.com/wailsapp/wails/cmd"
|
|
"github.com/wailsapp/wails/lib/binding"
|
|
"github.com/wailsapp/wails/lib/event"
|
|
"github.com/wailsapp/wails/lib/interfaces"
|
|
"github.com/wailsapp/wails/lib/ipc"
|
|
"github.com/wailsapp/wails/lib/logger"
|
|
"github.com/wailsapp/wails/lib/renderer"
|
|
wailsruntime "github.com/wailsapp/wails/runtime"
|
|
)
|
|
|
|
// -------------------------------- Compile time Flags ------------------------------
|
|
|
|
// BuildMode indicates what mode we are in
|
|
var BuildMode = cmd.BuildModeProd
|
|
|
|
// Runtime is the Go Runtime struct
|
|
type Runtime = wailsruntime.Runtime
|
|
|
|
// Store is a state store used for syncing with
|
|
// the front end
|
|
type Store = wailsruntime.Store
|
|
|
|
// CustomLogger is a specialised logger
|
|
type CustomLogger = logger.CustomLogger
|
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
// App defines the main application struct
|
|
type App struct {
|
|
config *AppConfig // The Application configuration object
|
|
cli *cmd.Cli // In debug mode, we have a cli
|
|
renderer interfaces.Renderer // The renderer is what we will render the app to
|
|
logLevel string // The log level of the app
|
|
ipc interfaces.IPCManager // Handles the IPC calls
|
|
log *logger.CustomLogger // Logger
|
|
bindingManager interfaces.BindingManager // Handles binding of Go code to renderer
|
|
eventManager interfaces.EventManager // Handles all the events
|
|
runtime interfaces.Runtime // The runtime object for registered structs
|
|
}
|
|
|
|
// CreateApp creates the application window with the given configuration
|
|
// If none given, the defaults are used
|
|
func CreateApp(optionalConfig ...*AppConfig) *App {
|
|
var userConfig *AppConfig
|
|
if len(optionalConfig) > 0 {
|
|
userConfig = optionalConfig[0]
|
|
}
|
|
|
|
result := &App{
|
|
logLevel: "debug",
|
|
renderer: renderer.NewWebView(),
|
|
ipc: ipc.NewManager(),
|
|
bindingManager: binding.NewManager(),
|
|
eventManager: event.NewManager(),
|
|
log: logger.NewCustomLogger("App"),
|
|
}
|
|
|
|
appconfig, err := newConfig(userConfig)
|
|
if err != nil {
|
|
result.log.Fatalf("Cannot use custom HTML: %s", err.Error())
|
|
}
|
|
result.config = appconfig
|
|
|
|
// Set up the CLI if not in release mode
|
|
if BuildMode != cmd.BuildModeProd {
|
|
result.cli = result.setupCli()
|
|
} else {
|
|
// Disable Inspector in release mode
|
|
result.config.DisableInspector = true
|
|
}
|
|
|
|
// Platform specific init
|
|
platformInit()
|
|
|
|
return result
|
|
}
|
|
|
|
// Run the app
|
|
func (a *App) Run() error {
|
|
|
|
if BuildMode != cmd.BuildModeProd {
|
|
return a.cli.Run()
|
|
}
|
|
|
|
a.logLevel = "error"
|
|
err := a.start()
|
|
if err != nil {
|
|
a.log.Error(err.Error())
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (a *App) start() error {
|
|
|
|
// Set the log level
|
|
logger.SetLogLevel(a.logLevel)
|
|
|
|
// Log starup
|
|
a.log.Info("Starting")
|
|
|
|
// Check if we are to run in bridge mode
|
|
if BuildMode == cmd.BuildModeBridge {
|
|
a.renderer = renderer.NewBridge()
|
|
}
|
|
|
|
// Initialise the renderer
|
|
err := a.renderer.Initialise(a.config, a.ipc, a.eventManager)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Start signal handler
|
|
t := tebata.New(os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
|
|
t.Reserve(func() {
|
|
a.log.Debug("SIGNAL CAUGHT! Starting Shutdown")
|
|
a.renderer.Close()
|
|
})
|
|
|
|
// Start event manager and give it our renderer
|
|
a.eventManager.Start(a.renderer)
|
|
|
|
// Start the IPC Manager and give it the event manager and binding manager
|
|
a.ipc.Start(a.eventManager, a.bindingManager)
|
|
|
|
// Create the runtime
|
|
a.runtime = wailsruntime.NewRuntime(a.eventManager, a.renderer)
|
|
|
|
// Start binding manager and give it our renderer
|
|
err = a.bindingManager.Start(a.renderer, a.runtime)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Defer the shutdown
|
|
defer a.shutdown()
|
|
|
|
// Run the renderer
|
|
err = a.renderer.Run()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// shutdown the app
|
|
func (a *App) shutdown() {
|
|
// Make sure this is only called once
|
|
a.log.Debug("Shutting down")
|
|
|
|
// Shutdown Binding Manager
|
|
a.bindingManager.Shutdown()
|
|
|
|
// Shutdown IPC Manager
|
|
a.ipc.Shutdown()
|
|
|
|
// Shutdown Event Manager
|
|
a.eventManager.Shutdown()
|
|
|
|
a.log.Debug("Cleanly Shutdown")
|
|
}
|
|
|
|
// Bind allows the user to bind the given object
|
|
// with the application
|
|
func (a *App) Bind(object interface{}) {
|
|
a.bindingManager.Bind(object)
|
|
}
|