diff --git a/v2/cmd/wails/internal/commands/generate/template/base/go.tmpl.mod b/v2/cmd/wails/internal/commands/generate/template/base/go.tmpl.mod
index d3dd6ecd..2b2c9dc9 100644
--- a/v2/cmd/wails/internal/commands/generate/template/base/go.tmpl.mod
+++ b/v2/cmd/wails/internal/commands/generate/template/base/go.tmpl.mod
@@ -19,10 +19,8 @@ module changeme
github.com/leaanthony/debme v1.2.1 // indirect
github.com/leaanthony/go-ansi-parser v1.0.1 // indirect
github.com/leaanthony/go-common-file-dialog v1.0.3 // indirect
- github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/go-webview2 v0.0.0-20210914103035-f00aa774a934 // indirect
github.com/leaanthony/slicer v1.5.0 // indirect
github.com/leaanthony/typescriptify-golang-structs v0.1.7 // indirect
- github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc v0.0.0-20210921073452-54963136bf18 // indirect
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f // indirect
diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/go.mod.tmpl b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/go.mod.tmpl
index 06f70133..3b74eb32 100644
--- a/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/go.mod.tmpl
+++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/svelte/go.mod.tmpl
@@ -19,10 +19,8 @@ github.com/klauspost/compress v1.12.2 // indirect
github.com/leaanthony/debme v1.2.1 // indirect
github.com/leaanthony/go-ansi-parser v1.0.1 // indirect
github.com/leaanthony/go-common-file-dialog v1.0.3 // indirect
-github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/go-webview2 v0.0.0-20210914103035-f00aa774a934 // indirect
github.com/leaanthony/slicer v1.5.0 // indirect
github.com/leaanthony/typescriptify-golang-structs v0.1.7 // indirect
-github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc v0.0.0-20210921073452-54963136bf18 // indirect
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f // indirect
diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/go.mod.tmpl b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/go.mod.tmpl
index 06f70133..3b74eb32 100644
--- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/go.mod.tmpl
+++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/go.mod.tmpl
@@ -19,10 +19,8 @@ github.com/klauspost/compress v1.12.2 // indirect
github.com/leaanthony/debme v1.2.1 // indirect
github.com/leaanthony/go-ansi-parser v1.0.1 // indirect
github.com/leaanthony/go-common-file-dialog v1.0.3 // indirect
-github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/go-webview2 v0.0.0-20210914103035-f00aa774a934 // indirect
github.com/leaanthony/slicer v1.5.0 // indirect
github.com/leaanthony/typescriptify-golang-structs v0.1.7 // indirect
-github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc v0.0.0-20210921073452-54963136bf18 // indirect
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/savsgio/gotils v0.0.0-20200117113501-90175b0fbe3f // indirect
diff --git a/v2/internal/app/debug.go b/v2/internal/app/debug.go
deleted file mode 100644
index 3a6a6916..00000000
--- a/v2/internal/app/debug.go
+++ /dev/null
@@ -1,37 +0,0 @@
-//go:build dev
-// +build dev
-
-package app
-
-import (
- "flag"
- "strings"
-
- "github.com/wailsapp/wails/v2/pkg/logger"
-)
-
-// Init initialises the application for a debug environment
-func (a *App) Init() error {
- // Indicate debug mode
- a.debug = true
-
- // Set log levels
- loglevel := flag.String("loglevel", "debug", "Loglevel to use - Trace, Debug, Info, Warning, Error")
- flag.Parse()
- if len(*loglevel) > 0 {
- switch strings.ToLower(*loglevel) {
- case "trace":
- a.logger.SetLogLevel(logger.TRACE)
- case "info":
- a.logger.SetLogLevel(logger.INFO)
- case "warning":
- a.logger.SetLogLevel(logger.WARNING)
- case "error":
- a.logger.SetLogLevel(logger.ERROR)
- default:
- a.logger.SetLogLevel(logger.DEBUG)
- }
- }
-
- return nil
-}
diff --git a/v2/internal/app/default.go b/v2/internal/app/default.go
deleted file mode 100644
index 31f173cf..00000000
--- a/v2/internal/app/default.go
+++ /dev/null
@@ -1,42 +0,0 @@
-//go:build !desktop && !hybrid && !server && !dev
-// +build !desktop,!hybrid,!server,!dev
-
-package app
-
-// This is the default application that will get run if the user compiles using `go build`.
-// The reason we want to prevent that is that the `wails build` command does a lot of behind
-// the scenes work such as asset compilation. If we allow `go build`, the state of these assets
-// will be unknown and the application will not work as expected.
-
-import (
- "os"
-
- "github.com/wailsapp/wails/v2/internal/logger"
-
- "github.com/wailsapp/wails/v2/pkg/options"
-)
-
-// App defines a Wails application structure
-type App struct {
- Title string
- Width int
- Height int
- Resizable bool
-
- // Indicates if the app is running in debug mode
- debug bool
-
- logger *logger.Logger
-}
-
-// CreateApp returns a null application
-func CreateApp(_ *options.App) (*App, error) {
- return &App{}, nil
-}
-
-// Run the application
-func (a *App) Run() error {
- println(`FATAL: This application was built using "go build". This is unsupported. Please compile using "wails build".`)
- os.Exit(1)
- return nil
-}
diff --git a/v2/internal/app/desktop.go b/v2/internal/app/desktop.go
deleted file mode 100644
index b27f9291..00000000
--- a/v2/internal/app/desktop.go
+++ /dev/null
@@ -1,256 +0,0 @@
-//go:build desktop && !server
-// +build desktop,!server
-
-package app
-
-import (
- "context"
- "sync"
-
- "github.com/wailsapp/wails/v2/internal/binding"
- "github.com/wailsapp/wails/v2/internal/ffenestri"
- "github.com/wailsapp/wails/v2/internal/logger"
- "github.com/wailsapp/wails/v2/internal/menumanager"
- "github.com/wailsapp/wails/v2/internal/messagedispatcher"
- "github.com/wailsapp/wails/v2/internal/servicebus"
- "github.com/wailsapp/wails/v2/internal/signal"
- "github.com/wailsapp/wails/v2/internal/subsystem"
- "github.com/wailsapp/wails/v2/pkg/options"
-)
-
-// App defines a Wails application structure
-type App struct {
- appType string
-
- window *ffenestri.Application
- servicebus *servicebus.ServiceBus
- logger *logger.Logger
- signal *signal.Manager
- options *options.App
-
- // Subsystems
- log *subsystem.Log
- runtime *subsystem.Runtime
- event *subsystem.Event
- //binding *subsystem.Binding
- call *subsystem.Call
- menu *subsystem.Menu
- url *subsystem.URL
- dispatcher *messagedispatcher.Dispatcher
-
- menuManager *menumanager.Manager
-
- // Indicates if the app is in debug mode
- debug bool
-
- // This is our binding DB
- bindings *binding.Bindings
-
- // OnStartup/OnShutdown
- startupCallback func(ctx context.Context)
- shutdownCallback func()
-}
-
-// Create App
-func CreateApp(appoptions *options.App) (*App, error) {
-
- // Merge default options
- options.MergeDefaults(appoptions)
-
- // Set up logger
- myLogger := logger.New(appoptions.Logger)
- myLogger.SetLogLevel(appoptions.LogLevel)
-
- // Create the menu manager
- menuManager := menumanager.NewManager()
-
- // Process the application menu
- appMenu := options.GetApplicationMenu(appoptions)
- menuManager.SetApplicationMenu(appMenu)
-
- // Process context menus
- contextMenus := options.GetContextMenus(appoptions)
- for _, contextMenu := range contextMenus {
- menuManager.AddContextMenu(contextMenu)
- }
-
- // Process tray menus
- trayMenus := options.GetTrayMenus(appoptions)
- for _, trayMenu := range trayMenus {
- menuManager.AddTrayMenu(trayMenu)
- }
-
- window := ffenestri.NewApplicationWithConfig(appoptions, myLogger, menuManager)
-
- // Create binding exemptions - Ugly hack. There must be a better way
- bindingExemptions := []interface{}{appoptions.OnStartup, appoptions.OnShutdown, appoptions.OnDomReady}
-
- result := &App{
- appType: "desktop",
- window: window,
- servicebus: servicebus.New(myLogger),
- logger: myLogger,
- bindings: binding.NewBindings(myLogger, appoptions.Bind, bindingExemptions),
- menuManager: menuManager,
- startupCallback: appoptions.OnStartup,
- shutdownCallback: appoptions.OnShutdown,
- }
-
- result.options = appoptions
-
- // Initialise the app
- err := result.Init()
- if err != nil {
- return nil, err
- }
-
- // Preflight Checks
- err = result.PreflightChecks(appoptions)
- if err != nil {
- return nil, err
- }
-
- return result, nil
-
-}
-
-// Run the application
-func (a *App) Run() error {
-
- var err error
-
- // Setup a context
- var subsystemWaitGroup sync.WaitGroup
- parentContext := context.WithValue(context.Background(), "waitgroup", &subsystemWaitGroup)
- ctx, cancel := context.WithCancel(parentContext)
-
- // Start the service bus
- a.servicebus.Debug()
- err = a.servicebus.Start()
- if err != nil {
- return err
- }
-
- runtimesubsystem, err := subsystem.NewRuntime(ctx, a.servicebus, a.logger, a.startupCallback)
- if err != nil {
- return err
- }
- a.runtime = runtimesubsystem
- err = a.runtime.Start()
- if err != nil {
- return err
- }
-
- // Start the logging subsystem
- log, err := subsystem.NewLog(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.log = log
- err = a.log.Start()
- if err != nil {
- return err
- }
-
- // create the dispatcher
- dispatcher, err := messagedispatcher.New(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.dispatcher = dispatcher
- err = dispatcher.Start()
- if err != nil {
- return err
- }
-
- if a.options.Mac.URLHandlers != nil {
- // Start the url handler subsystem
- url, err := subsystem.NewURL(a.servicebus, a.logger, a.options.Mac.URLHandlers)
- if err != nil {
- return err
- }
- a.url = url
- err = a.url.Start()
- if err != nil {
- return err
- }
- }
-
- // Start the eventing subsystem
- eventsubsystem, err := subsystem.NewEvent(ctx, a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.event = eventsubsystem
- err = a.event.Start()
- if err != nil {
- return err
- }
-
- // Start the menu subsystem
- menusubsystem, err := subsystem.NewMenu(ctx, a.servicebus, a.logger, a.menuManager)
- if err != nil {
- return err
- }
- a.menu = menusubsystem
- err = a.menu.Start()
- if err != nil {
- return err
- }
-
- // Start the call subsystem
- callSubsystem, err := subsystem.NewCall(ctx, a.servicebus, a.logger, a.bindings.DB())
- if err != nil {
- return err
- }
- a.call = callSubsystem
- err = a.call.Start()
- if err != nil {
- return err
- }
-
- // Dump bindings as a debug
- bindingDump, err := a.bindings.ToJSON()
- if err != nil {
- return err
- }
-
- // Setup signal handler
- signalsubsystem, err := signal.NewManager(ctx, cancel, a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.signal = signalsubsystem
- a.signal.Start()
-
- err = a.window.Run(dispatcher, bindingDump, a.debug)
- a.logger.Trace("Ffenestri.Run() exited")
- if err != nil {
- return err
- }
-
- // Close down all the subsystems
- a.logger.Trace("Cancelling subsystems")
- cancel()
- subsystemWaitGroup.Wait()
-
- a.logger.Trace("Cancelling dispatcher")
- dispatcher.Close()
-
- // Close log
- a.logger.Trace("Stopping log")
- log.Close()
-
- a.logger.Trace("Stopping Service bus")
- err = a.servicebus.Stop()
- if err != nil {
- return err
- }
-
- // OnShutdown callback
- if a.shutdownCallback != nil {
- a.shutdownCallback()
- }
-
- return nil
-}
diff --git a/v2/internal/app/dev.go b/v2/internal/app/dev.go
deleted file mode 100644
index 3b7be059..00000000
--- a/v2/internal/app/dev.go
+++ /dev/null
@@ -1,249 +0,0 @@
-//go:build dev
-// +build dev
-
-package app
-
-/*
-import (
- "context"
- "sync"
-
- "github.com/wailsapp/wails/runtime"
-
- "github.com/wailsapp/wails/v2/internal/bridge"
- "github.com/wailsapp/wails/v2/internal/menumanager"
-
- "github.com/wailsapp/wails/v2/pkg/options"
-
- "github.com/wailsapp/wails/v2/internal/binding"
- "github.com/wailsapp/wails/v2/internal/logger"
- "github.com/wailsapp/wails/v2/internal/messagedispatcher"
- "github.com/wailsapp/wails/v2/internal/servicebus"
- "github.com/wailsapp/wails/v2/internal/signal"
- "github.com/wailsapp/wails/v2/internal/subsystem"
-)
-
-// App defines a Wails application structure
-type App struct {
- appType string
-
- servicebus *servicebus.ServiceBus
- logger *logger.Logger
- signal *signal.Manager
- options *options.App
-
- // Subsystems
- log *subsystem.Log
- runtime *subsystem.Runtime
- event *subsystem.Event
- //binding *subsystem.Binding
- call *subsystem.Call
- menu *subsystem.Menu
- dispatcher *messagedispatcher.Dispatcher
-
- menuManager *menumanager.Manager
-
- // Indicates if the app is in debug mode
- debug bool
-
- // This is our binding DB
- bindings *binding.Bindings
-
- // Application Stores
- loglevelStore *runtime.Store
- appconfigStore *runtime.Store
-
- // OnStartup/OnShutdown
- startupCallback func(*runtime.Runtime)
- shutdownCallback func()
-
- // Bridge
- bridge *bridge.Bridge
-}
-
-// Create App
-func CreateApp(appoptions *options.App) (*App, error) {
-
- // Merge default options
- options.MergeDefaults(appoptions)
-
- // Set up logger
- myLogger := logger.New(appoptions.Logger)
-
- // Create the menu manager
- menuManager := menumanager.NewManager()
-
- // Process the application menu
- menuManager.SetApplicationMenu(options.GetApplicationMenu(appoptions))
-
- // Process context menus
- contextMenus := options.GetContextMenus(appoptions)
- for _, contextMenu := range contextMenus {
- menuManager.AddContextMenu(contextMenu)
- }
-
- // Process tray menus
- trayMenus := options.GetTrayMenus(appoptions)
- for _, trayMenu := range trayMenus {
- menuManager.AddTrayMenu(trayMenu)
- }
-
- // Create binding exemptions - Ugly hack. There must be a better way
- bindingExemptions := []interface{}{appoptions.OnStartup, appoptions.OnShutdown, appoptions.OnDomReady}
-
- result := &App{
- appType: "dev",
- bindings: binding.NewBindings(myLogger, appoptions.Bind, bindingExemptions),
- logger: myLogger,
- servicebus: servicebus.New(myLogger),
- startupCallback: appoptions.OnStartup,
- shutdownCallback: appoptions.OnShutdown,
- bridge: bridge.NewBridge(myLogger),
- menuManager: menuManager,
- }
-
- result.options = appoptions
-
- // Initialise the app
- err := result.Init()
-
- return result, err
-
-}
-
-// Run the application
-func (a *App) Run() error {
-
- var err error
-
- // Setup a context
- var subsystemWaitGroup sync.WaitGroup
- parentContext := context.WithValue(context.Background(), "waitgroup", &subsystemWaitGroup)
- ctx, cancel := context.WithCancel(parentContext)
- defer cancel()
-
- // Start the service bus
- a.servicebus.Debug()
- err = a.servicebus.Start()
- if err != nil {
- return err
- }
-
- runtimesubsystem, err := subsystem.NewRuntime(ctx, a.servicebus, a.logger, a.startupCallback)
- if err != nil {
- return err
- }
- a.runtime = runtimesubsystem
- err = a.runtime.Start()
- if err != nil {
- return err
- }
-
- // Application Stores
- a.loglevelStore = a.runtime.GoRuntime().Store.New("wails:loglevel", a.options.LogLevel)
- a.appconfigStore = a.runtime.GoRuntime().Store.New("wails:appconfig", a.options)
-
- // Start the logging subsystem
- log, err := subsystem.NewLog(a.servicebus, a.logger, a.loglevelStore)
- if err != nil {
- return err
- }
- a.log = log
- err = a.log.Start()
- if err != nil {
- return err
- }
-
- // create the dispatcher
- dispatcher, err := messagedispatcher.New(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.dispatcher = dispatcher
- err = dispatcher.Start()
- if err != nil {
- return err
- }
-
- // Start the eventing subsystem
- eventsubsystem, err := subsystem.NewEvent(ctx, a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.event = eventsubsystem
- err = a.event.Start()
- if err != nil {
- return err
- }
-
- // Start the menu subsystem
- menusubsystem, err := subsystem.NewMenu(ctx, a.servicebus, a.logger, a.menuManager)
- if err != nil {
- return err
- }
- a.menu = menusubsystem
- err = a.menu.Start()
- if err != nil {
- return err
- }
-
- // Start the call subsystem
- callSubsystem, err := subsystem.NewCall(ctx, a.servicebus, a.logger, a.bindings.DB())
- if err != nil {
- return err
- }
- a.call = callSubsystem
- err = a.call.Start()
- if err != nil {
- return err
- }
-
- // Dump bindings as a debug
- bindingDump, err := a.bindings.ToJSON()
- if err != nil {
- return err
- }
-
- // Generate backend.js
- a.bindings.GenerateBackendJS()
-
- // Setup signal handler
- signalsubsystem, err := signal.NewManager(ctx, cancel, a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.signal = signalsubsystem
- a.signal.Start()
-
- err = a.bridge.Run(dispatcher, a.menuManager, bindingDump, a.debug)
- a.logger.Trace("Bridge.Run() exited")
- if err != nil {
- return err
- }
-
- // Close down all the subsystems
- a.logger.Trace("Cancelling subsystems")
- cancel()
- subsystemWaitGroup.Wait()
-
- a.logger.Trace("Cancelling dispatcher")
- dispatcher.Close()
-
- // Close log
- a.logger.Trace("Stopping log")
- log.Close()
-
- a.logger.Trace("Stopping Service bus")
- err = a.servicebus.Stop()
- if err != nil {
- return err
- }
-
- // OnShutdown callback
- if a.shutdownCallback != nil {
- a.shutdownCallback()
- }
- return nil
-
-}
-*/
diff --git a/v2/internal/app/hybrid.go b/v2/internal/app/hybrid.go
deleted file mode 100644
index c9ff11df..00000000
--- a/v2/internal/app/hybrid.go
+++ /dev/null
@@ -1,195 +0,0 @@
-//go:build !server && !desktop && hybrid
-// +build !server,!desktop,hybrid
-
-package app
-
-import (
- "os"
- "path/filepath"
-
- "github.com/leaanthony/clir"
- "github.com/wailsapp/wails/v2/internal/binding"
- "github.com/wailsapp/wails/v2/internal/ffenestri"
- "github.com/wailsapp/wails/v2/internal/logger"
- "github.com/wailsapp/wails/v2/internal/messagedispatcher"
- "github.com/wailsapp/wails/v2/internal/servicebus"
- "github.com/wailsapp/wails/v2/internal/subsystem"
- "github.com/wailsapp/wails/v2/internal/webserver"
-)
-
-// Config defines the Application's configuration
-type Config struct {
- Title string // Title is the value to be displayed in the title bar
- Width int // Width is the desired window width
- Height int // Height is the desired window height
- DevTools bool // DevTools enables or disables the browser development tools
- Resizable bool // Resizable when False prevents window resizing
- ServerEnabled bool // ServerEnabled when True allows remote connections
-}
-
-// App defines a Wails application structure
-type App struct {
- config Config
- window *ffenestri.Application
- webserver *webserver.WebServer
- binding *subsystem.Binding
- call *subsystem.Call
- event *subsystem.Event
- log *subsystem.Log
- runtime *subsystem.Runtime
-
- bindings *binding.Bindings
- logger *logger.Logger
- dispatcher *messagedispatcher.Dispatcher
- servicebus *servicebus.ServiceBus
-
- debug bool
-}
-
-// Create App
-func CreateApp(options *Options) *App {
-
- // Merge default options
- options.mergeDefaults()
-
- // Set up logger
- myLogger := logger.New(os.Stdout)
- myLogger.SetLogLevel(logger.INFO)
-
- window := ffenestri.NewApplicationWithConfig(&ffenestri.Config{
- Title: options.Title,
- Width: options.Width,
- Height: options.Height,
- MinWidth: options.MinWidth,
- MinHeight: options.MinHeight,
- MaxWidth: options.MaxWidth,
- MaxHeight: options.MaxHeight,
- StartHidden: options.StartHidden,
- DevTools: options.DevTools,
-
- Resizable: !options.DisableResize,
- Fullscreen: options.Fullscreen,
- }, myLogger)
-
- app := &App{
- window: window,
- webserver: webserver.NewWebServer(myLogger),
- servicebus: servicebus.New(myLogger),
- logger: myLogger,
- bindings: binding.NewBindings(myLogger, options.Bind),
- }
-
- // Initialise the app
- app.Init()
-
- return app
-}
-
-// Run the application
-func (a *App) Run() error {
-
- // Default app options
- var port = 8080
- var ip = "localhost"
- var suppressLogging = false
-
- // Create CLI
- cli := clir.NewCli(filepath.Base(os.Args[0]), "Desktop/Server Build", "")
-
- // Setup flags
- cli.IntFlag("p", "Port to serve on", &port)
- cli.StringFlag("i", "IP to serve on", &ip)
- cli.BoolFlag("q", "Suppress logging", &suppressLogging)
-
- // Setup main action
- cli.Action(func() error {
-
- // Set IP + Port
- a.webserver.SetPort(port)
- a.webserver.SetIP(ip)
- a.webserver.SetBindings(a.bindings)
- // Log information (if we aren't suppressing it)
- if !suppressLogging {
- cli.PrintBanner()
- a.logger.Info("Running server at %s", a.webserver.URL())
- }
-
- a.servicebus.Start()
- log, err := subsystem.NewLog(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.log = log
- a.log.Start()
- dispatcher, err := messagedispatcher.New(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.dispatcher = dispatcher
- a.dispatcher.Start()
-
- // Start the runtime
- runtime, err := subsystem.NewRuntime(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.runtime = runtime
- a.runtime.Start()
-
- // Start the binding subsystem
- binding, err := subsystem.NewBinding(a.servicebus, a.logger, a.bindings, runtime.GoRuntime())
- if err != nil {
- return err
- }
- a.binding = binding
- a.binding.Start()
-
- // Start the eventing subsystem
- event, err := subsystem.NewEvent(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.event = event
- a.event.Start()
-
- // Start the call subsystem
- call, err := subsystem.NewCall(a.servicebus, a.logger, a.bindings.DB())
- if err != nil {
- return err
- }
- a.call = call
- a.call.Start()
-
- // Required so that the WailsInit functions are fired!
- runtime.GoRuntime().Events.Emit("wails:loaded")
-
- // Set IP + Port
- a.webserver.SetPort(port)
- a.webserver.SetIP(ip)
-
- // Log information (if we aren't suppressing it)
- if !suppressLogging {
- cli.PrintBanner()
- println("Running server at " + a.webserver.URL())
- }
-
- // Dump bindings as a debug
- bindingDump, err := a.bindings.ToJSON()
- if err != nil {
- return err
- }
-
- go func() {
- if err := a.webserver.Start(dispatcher, event); err != nil {
- a.logger.Error("Webserver failed to start %s", err)
- }
- }()
-
- result := a.window.Run(dispatcher, bindingDump)
- a.servicebus.Stop()
-
- return result
- })
-
- return cli.Run()
-}
diff --git a/v2/internal/app/preflight_default.go b/v2/internal/app/preflight_default.go
deleted file mode 100644
index 00197098..00000000
--- a/v2/internal/app/preflight_default.go
+++ /dev/null
@@ -1,10 +0,0 @@
-//go:build !windows
-// +build !windows
-
-package app
-
-import "github.com/wailsapp/wails/v2/pkg/options"
-
-func (a *App) PreflightChecks(options *options.App) error {
- return nil
-}
diff --git a/v2/internal/app/preflight_windows.go b/v2/internal/app/preflight_windows.go
deleted file mode 100644
index f8e99497..00000000
--- a/v2/internal/app/preflight_windows.go
+++ /dev/null
@@ -1,27 +0,0 @@
-//go:build windows
-// +build windows
-
-package app
-
-import (
- "github.com/wailsapp/wails/v2/internal/ffenestri/windows/wv2runtime"
- "github.com/wailsapp/wails/v2/pkg/options"
-)
-
-func (a *App) PreflightChecks(options *options.App) error {
-
- _ = options
-
- // Process the webview2 runtime situation. We can pass a strategy in via the `webview2` flag for `wails build`.
- // This will determine how wv2runtime.Process will handle a lack of valid runtime.
- installedVersion, err := wv2runtime.Process()
- if installedVersion != nil {
- a.logger.Debug("WebView2 Runtime installed: Name: '%s' Version:'%s' Location:'%s'. Minimum version required: %s.",
- installedVersion.Name, installedVersion.Version, installedVersion.Location, wv2runtime.MinimumRuntimeVersion)
- }
- if err != nil {
- return err
- }
-
- return nil
-}
diff --git a/v2/internal/app/production.go b/v2/internal/app/production.go
deleted file mode 100644
index 9a255482..00000000
--- a/v2/internal/app/production.go
+++ /dev/null
@@ -1,12 +0,0 @@
-//go:build production
-// +build production
-
-package app
-
-import "github.com/wailsapp/wails/v2/pkg/logger"
-
-// Init initialises the application for a production environment
-func (a *App) Init() error {
- a.logger.SetLogLevel(logger.ERROR)
- return nil
-}
diff --git a/v2/internal/app/server.go b/v2/internal/app/server.go
deleted file mode 100644
index 06734f0a..00000000
--- a/v2/internal/app/server.go
+++ /dev/null
@@ -1,165 +0,0 @@
-//go:build server && !desktop
-// +build server,!desktop
-
-package app
-
-import (
- "context"
- "os"
- "path/filepath"
-
- "github.com/wailsapp/wails/v2/pkg/options"
-
- "github.com/leaanthony/clir"
- "github.com/wailsapp/wails/v2/internal/binding"
- "github.com/wailsapp/wails/v2/internal/logger"
- "github.com/wailsapp/wails/v2/internal/messagedispatcher"
- "github.com/wailsapp/wails/v2/internal/servicebus"
- "github.com/wailsapp/wails/v2/internal/subsystem"
- "github.com/wailsapp/wails/v2/internal/webserver"
-)
-
-// App defines a Wails application structure
-type App struct {
- appType string
-
- binding *subsystem.Binding
- call *subsystem.Call
- event *subsystem.Event
- log *subsystem.Log
-
- options *options.App
-
- bindings *binding.Bindings
- logger *logger.Logger
- dispatcher *messagedispatcher.Dispatcher
- servicebus *servicebus.ServiceBus
- webserver *webserver.WebServer
-
- debug bool
-
- // OnStartup/OnShutdown
- startupCallback func(ctx context.Context)
- shutdownCallback func()
-}
-
-// Create App
-func CreateApp(appoptions *options.App) (*App, error) {
-
- // Merge default options
- options.MergeDefaults(appoptions)
-
- // Set up logger
- myLogger := logger.New(appoptions.Logger)
- myLogger.SetLogLevel(appoptions.LogLevel)
-
- result := &App{
- appType: "server",
- bindings: binding.NewBindings(myLogger, options.Bind),
- logger: myLogger,
- servicebus: servicebus.New(myLogger),
- webserver: webserver.NewWebServer(myLogger),
- startupCallback: appoptions.OnStartup,
- shutdownCallback: appoptions.OnShutdown,
- }
-
- // Initialise app
- result.Init()
-
- return result, nil
-}
-
-// Run the application
-func (a *App) Run() error {
-
- // Default app options
- var port = 8080
- var ip = "localhost"
- var SuppressLogging = false
- var debugMode = false
-
- // Create CLI
- cli := clir.NewCli(filepath.Base(os.Args[0]), "Server Build", "")
-
- // Setup flags
- cli.IntFlag("p", "Port to serve on", &port)
- cli.StringFlag("i", "IP to serve on", &ip)
- cli.BoolFlag("d", "Debug mode", &debugMode)
- cli.BoolFlag("q", "Suppress logging", &SuppressLogging)
-
- // Setup main action
- cli.Action(func() error {
-
- // Set IP + Port
- a.webserver.SetPort(port)
- a.webserver.SetIP(ip)
- a.webserver.SetBindings(a.bindings)
- // Log information (if we aren't Suppressing it)
- if !SuppressLogging {
- cli.PrintBanner()
- a.logger.Info("Running server at %s", a.webserver.URL())
- }
-
- if debugMode {
- a.servicebus.Debug()
- }
-
- // Start the runtime
- runtime, err := subsystem.NewRuntime(a.servicebus, a.logger, a.startupCallback)
- if err != nil {
- return err
- }
- a.runtime = runtime
- a.runtime.Start()
-
- a.servicebus.Start()
- log, err := subsystem.NewLog(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.log = log
- a.log.Start()
- dispatcher, err := messagedispatcher.New(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.dispatcher = dispatcher
- a.dispatcher.Start()
-
- // Start the binding subsystem
- binding, err := subsystem.NewBinding(a.servicebus, a.logger, a.bindings)
- if err != nil {
- return err
- }
- a.binding = binding
- a.binding.Start()
-
- // Start the eventing subsystem
- event, err := subsystem.NewEvent(a.servicebus, a.logger)
- if err != nil {
- return err
- }
- a.event = event
- a.event.Start()
-
- // Start the call subsystem
- call, err := subsystem.NewCall(a.servicebus, a.logger, a.bindings.DB(), a.runtime.GoRuntime())
- if err != nil {
- return err
- }
- a.call = call
- a.call.Start()
-
- // Required so that the WailsInit functions are fired!
- runtime.GoRuntime().Events.Emit("wails:loaded")
-
- if err := a.webserver.Start(dispatcher, event); err != nil {
- a.logger.Error("Webserver failed to start %s", err)
- return err
- }
-
- return nil
- })
-
- return cli.Run()
-}
diff --git a/v2/internal/assetdb/assetdb.go b/v2/internal/assetdb/assetdb.go
deleted file mode 100644
index 54892952..00000000
--- a/v2/internal/assetdb/assetdb.go
+++ /dev/null
@@ -1,112 +0,0 @@
-package assetdb
-
-import (
- "fmt"
- "strings"
- "unsafe"
-)
-
-// AssetDB is a database for assets encoded as byte slices
-type AssetDB struct {
- db map[string][]byte
-}
-
-// NewAssetDB creates a new AssetDB and initialises a blank db
-func NewAssetDB() *AssetDB {
- return &AssetDB{
- db: make(map[string][]byte),
- }
-}
-
-// AddAsset saves the given byte slice under the given name
-func (a *AssetDB) AddAsset(name string, data []byte) {
- a.db[name] = data
-}
-
-// Remove removes the named asset
-func (a *AssetDB) Remove(name string) {
- delete(a.db, name)
-}
-
-// Asset retrieves the byte slice for the given name
-func (a *AssetDB) Read(name string) ([]byte, error) {
- result := a.db[name]
- if result == nil {
- return nil, fmt.Errorf("asset '%s' not found", name)
- }
- return result, nil
-}
-
-// AssetAsString returns the asset as a string.
-// It also returns a boolean indicating whether the asset existed or not.
-func (a *AssetDB) String(name string) (string, error) {
- asset, err := a.Read(name)
- if err != nil {
- return "", err
- }
- return *(*string)(unsafe.Pointer(&asset)), nil
-}
-
-func (a *AssetDB) Dump() {
- fmt.Printf("Assets:\n")
- for k, _ := range a.db {
- fmt.Println(k)
- }
-}
-
-// Serialize converts the entire database to a file that when compiled will
-// reconstruct the AssetDB during init()
-// name: name of the asset.AssetDB instance
-// pkg: package name placed at the top of the file
-func (a *AssetDB) Serialize(name, pkg string) string {
- var cdata strings.Builder
- // Set buffer size to 4k
- cdata.Grow(4096)
-
- // Write header
- header := `// DO NOT EDIT - Generated automatically
-package %s
-
-import "github.com/wailsapp/wails/v2/internal/assetdb"
-
-var (
- %s *assetdb.AssetDB = assetdb.NewAssetDB()
-)
-
-// AssetsDB is a clean interface to the assetdb.AssetDB struct
-type AssetsDB interface {
- Read(string) ([]byte, error)
- String(string) (string, error)
-}
-
-// Assets returns the asset database
-func Assets() AssetsDB {
- return %s
-}
-
-func init() {
-`
- cdata.WriteString(fmt.Sprintf(header, pkg, name, name))
-
- for aname, bytes := range a.db {
- cdata.WriteString(fmt.Sprintf("\t%s.AddAsset(\"%s\", []byte{",
- name,
- aname))
-
- l := len(bytes)
- if l == 0 {
- cdata.WriteString("0x00})\n")
- continue
- }
-
- // Convert each byte to hex
- for _, b := range bytes[:l-1] {
- cdata.WriteString(fmt.Sprintf("0x%x, ", b))
- }
- cdata.WriteString(fmt.Sprintf("0x%x})\n", bytes[l-1]))
- }
-
- cdata.WriteString(`}`)
-
- return cdata.String()
-}
diff --git a/v2/internal/assetdb/assetdb_test.go b/v2/internal/assetdb/assetdb_test.go
deleted file mode 100644
index b3f34b9f..00000000
--- a/v2/internal/assetdb/assetdb_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package assetdb
-
-import "testing"
-import "github.com/matryer/is"
-
-func TestExistsAsBytes(t *testing.T) {
-
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("hello", helloworld)
-
- result, err := db.Read("hello")
-
- is.True(err == nil)
- is.Equal(result, helloworld)
-}
-
-func TestNotExistsAsBytes(t *testing.T) {
-
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("hello4", helloworld)
-
- result, err := db.Read("hello")
-
- is.True(err != nil)
- is.True(result == nil)
-}
-
-func TestExistsAsString(t *testing.T) {
-
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("hello", helloworld)
-
- result, err := db.String("hello")
-
- // Ensure it exists
- is.True(err == nil)
-
- // Ensure the string is the same as the byte slice
- is.Equal(result, "Hello, World!")
-}
-
-func TestNotExistsAsString(t *testing.T) {
-
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("hello", helloworld)
-
- result, err := db.String("help")
-
- // Ensure it doesn't exist
- is.True(err != nil)
-
- // Ensure the string is blank
- is.Equal(result, "")
-}
diff --git a/v2/internal/assetdb/filesystem.go b/v2/internal/assetdb/filesystem.go
deleted file mode 100644
index 954d97ca..00000000
--- a/v2/internal/assetdb/filesystem.go
+++ /dev/null
@@ -1,178 +0,0 @@
-//go:build !desktop
-// +build !desktop
-
-package assetdb
-
-import (
- "errors"
- "io"
- "net/http"
- "os"
- "path"
- "sort"
- "strings"
- "time"
-)
-
-var errWhence = errors.New("Seek: invalid whence")
-var errOffset = errors.New("Seek: invalid offset")
-
-// Open implements the http.FileSystem interface for the AssetDB
-func (a *AssetDB) Open(name string) (http.File, error) {
- if name == "/" || name == "" {
- return &Entry{name: "/", dir: true, db: a}, nil
- }
-
- if data, ok := a.db[name]; ok {
- return &Entry{name: name, data: data, size: len(data)}, nil
- } else {
- for n, _ := range a.db {
- if strings.HasPrefix(n, name+"/") {
- return &Entry{name: name, db: a, dir: true}, nil
- }
- }
- }
- return &Entry{}, os.ErrNotExist
-}
-
-// readdir returns the directory entries for the requested directory
-func (a *AssetDB) readdir(name string) ([]os.FileInfo, error) {
- dir := name
- var ents []string
-
- fim := make(map[string]os.FileInfo)
- for fn, data := range a.db {
- if strings.HasPrefix(fn, dir) {
- pieces := strings.Split(fn[len(dir)+1:], "/")
- if len(pieces) == 1 {
- fim[pieces[0]] = FI{name: pieces[0], dir: false, size: len(data)}
- ents = append(ents, pieces[0])
- } else {
- fim[pieces[0]] = FI{name: pieces[0], dir: true, size: -1}
- ents = append(ents, pieces[0])
- }
- }
- }
-
- if len(ents) == 0 {
- return nil, os.ErrNotExist
- }
-
- sort.Strings(ents)
- var list []os.FileInfo
- for _, dir := range ents {
- list = append(list, fim[dir])
- }
- return list, nil
-}
-
-// Entry implements the http.File interface to allow for
-// use in the http.FileSystem implementation of AssetDB
-type Entry struct {
- name string
- data []byte
- dir bool
- size int
- db *AssetDB
- off int
-}
-
-// Close is a noop
-func (e Entry) Close() error {
- return nil
-}
-
-// Read fills the slice provided returning how many bytes were written
-// and any errors encountered
-func (e *Entry) Read(p []byte) (n int, err error) {
- if e.off >= e.size {
- return 0, io.EOF
- }
- numout := len(p)
- if numout > e.size {
- numout = e.size
- }
- for i := 0; i < numout; i++ {
- p[i] = e.data[e.off+i]
- }
- e.off += numout
- n = int(numout)
- err = nil
- return
-}
-
-// Seek seeks to the specified offset from the location specified by whence
-func (e *Entry) Seek(offset int64, whence int) (int64, error) {
- switch whence {
- default:
- return 0, errWhence
- case io.SeekStart:
- offset += 0
- case io.SeekCurrent:
- offset += int64(e.off)
- case io.SeekEnd:
- offset += int64(e.size)
- }
-
- if offset < 0 {
- return 0, errOffset
- }
- e.off = int(offset)
- return offset, nil
-}
-
-// Readdir returns the directory entries inside this entry if it is a directory
-func (e Entry) Readdir(count int) ([]os.FileInfo, error) {
- ents := []os.FileInfo{}
- if !e.dir {
- return ents, errors.New("Not a directory")
- }
- return e.db.readdir(e.name)
-}
-
-// Stat returns information about this directory entry
-func (e Entry) Stat() (os.FileInfo, error) {
- return FI{e.name, e.size, e.dir}, nil
-}
-
-// FI is the AssetDB implementation of os.FileInfo.
-type FI struct {
- name string
- size int
- dir bool
-}
-
-// IsDir returns true if this is a directory
-func (fi FI) IsDir() bool {
- return fi.dir
-}
-
-// ModTime always returns now
-func (fi FI) ModTime() time.Time {
- return time.Time{}
-}
-
-// Mode returns the file as readonly and directories
-// as world writeable and executable
-func (fi FI) Mode() os.FileMode {
- if fi.IsDir() {
- return 0755 | os.ModeDir
- }
- return 0444
-}
-
-// Name returns the name of this object without
-// any leading slashes
-func (fi FI) Name() string {
- return path.Base(fi.name)
-}
-
-// Size returns the size of this item
-func (fi FI) Size() int64 {
- return int64(fi.size)
-}
-
-// Sys returns nil
-func (fi FI) Sys() interface{} {
- return nil
-}
diff --git a/v2/internal/assetdb/filesystem_test.go b/v2/internal/assetdb/filesystem_test.go
deleted file mode 100644
index 1c2ed94a..00000000
--- a/v2/internal/assetdb/filesystem_test.go
+++ /dev/null
@@ -1,108 +0,0 @@
-package assetdb
-
-import (
- "fmt"
- "os"
- "testing"
-
- "github.com/matryer/is"
-)
-
-func TestOpenLeadingSlash(t *testing.T) {
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("/hello", helloworld)
-
- file, err := db.Open("/hello")
- // Ensure it does exist
- is.True(err == nil)
-
- buff := make([]byte, len(helloworld))
- n, err := file.Read(buff)
- fmt.Printf("Error %v\n", err)
- is.True(err == nil)
- is.Equal(n, len(helloworld))
- result := string(buff)
-
- // Ensure the string is blank
- is.Equal(result, string(helloworld))
-}
-
-func TestOpen(t *testing.T) {
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("/hello", helloworld)
-
- file, err := db.Open("/hello")
-
- // Ensure it does exist
- is.True(err == nil)
-
- buff := make([]byte, len(helloworld))
- n, err := file.Read(buff)
- is.True(err == nil)
- is.Equal(n, len(helloworld))
- result := string(buff)
-
- // Ensure the string is blank
- is.Equal(result, string(helloworld))
-}
-
-func TestReaddir(t *testing.T) {
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("/hello", helloworld)
- db.AddAsset("/directory/hello", helloworld)
- db.AddAsset("/directory/subdirectory/hello", helloworld)
-
- dir, err := db.Open("/doesntexist")
- is.True(err == os.ErrNotExist)
- ents, err := dir.Readdir(-1)
- is.Equal([]os.FileInfo{}, ents)
-
- dir, err = db.Open("/")
- is.True(dir != nil)
- is.True(err == nil)
- ents, err = dir.Readdir(-1)
- is.True(err == nil)
- is.Equal(3, len(ents))
-}
-
-func TestReaddirSubdirectory(t *testing.T) {
- is := is.New(t)
-
- var helloworld = []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
-
- db := NewAssetDB()
- db.AddAsset("/hello", helloworld)
- db.AddAsset("/directory/hello", helloworld)
- db.AddAsset("/directory/subdirectory/hello", helloworld)
-
- expected := []os.FileInfo{
- FI{name: "hello", dir: false, size: len(helloworld)},
- FI{name: "subdirectory", dir: true, size: -1},
- }
-
- dir, err := db.Open("/directory")
- is.True(dir != nil)
- is.True(err == nil)
- ents, err := dir.Readdir(-1)
- is.Equal(expected, ents)
-
- // Check sub-subdirectory
- dir, err = db.Open("/directory/subdirectory")
- is.True(dir != nil)
- is.True(err == nil)
- ents, err = dir.Readdir(-1)
- is.True(err == nil)
- is.Equal([]os.FileInfo{FI{name: "hello", size: len(helloworld)}}, ents)
-}
diff --git a/v2/internal/bind/bind.go b/v2/internal/bind/bind.go
deleted file mode 100644
index 156fd4ce..00000000
--- a/v2/internal/bind/bind.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package bind
-
-func IsStructPointer(value interface{}) bool {
- switch t := value.(type) {
- default:
- println(t)
- }
- return false
-}
diff --git a/v2/internal/bridge/bridge.go b/v2/internal/bridge/bridge.go
deleted file mode 100644
index 1ea509d3..00000000
--- a/v2/internal/bridge/bridge.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package bridge
-
-import (
- "context"
- "log"
- "net/http"
- "sync"
-
- "github.com/wailsapp/wails/v2/internal/menumanager"
-
- "github.com/wailsapp/wails/v2/internal/messagedispatcher"
-
- "github.com/gorilla/websocket"
- "github.com/wailsapp/wails/v2/internal/logger"
-)
-
-type Bridge struct {
- upgrader websocket.Upgrader
- server *http.Server
- myLogger *logger.Logger
-
- bindings string
- dispatcher *messagedispatcher.Dispatcher
-
- mu sync.Mutex
- sessions map[string]*session
-
- ctx context.Context
- cancel context.CancelFunc
-
- // Dialog client
- dialog *messagedispatcher.DispatchClient
-
- // Menus
- menumanager *menumanager.Manager
-}
-
-func NewBridge(myLogger *logger.Logger) *Bridge {
- result := &Bridge{
- myLogger: myLogger,
- upgrader: websocket.Upgrader{CheckOrigin: func(r *http.Request) bool { return true }},
- sessions: make(map[string]*session),
- }
-
- myLogger.SetLogLevel(1)
-
- ctx, cancel := context.WithCancel(context.Background())
- result.ctx = ctx
- result.cancel = cancel
- result.server = &http.Server{Addr: ":34115"}
- http.HandleFunc("/bridge", result.wsBridgeHandler)
- return result
-}
-
-func (b *Bridge) Run(dispatcher *messagedispatcher.Dispatcher, menumanager *menumanager.Manager, bindings string, debug bool) error {
-
- // Ensure we cancel the context when we shutdown
- defer b.cancel()
-
- b.bindings = bindings
- b.dispatcher = dispatcher
- b.menumanager = menumanager
-
- // Setup dialog handler
- dialogClient := NewDialogClient(b.myLogger)
- b.dialog = dispatcher.RegisterClient(dialogClient)
- dialogClient.dispatcher = b.dialog
-
- b.myLogger.Info("Bridge mode started.")
-
- err := b.server.ListenAndServe()
- if err != nil && err != http.ErrServerClosed {
- return err
- }
-
- return nil
-}
-
-func (b *Bridge) wsBridgeHandler(w http.ResponseWriter, r *http.Request) {
- c, err := b.upgrader.Upgrade(w, r, nil)
- if err != nil {
- log.Print("upgrade:", err)
- return
- }
-
- if err != nil {
- http.Error(w, "Could not open websocket connection", http.StatusBadRequest)
- }
- b.myLogger.Info("Connection from frontend accepted [%s].", c.RemoteAddr().String())
- b.startSession(c)
-
-}
-
-func (b *Bridge) startSession(conn *websocket.Conn) {
-
- // Create a new session for this connection
- s := newSession(conn, b.menumanager, b.bindings, b.dispatcher, b.myLogger, b.ctx)
-
- // Setup the close handler
- conn.SetCloseHandler(func(int, string) error {
- b.myLogger.Info("Connection dropped [%s].", s.Identifier())
- b.dispatcher.RemoveClient(s.client)
- b.mu.Lock()
- delete(b.sessions, s.Identifier())
- b.mu.Unlock()
- return nil
- })
-
- b.mu.Lock()
- go s.start(len(b.sessions) == 0)
- b.sessions[s.Identifier()] = s
- b.mu.Unlock()
-}
diff --git a/v2/internal/bridge/client.go b/v2/internal/bridge/client.go
deleted file mode 100644
index 2c2db80e..00000000
--- a/v2/internal/bridge/client.go
+++ /dev/null
@@ -1,141 +0,0 @@
-package bridge
-
-import (
- "github.com/wailsapp/wails/v2/pkg/runtime"
-)
-
-type BridgeClient struct {
- session *session
-
- // Tray menu cache to send to reconnecting clients
- messageCache chan string
-}
-
-func (b BridgeClient) DeleteTrayMenuByID(id string) {
- b.session.sendMessage("TD" + id)
-}
-
-func NewBridgeClient() *BridgeClient {
- return &BridgeClient{
- messageCache: make(chan string, 100),
- }
-}
-
-func (b BridgeClient) Quit() {
- b.session.log.Info("Quit unsupported in Bridge mode")
-}
-
-func (b BridgeClient) NotifyEvent(message string) {
- b.session.sendMessage("n" + message)
- b.session.log.Info("Notify: %s", message)
-}
-
-func (b BridgeClient) CallResult(message string) {
- b.session.sendMessage("c" + message)
-}
-
-func (b BridgeClient) OpenFileDialog(dialogOptions runtime.OpenDialogOptions, callbackID string) {
- // Handled by dialog_client
-}
-
-func (b BridgeClient) OpenMultipleFilesDialog(dialogOptions runtime.OpenDialogOptions, callbackID string) {
- // Handled by dialog_client
-}
-
-func (b BridgeClient) OpenDirectoryDialog(dialogOptions runtime.OpenDialogOptions, callbackID string) {
- // Handled by dialog_client
-}
-
-func (b BridgeClient) SaveDialog(dialogOptions runtime.SaveDialogOptions, callbackID string) {
- // Handled by dialog_client
-}
-
-func (b BridgeClient) MessageDialog(dialogOptions runtime.MessageDialogOptions, callbackID string) {
- // Handled by dialog_client
-}
-
-func (b BridgeClient) WindowSetTitle(title string) {
- b.session.log.Info("WindowSetTitle unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowShow() {
- b.session.log.Info("WindowShow unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowHide() {
- b.session.log.Info("WindowHide unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowCenter() {
- b.session.log.Info("WindowCenter unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowMaximise() {
- b.session.log.Info("WindowMaximise unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowUnmaximise() {
- b.session.log.Info("WindowUnmaximise unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowMinimise() {
- b.session.log.Info("WindowMinimise unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowUnminimise() {
- b.session.log.Info("WindowUnminimise unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowPosition(x int, y int) {
- b.session.log.Info("WindowPosition unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowSize(width int, height int) {
- b.session.log.Info("WindowSize unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowSetMinSize(width int, height int) {
- b.session.log.Info("WindowSetMinSize unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowSetMaxSize(width int, height int) {
- b.session.log.Info("WindowSetMaxSize unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowFullscreen() {
- b.session.log.Info("WindowFullscreen unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowUnfullscreen() {
- b.session.log.Info("WindowUnfullscreen unsupported in Bridge mode")
-}
-
-func (b BridgeClient) WindowSetColour(colour int) {
- b.session.log.Info("WindowSetColour unsupported in Bridge mode")
-}
-
-func (b BridgeClient) DarkModeEnabled(callbackID string) {
- b.session.log.Info("DarkModeEnabled unsupported in Bridge mode")
-}
-
-func (b BridgeClient) MenuSetApplicationMenu(menuJSON string) {
- b.session.log.Info("MenuSetApplicationMenu unsupported in Bridge mode")
-}
-
-func (b BridgeClient) SetTrayMenu(trayMenuJSON string) {
- b.session.sendMessage("TS" + trayMenuJSON)
-}
-
-func (b BridgeClient) UpdateTrayMenuLabel(trayMenuJSON string) {
- b.session.sendMessage("TU" + trayMenuJSON)
-}
-
-func (b BridgeClient) UpdateContextMenu(contextMenuJSON string) {
- b.session.log.Info("UpdateContextMenu unsupported in Bridge mode")
-}
-
-func newBridgeClient(session *session) *BridgeClient {
- return &BridgeClient{
- session: session,
- }
-}
diff --git a/v2/internal/bridge/darwin.js b/v2/internal/bridge/darwin.js
deleted file mode 100644
index 4758b4e2..00000000
--- a/v2/internal/bridge/darwin.js
+++ /dev/null
@@ -1 +0,0 @@
-var Wails=function(n){var t={};function e(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return n[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=n,e.c=t,e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:r})},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},e.t=function(n,t){if(1&t&&(n=e(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var i in n)e.d(r,i,function(t){return n[t]}.bind(null,i));return r},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=0)}([function(n,t,e){"use strict";e.r(t);var r={};e.r(r),e.d(r,"Trace",(function(){return v})),e.d(r,"Print",(function(){return p})),e.d(r,"Debug",(function(){return y})),e.d(r,"Info",(function(){return m})),e.d(r,"Warning",(function(){return b})),e.d(r,"Error",(function(){return g})),e.d(r,"Fatal",(function(){return h})),e.d(r,"SetLogLevel",(function(){return S})),e.d(r,"Level",(function(){return E}));var i={};e.r(i),e.d(i,"Open",(function(){return x}));var o={};e.r(o),e.d(o,"Center",(function(){return N})),e.d(o,"SetTitle",(function(){return T})),e.d(o,"Fullscreen",(function(){return j})),e.d(o,"UnFullscreen",(function(){return D})),e.d(o,"SetSize",(function(){return I})),e.d(o,"SetPosition",(function(){return P})),e.d(o,"Hide",(function(){return A})),e.d(o,"Show",(function(){return J})),e.d(o,"Maximise",(function(){return L})),e.d(o,"Unmaximise",(function(){return R})),e.d(o,"Minimise",(function(){return _})),e.d(o,"Unminimise",(function(){return F})),e.d(o,"Close",(function(){return U}));var a={};e.r(a),e.d(a,"Open",(function(){return B})),e.d(a,"Save",(function(){return H})),e.d(a,"Message",(function(){return G}));var u={};e.r(u),e.d(u,"New",(function(){return en}));var c={};e.r(c),e.d(c,"SetIcon",(function(){return rn}));var l={AppType:"desktop",Platform:function(){return"darwin"}};var s=[];function f(n){s.push(n)}function d(n){if(function(n){window.wailsInvoke(n)}(n),s.length>0)for(var t=0;t
`, 1) - - url := url.URL{Path: result} - urlString := strings.ReplaceAll(url.String(), "/", "%2f") - - // Save Data uRI string - return "data:text/html;charset=utf-8," + urlString, nil - - case AssetTypes.CSS: - - // Escape CSS data - var re = regexp.MustCompile(`\s{2,}`) - result := re.ReplaceAllString(a.Data, ``) - result = strings.ReplaceAll(result, "\n", "") - result = strings.ReplaceAll(result, "\r\n", "") - result = strings.ReplaceAll(result, "\n", "") - result = strings.ReplaceAll(result, "\t", "") - result = strings.ReplaceAll(result, `\`, `\\`) - result = strings.ReplaceAll(result, `"`, `\"`) - result = strings.ReplaceAll(result, `'`, `\'`) - result = strings.ReplaceAll(result, ` {`, `{`) - result = strings.ReplaceAll(result, `: `, `:`) - return fmt.Sprintf("window.wails._.InjectCSS(\"%s\");", result), nil - - case AssetTypes.JS: - m := minify.New() - m.AddFunc("application/javascript", js.Minify) - var err error - result, err := m.String("application/javascript", a.Data+";") - if err != nil { - return "", err - } - return result, nil - default: - return "", fmt.Errorf("minification for asset type %s not implemented", a.Type) - } -} - -// AsCHexData processes the asset data so it may be used by C -func (a *Asset) AsCHexData() string { - dataString, err := a.minifiedData() - if err != nil { - log.Fatal(err) - } - // Get byte data of the string - bytes := *(*[]byte)(unsafe.Pointer(&dataString)) - - // Create a strings builder - var cdata strings.Builder - - // Set buffer size to 4k - cdata.Grow(4096) - - // Convert each byte to hex - for _, b := range bytes { - cdata.WriteString(fmt.Sprintf("0x%x, ", b)) - } - - return cdata.String() -} - -// Dump will output the asset to the terminal -func (a *Asset) Dump() { - fmt.Printf("{ Type: %s, Path: %s, Data: %+v }\n", a.Type, a.Path, a.Data[:10]) -} diff --git a/v2/internal/html/asset_test.go b/v2/internal/html/asset_test.go deleted file mode 100644 index f743b4ba..00000000 --- a/v2/internal/html/asset_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package html - -import "testing" - -func TestAsset_minifiedData(t *testing.T) { - type fields struct { - Type string - Path string - Data string - } - tests := []struct { - name string - fields fields - want string - wantErr bool - }{ - { - name: "multi-line tag", - fields: fields{ - Type: AssetTypes.HTML, - Path: "foo.html", - Data: "\n", - }, - want: "data:text/html;charset=utf-8,%3Clink%20rel=%22stylesheet%22%20href=%22src%2ffoo.css%22%20%3E%20", - }, - { - name: "multi-line tag no spaces", - fields: fields{ - Type: AssetTypes.HTML, - Path: "foo.html", - Data: "\n", - }, - want: "data:text/html;charset=utf-8,%3Clink%20rel=%22stylesheet%22%20href=%22src%2ffoo.css%22%20%3E%20", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - a := &Asset{ - Type: tt.fields.Type, - Path: tt.fields.Path, - Data: tt.fields.Data, - } - got, err := a.minifiedData() - if (err != nil) != tt.wantErr { - t.Errorf("Asset.minifiedData() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("Asset.minifiedData() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/v2/internal/html/assetbundle.go b/v2/internal/html/assetbundle.go deleted file mode 100644 index 1878357a..00000000 --- a/v2/internal/html/assetbundle.go +++ /dev/null @@ -1,218 +0,0 @@ -package html - -import ( - "bytes" - "fmt" - "io" - "os" - "path/filepath" - "strings" - - "github.com/leaanthony/slicer" - "github.com/wailsapp/wails/v2/internal/assetdb" - "golang.org/x/net/html" -) - -// AssetBundle is a collection of Assets -type AssetBundle struct { - assets []*Asset - basedirectory string -} - -// NewAssetBundle creates a new AssetBundle struct containing -// the given html and all the assets referenced by it -func NewAssetBundle(pathToHTML string) (*AssetBundle, error) { - - // Create result - result := &AssetBundle{ - basedirectory: filepath.Dir(pathToHTML), - } - - err := result.loadAssets(pathToHTML) - if err != nil { - return nil, err - } - - return result, nil -} - -// loadAssets processes the given html file and loads in -// all referenced assets -func (a *AssetBundle) loadAssets(pathToHTML string) error { - - // Save HTML - htmlAsset := &Asset{ - Type: AssetTypes.HTML, - Path: filepath.Base(pathToHTML), - } - err := htmlAsset.Load(a.basedirectory) - if err != nil { - return err - } - a.assets = append(a.assets, htmlAsset) - - return a.processHTML(htmlAsset.AsString()) -} - -// Credit to: https://drstearns.github.io/tutorials/tokenizing/ -func (a *AssetBundle) processHTML(htmldata string) error { - - // Tokenize the html - buf := bytes.NewBufferString(htmldata) - tokenizer := html.NewTokenizer(buf) - - paths := slicer.String() - - for { - //get the next token type - tokenType := tokenizer.Next() - - //if it's an error token, we either reached - //the end of the file, or the HTML was malformed - if tokenType == html.ErrorToken { - err := tokenizer.Err() - if err == io.EOF { - //end of the file, break out of the loop - break - } - //otherwise, there was an error tokenizing, - //which likely means the HTML was malformed. - //since this is a simple command-line utility, - //we can just use log.Fatalf() to report the error - //and exit the process with a non-zero status code - return tokenizer.Err() - } - - //process the token according to the token type... - if tokenType == html.StartTagToken || tokenType == html.SelfClosingTagToken { - //get the token - token := tokenizer.Token() - - //if the name of the element is "title" - if "link" == token.Data { - //the next token should be the page title - tokenType = tokenizer.Next() - //just make sure it's actually a text token - asset := &Asset{} - for _, attr := range token.Attr { - // Favicon - if attr.Key == "rel" && attr.Val == "icon" { - asset.Type = AssetTypes.FAVICON - } - if attr.Key == "href" { - asset.Path = attr.Val - } - // standard stylesheet - if attr.Key == "rel" && attr.Val == "stylesheet" { - asset.Type = AssetTypes.CSS - } - if attr.Key == "as" && attr.Val == "style" { - asset.Type = AssetTypes.CSS - } - if attr.Key == "as" && attr.Val == "script" { - asset.Type = AssetTypes.JS - } - if attr.Key == "rel" && attr.Val == "modulepreload" { - asset.Type = AssetTypes.JS - } - } - - // Ensure we don't include duplicates - if !paths.Contains(asset.Path) { - err := asset.Load(a.basedirectory) - if err != nil { - return err - } - a.assets = append(a.assets, asset) - paths.Add(asset.Path) - } - } - if "script" == token.Data { - tokenType = tokenizer.Next() - //just make sure it's actually a text token - asset := &Asset{Type: AssetTypes.JS} - for _, attr := range token.Attr { - if attr.Key == "src" { - asset.Path = attr.Val - break - } - } - if !paths.Contains(asset.Path) && asset.Path != "" { - err := asset.Load(a.basedirectory) - if err != nil { - return err - } - a.assets = append(a.assets, asset) - paths.Add(asset.Path) - } - } - } - } - - return nil -} - -// WriteToCFile dumps all the assets to C files in the given directory -func (a *AssetBundle) WriteToCFile(targetDir string) (string, error) { - - // Write out the assets.c file - var cdata strings.Builder - - // Write header - header := `// assets.h -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL. -// This file was auto-generated. DO NOT MODIFY. - -` - cdata.WriteString(header) - - // Loop over the Assets - var err error - assetVariables := slicer.String() - var variableName string - for index, asset := range a.assets { - // For desktop we ignore the favicon - if asset.Type == AssetTypes.FAVICON { - continue - } - variableName = fmt.Sprintf("%s%d", asset.Type, index) - assetCdata := fmt.Sprintf("const unsigned char %s[]={ %s0x00 };\n", variableName, asset.AsCHexData()) - cdata.WriteString(assetCdata) - assetVariables.Add(variableName) - } - - if assetVariables.Length() > 0 { - cdata.WriteString(fmt.Sprintf("\nconst unsigned char *assets[] = { %s, 0x00 };", assetVariables.Join(", "))) - } else { - cdata.WriteString("\nconst unsigned char *assets[] = { 0x00 };") - } - - // Save file - assetsFile := filepath.Join(targetDir, "assets.h") - err = os.WriteFile(assetsFile, []byte(cdata.String()), 0600) - if err != nil { - return "", err - } - return assetsFile, nil -} - -// ConvertToAssetDB returns an assetdb.AssetDB initialized with -// the items in the AssetBundle -func (a *AssetBundle) ConvertToAssetDB() (*assetdb.AssetDB, error) { - theassetdb := assetdb.NewAssetDB() - - // Loop over the Assets - for _, asset := range a.assets { - theassetdb.AddAsset(asset.Path, []byte(asset.Data)) - } - - return theassetdb, nil -} - -// Dump will output the assets to the terminal -func (a *AssetBundle) Dump() { - println("Assets:") - for _, asset := range a.assets { - asset.Dump() - } -} diff --git a/v2/internal/html/assetbundle_test.go b/v2/internal/html/assetbundle_test.go deleted file mode 100644 index d1009d7a..00000000 --- a/v2/internal/html/assetbundle_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package html - -import ( - "testing" -) - -func TestNewAssetBundle(t *testing.T) { - tests := []struct { - name string - pathToHTML string - wantAssets []string - wantErr bool - }{ - { - name: "basic html", - pathToHTML: "testdata/basic.html", - wantAssets: []string{ - AssetTypes.HTML, - AssetTypes.FAVICON, - AssetTypes.JS, - AssetTypes.CSS, - }, - wantErr: false, - }, - { - name: "self closing tags", - pathToHTML: "testdata/self_closing.html", - wantAssets: []string{ - AssetTypes.HTML, - AssetTypes.FAVICON, - AssetTypes.JS, - AssetTypes.CSS, - }, - wantErr: false, - }, - { - name: "multi-line tags", - pathToHTML: "testdata/self_closing.html", - wantAssets: []string{ - AssetTypes.HTML, - AssetTypes.FAVICON, - AssetTypes.JS, - AssetTypes.CSS, - }, - wantErr: false, - }, - { - name: "inline javascript", - pathToHTML: "testdata/inline_javascript.html", - wantAssets: []string{ - AssetTypes.HTML, - AssetTypes.FAVICON, - AssetTypes.JS, - AssetTypes.CSS, - }, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := NewAssetBundle(tt.pathToHTML) - if (err != nil) != tt.wantErr { - t.Errorf("NewAssetBundle() error = %v, wantErr %v", err, tt.wantErr) - return - } - if len(got.assets) != len(tt.wantAssets) { - t.Errorf("NewAssetBundle() len(assets) = %d, want %d", - len(got.assets), len(tt.wantAssets)) - } - - for i := range tt.wantAssets { - if i >= len(got.assets) { - t.Errorf("NewAssetBundle() missing assets[%d].Type = %s", - i, tt.wantAssets[i]) - } else { - if got.assets[i].Type != tt.wantAssets[i] { - t.Errorf("NewAssetBundle() assets[%d].Type = %s, want %s", - i, got.assets[i].Type, tt.wantAssets[i]) - } - } - } - }) - } -} diff --git a/v2/internal/html/testdata/basic.html b/v2/internal/html/testdata/basic.html deleted file mode 100644 index cdc3770b..00000000 --- a/v2/internal/html/testdata/basic.html +++ /dev/null @@ -1,14 +0,0 @@ - - -
- - - - - -
- -
-