Skip to content

Commit

Permalink
# Conflicts:
Browse files Browse the repository at this point in the history
#	mkdocs-website/docs/en/changelog.md
  • Loading branch information
leaanthony committed Sep 17, 2024
1 parent 2c55110 commit 4386f5f
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 37 deletions.
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion v3/examples/plain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

Expand Down
4 changes: 2 additions & 2 deletions v3/examples/wml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
})

Expand Down
2 changes: 1 addition & 1 deletion v3/internal/assetserver/assetserver_webview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
4 changes: 2 additions & 2 deletions v3/internal/signal/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
5 changes: 1 addition & 4 deletions v3/internal/templates/_common/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion v3/pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
29 changes: 12 additions & 17 deletions v3/plugins/experimental/oauth/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oauth

import (
"context"
"fmt"
"github.com/gorilla/pat"
"github.com/gorilla/sessions"
Expand All @@ -26,7 +27,6 @@ type Plugin struct {
config Config
server *http.Server
router *pat.Router
api application.PluginAPI
}

type Config struct {
Expand Down Expand Up @@ -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 = "/"
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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()
})

Expand All @@ -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
})
Expand Down Expand Up @@ -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()
})

Expand Down
9 changes: 5 additions & 4 deletions v3/plugins/experimental/single_instance/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package single_instance

import (
"context"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -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()
}

Expand All @@ -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())
Expand Down
7 changes: 4 additions & 3 deletions v3/plugins/experimental/start_at_login/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package start_at_login

import (
"context"
"github.com/wailsapp/wails/v3/pkg/application"
"io/fs"
)
Expand All @@ -22,17 +23,17 @@ 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
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 {
Expand Down

0 comments on commit 4386f5f

Please sign in to comment.