5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-06 02:41:28 +08:00
wails/v3/plugins/experimental/server/plugin.go
2023-10-11 20:25:56 +11:00

64 lines
1.1 KiB
Go

package server
import (
_ "embed"
"fmt"
"github.com/wailsapp/wails/v3/pkg/application"
)
//go:embed plugin.js
var pluginJS string
//go:embed client.js
var clientJS string
type Config struct {
Host string
Port int
Enabled bool
Headers map[string]string
}
func (c Config) ListenAddress() string {
return fmt.Sprintf("%s:%d", c.Host, c.Port)
}
type Plugin struct {
config *Config
server *Server
}
func NewPlugin(config *Config) *Plugin {
return &Plugin{
config: config,
server: NewServer(config),
}
}
func (s *Plugin) CallableByJS() []string {
return []string{} // maybe # clients?
}
func (p *Plugin) InjectJS() string {
return pluginJS
}
// Init is called when the plugin is loaded. It is passed the application.App
// instance. This is where you should do any setup.
func (p *Plugin) Init() error {
p.server.app = application.Get()
p.server.run()
return nil
}
// Shutdown will stop the server
func (s *Plugin) Shutdown() {
s.server.Shutdown()
}
// Name returns the name of the plugin.
func (s *Plugin) Name() string {
return "github.com/wailsapp/wails/v3/plugins/server"
}