From 4386f5fcb240b84da0cf13f001c1ea78ca464b49 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 18 Sep 2024 05:55:49 +1000 Subject: [PATCH] # Conflicts: # mkdocs-website/docs/en/changelog.md --- mkdocs-website/docs/en/changelog.md | 1 + v3/examples/plain/main.go | 2 +- v3/examples/wml/main.go | 4 +-- .../assetserver/assetserver_webview.go | 2 +- .../testcases/complex_instantiations/funcs.go | 2 +- .../complex_instantiations/other/funcs.go | 2 +- v3/internal/signal/signal.go | 4 +-- v3/internal/templates/_common/main.go.tmpl | 5 +--- v3/pkg/application/application.go | 2 +- v3/plugins/experimental/oauth/plugin.go | 29 ++++++++----------- .../experimental/single_instance/plugin.go | 9 +++--- .../experimental/start_at_login/plugin.go | 7 +++-- 12 files changed, 32 insertions(+), 37 deletions(-) diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 3e99e2acf..ea5761970 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Do not bind internal service methods in [#3720](https://github.com/wailsapp/wails/pull/3720) by [leaanthony](https://github.com/leaanthony) - [windows] Fixed system tray startup panic in [#3693](https://github.com/wailsapp/wails/issues/3693) by [@DeltaLaboratory](https://github.com/DeltaLaboratory) - Major menu item refactor and event handling. Mainly improves macOS for now. By [leaanthony](https://github.com/leaanthony) +- Fix tests after plugins and event refactor in [#3746](https://github.com/wailsapp/wails/pull/3746) by [@stendler](https://github.com/stendler) - [windows] Fixed `Failed to unregister class Chrome_WidgetWin_0` warning. By [leaanthony](https://github.com/leaanthony) ## v3.0.0-alpha.6 - 2024-07-30 diff --git a/v3/examples/plain/main.go b/v3/examples/plain/main.go index 3676423a4..8f161e50d 100644 --- a/v3/examples/plain/main.go +++ b/v3/examples/plain/main.go @@ -42,7 +42,7 @@ func main() { JS: `window.iamhere = function() { console.log("Hello World!"); }`, }) - app.customEventProcessor.On("clicked", func(_ *application.CustomEvent) { + app.OnEvent("clicked", func(_ *application.CustomEvent) { println("clicked") }) diff --git a/v3/examples/wml/main.go b/v3/examples/wml/main.go index 52a040b8a..5b8b12ac4 100644 --- a/v3/examples/wml/main.go +++ b/v3/examples/wml/main.go @@ -35,10 +35,10 @@ func main() { }, }) - app.customEventProcessor.On("button-pressed", func(_ *application.CustomEvent) { + app.OnEvent("button-pressed", func(_ *application.CustomEvent) { println("Button Pressed!") }) - app.customEventProcessor.On("hover", func(_ *application.CustomEvent) { + app.OnEvent("hover", func(_ *application.CustomEvent) { println("Hover time!") }) diff --git a/v3/internal/assetserver/assetserver_webview.go b/v3/internal/assetserver/assetserver_webview.go index 8579d9463..377458533 100644 --- a/v3/internal/assetserver/assetserver_webview.go +++ b/v3/internal/assetserver/assetserver_webview.go @@ -79,7 +79,7 @@ func (a *AssetServer) processWebViewRequestInternal(r webview.Request) { uri, err = r.URL() if err != nil { - a.options.Logger.Error("Error processing request, unable to get URL: %s (HttpResponse=500)", err) + a.options.Logger.Error(fmt.Sprintf("Error processing request, unable to get URL: %s (HttpResponse=500)", err)) http.Error(rw, err.Error(), http.StatusInternalServerError) return } diff --git a/v3/internal/generator/testcases/complex_instantiations/funcs.go b/v3/internal/generator/testcases/complex_instantiations/funcs.go index 7aea0e7e0..73788baf6 100644 --- a/v3/internal/generator/testcases/complex_instantiations/funcs.go +++ b/v3/internal/generator/testcases/complex_instantiations/funcs.go @@ -2,7 +2,7 @@ package main import "github.com/wailsapp/wails/v3/pkg/application" -func ServiceInitialiser[T any]() func(*T) application.Service { +func ServiceInitialiser[T any]() func(*T, ...application.ServiceOptions) application.Service { return application.NewService[T] } diff --git a/v3/internal/generator/testcases/complex_instantiations/other/funcs.go b/v3/internal/generator/testcases/complex_instantiations/other/funcs.go index daf1ad066..1f413998e 100644 --- a/v3/internal/generator/testcases/complex_instantiations/other/funcs.go +++ b/v3/internal/generator/testcases/complex_instantiations/other/funcs.go @@ -6,7 +6,7 @@ func CustomNewService[T any](srv T) application.Service { return application.NewService(&srv) } -func ServiceInitialiser[T any]() func(*T) application.Service { +func ServiceInitialiser[T any]() func(*T, ...application.ServiceOptions) application.Service { return application.NewService[T] } diff --git a/v3/internal/signal/signal.go b/v3/internal/signal/signal.go index eb0ce6b16..8ac9821d0 100644 --- a/v3/internal/signal/signal.go +++ b/v3/internal/signal/signal.go @@ -39,10 +39,10 @@ func (s *SignalHandler) Start() { s.cleanup() break } else if i < s.MaxSignal { - s.Logger.Info("Received signal: %v. Press CTRL+C %d more times to force quit...\n", sig, s.MaxSignal-i) + s.Logger.Info(fmt.Sprintf("Received signal: %v. Press CTRL+C %d more times to force quit...\n", sig, s.MaxSignal-i)) continue } else { - s.Logger.Info("Received signal: %v. Force quitting...\n", sig) + s.Logger.Info(fmt.Sprintf("Received signal: %v. Force quitting...\n", sig)) os.Exit(1) } } diff --git a/v3/internal/templates/_common/main.go.tmpl b/v3/internal/templates/_common/main.go.tmpl index b93e392a9..948759204 100644 --- a/v3/internal/templates/_common/main.go.tmpl +++ b/v3/internal/templates/_common/main.go.tmpl @@ -62,10 +62,7 @@ func main() { go func() { for { now := time.Now().Format(time.RFC1123) - app.Events.Emit(&application.WailsEvent{ - Name: "time", - Data: now, - }) + app.EmitEvent("time", now) time.Sleep(time.Second) } }() diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index bad392beb..edbf16f7b 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -144,7 +144,7 @@ func New(appOptions Options) *App { if name == "" { name = getServiceName(service) } - globalApplication.error("OnStartup() failed:", "service", name, "error", err.Error()) + globalApplication.Logger.Error("OnStartup() failed:", "service", name, "error", err.Error()) continue } } diff --git a/v3/plugins/experimental/oauth/plugin.go b/v3/plugins/experimental/oauth/plugin.go index 2f2a1dd84..c70aa44f5 100644 --- a/v3/plugins/experimental/oauth/plugin.go +++ b/v3/plugins/experimental/oauth/plugin.go @@ -1,6 +1,7 @@ package oauth import ( + "context" "fmt" "github.com/gorilla/pat" "github.com/gorilla/sessions" @@ -26,7 +27,6 @@ type Plugin struct { config Config server *http.Server router *pat.Router - api application.PluginAPI } type Config struct { @@ -81,8 +81,7 @@ func (p *Plugin) Name() string { return "github.com/wailsapp/wails/v3/plugins/oauth" } -func (p *Plugin) Init(api application.PluginAPI) error { - p.api = api +func (p *Plugin) OnStartup(ctx context.Context, options application.ServiceOptions) error { store := sessions.NewCookieStore([]byte(p.config.SessionSecret)) store.MaxAge(p.config.MaxAge) store.Options.Path = "/" @@ -232,16 +231,13 @@ func (p *Plugin) start(provider string) error { router := pat.New() router.Get("/auth/{provider}/callback", func(res http.ResponseWriter, req *http.Request) { - event := &application.WailsEvent{Name: Success} - user, err := gothic.CompleteUserAuth(res, req) if err != nil { - event.Data = err.Error() - event.Name = Error + application.Get().EmitEvent(Error, err.Error()) } else { - event.Data = user + application.Get().EmitEvent(Success, user) } - application.Get().Events.Emit(event) + _ = p.server.Close() p.server = nil }) @@ -283,10 +279,10 @@ func (p *Plugin) start(provider string) error { window := application.Get().NewWebviewWindowWithOptions(*p.config.WindowConfig) window.Show() - application.Get().Events.On(Success, func(event *application.WailsEvent) { + application.Get().OnEvent(Success, func(event *application.CustomEvent) { window.Close() }) - application.Get().Events.On(Error, func(event *application.WailsEvent) { + application.Get().OnEvent(Error, func(event *application.CustomEvent) { window.Close() }) @@ -301,12 +297,11 @@ func (p *Plugin) logout(provider string) error { router := pat.New() router.Get("/logout/{provider}", func(res http.ResponseWriter, req *http.Request) { err := gothic.Logout(res, req) - event := &application.WailsEvent{Name: LoggedOut} if err != nil { - event.Data = err.Error() - event.Name = Error + application.Get().EmitEvent(Error, err.Error()) + } else { + application.Get().EmitEvent(LoggedOut) } - application.Get().Events.Emit(event) _ = p.server.Close() p.server = nil }) @@ -344,10 +339,10 @@ func (p *Plugin) logout(provider string) error { window := application.Get().NewWebviewWindowWithOptions(*p.config.WindowConfig) window.Show() - application.Get().Events.On(LoggedOut, func(event *application.WailsEvent) { + application.Get().OnEvent(LoggedOut, func(event *application.CustomEvent) { window.Close() }) - application.Get().Events.On(Error, func(event *application.WailsEvent) { + application.Get().OnEvent(Error, func(event *application.CustomEvent) { window.Close() }) diff --git a/v3/plugins/experimental/single_instance/plugin.go b/v3/plugins/experimental/single_instance/plugin.go index 227361e8f..5972dabf4 100644 --- a/v3/plugins/experimental/single_instance/plugin.go +++ b/v3/plugins/experimental/single_instance/plugin.go @@ -1,6 +1,7 @@ package single_instance import ( + "context" "fmt" "io/fs" "os" @@ -43,8 +44,8 @@ func NewPlugin(config *Config) *Plugin { } } -// Shutdown is called when the app is shutting down -func (p *Plugin) Shutdown() error { +// OnShutdown is called when the app is shutting down +func (p *Plugin) OnShutdown() error { return p.lockfile.Close() } @@ -53,10 +54,10 @@ func (p *Plugin) Name() string { return "github.com/wailsapp/wails/v3/plugins/single-instance" } -// Init is called when the app is starting up. You can use this to +// OnStartup is called when the app is starting up. You can use this to // initialise any resources you need. You can also access the application // instance via the app property. -func (p *Plugin) Init(api application.PluginAPI) error { +func (p *Plugin) OnStartup(ctx context.Context, options application.ServiceOptions) error { var err error lockfileName := p.config.LockFilePath + "/" + p.config.LockFileName p.lockfile, err = CreateLockFile(lockfileName, application.Get().GetPID()) diff --git a/v3/plugins/experimental/start_at_login/plugin.go b/v3/plugins/experimental/start_at_login/plugin.go index 5ec4970b8..cb0482eab 100644 --- a/v3/plugins/experimental/start_at_login/plugin.go +++ b/v3/plugins/experimental/start_at_login/plugin.go @@ -1,6 +1,7 @@ package start_at_login import ( + "context" "github.com/wailsapp/wails/v3/pkg/application" "io/fs" ) @@ -22,9 +23,9 @@ func NewPlugin(options Config) *Plugin { } } -// Shutdown is called when the app is shutting down +// OnShutdown is called when the app is shutting down // You can use this to clean up any resources you have allocated -func (p *Plugin) Shutdown() error { return nil } +func (p *Plugin) OnShutdown() error { return nil } // Name returns the name of the plugin. // You should use the go module format e.g. github.com/myuser/myplugin @@ -32,7 +33,7 @@ func (p *Plugin) Name() string { return "github.com/wailsapp/wails/v3/plugins/start_at_login" } -func (p *Plugin) Init(api application.PluginAPI) error { +func (p *Plugin) OnStartup(ctx context.Context, options application.ServiceOptions) error { // OS specific initialiser err := p.init() if err != nil {