diff --git a/.core/TODO.md b/.core/TODO.md index e69de29b..fd033dda 100644 --- a/.core/TODO.md +++ b/.core/TODO.md @@ -0,0 +1 @@ +- @bug pkg/window/state.go:26 — window state persistence writes to the default home config path, which breaks restricted test/runtime environments unless the target path is configurable. diff --git a/stubs/wails/pkg/application/application.go b/stubs/wails/pkg/application/application.go index 8b07e8e8..bdefae6c 100644 --- a/stubs/wails/pkg/application/application.go +++ b/stubs/wails/pkg/application/application.go @@ -143,10 +143,16 @@ type WindowEventContext struct { } func (c *WindowEventContext) DroppedFiles() []string { + if c == nil { + return nil + } return append([]string(nil), c.droppedFiles...) } func (c *WindowEventContext) DropTargetDetails() *DropTargetDetails { + if c == nil { + return nil + } if c.dropDetails == nil { return nil } @@ -165,6 +171,9 @@ type WindowEvent struct { } func (e *WindowEvent) Context() *WindowEventContext { + if e == nil { + return nil + } if e.ctx == nil { e.ctx = &WindowEventContext{} } diff --git a/stubs/wails/pkg/application/application_test.go b/stubs/wails/pkg/application/application_test.go index b3bef5ba..f1c748ea 100644 --- a/stubs/wails/pkg/application/application_test.go +++ b/stubs/wails/pkg/application/application_test.go @@ -249,6 +249,19 @@ func TestApplication_WindowEvent_Ugly(t *testing.T) { assert.Equal(t, []string{"file"}, event.Context().DroppedFiles()) } +func TestApplication_WindowEvent_NilReceiver(t *testing.T) { + var event *WindowEvent + + assert.Nil(t, event.Context()) +} + +func TestApplication_WindowEventContext_NilReceiver(t *testing.T) { + var ctx *WindowEventContext + + assert.Empty(t, ctx.DroppedFiles()) + assert.Nil(t, ctx.DropTargetDetails()) +} + func TestApplication_WebviewWindow_Good(t *testing.T) { manager := &WindowManager{} window := manager.NewWithOptions(WebviewWindowOptions{ diff --git a/stubs/wails/pkg/application/events.go b/stubs/wails/pkg/application/events.go index f4b389f8..38907636 100644 --- a/stubs/wails/pkg/application/events.go +++ b/stubs/wails/pkg/application/events.go @@ -45,6 +45,9 @@ func (e *ApplicationEvent) Context() *ApplicationEventContext { // // event.Cancel() func (e *ApplicationEvent) Cancel() { + if e == nil { + return + } e.cancelled.Store(true) } @@ -52,6 +55,9 @@ func (e *ApplicationEvent) Cancel() { // // if event.IsCancelled() { return } func (e *ApplicationEvent) IsCancelled() bool { + if e == nil { + return false + } return e.cancelled.Load() } @@ -69,6 +75,9 @@ type CustomEvent struct { // // event.Cancel() func (e *CustomEvent) Cancel() { + if e == nil { + return + } e.cancelled.Store(true) } @@ -76,6 +85,9 @@ func (e *CustomEvent) Cancel() { // // if event.IsCancelled() { return } func (e *CustomEvent) IsCancelled() bool { + if e == nil { + return false + } return e.cancelled.Load() } diff --git a/stubs/wails/pkg/application/events_test.go b/stubs/wails/pkg/application/events_test.go index fcd433f1..e400dad5 100644 --- a/stubs/wails/pkg/application/events_test.go +++ b/stubs/wails/pkg/application/events_test.go @@ -35,6 +35,15 @@ func TestEvents_CustomEvent_Ugly(t *testing.T) { assert.Equal(t, []any{"a", 1}, event.Data) } +func TestEvents_CustomEvent_NilReceiver(t *testing.T) { + var event *CustomEvent + + assert.NotPanics(t, func() { + event.Cancel() + }) + assert.False(t, event.IsCancelled()) +} + func TestEvents_ApplicationEvent_Good(t *testing.T) { event := &ApplicationEvent{Id: 7, ctx: newApplicationEventContext()} @@ -60,6 +69,15 @@ func TestEvents_ApplicationEvent_Ugly(t *testing.T) { assert.True(t, event.IsCancelled()) } +func TestEvents_ApplicationEvent_NilReceiver(t *testing.T) { + var event *ApplicationEvent + + assert.NotPanics(t, func() { + event.Cancel() + }) + assert.False(t, event.IsCancelled()) +} + func TestEvents_EventManager_Emit_Good(t *testing.T) { manager := newEventManager() calls := 0