diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 406bd32a..52f6fe37 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -1188,7 +1188,7 @@ func (w *macosWebviewWindow) run() { // Translate ShouldClose to common WindowClosing event w.parent.On(events.Mac.WindowShouldClose, func(_ *WindowEventContext) { - w.emit(events.Common.WindowClosing) + w.parent.emit(events.Common.WindowClosing) }) if w.parent.options.HTML != "" { diff --git a/v3/pkg/application/webview_window_darwin.m b/v3/pkg/application/webview_window_darwin.m index 1a5b80c8..77c5496f 100644 --- a/v3/pkg/application/webview_window_darwin.m +++ b/v3/pkg/application/webview_window_darwin.m @@ -48,6 +48,10 @@ extern bool hasListeners(unsigned int); } @end @implementation WebviewWindowDelegate +- (BOOL)windowShouldClose:(NSWindow *)sender { + processWindowEvent(self.windowId, EventWindowShouldClose); + return false; +} - (void) dealloc { // Makes sure to remove the retained properties so the reference counter of the retains are decreased self.leftMouseEvent = nil; @@ -56,7 +60,6 @@ extern bool hasListeners(unsigned int); // Handle script messages from the external bridge - (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message { NSString *m = message.body; - // TODO: Standardise drag by sending the drag event back to Go if ( [m isEqualToString:@"drag"] ) { /* @@ -373,12 +376,6 @@ extern bool hasListeners(unsigned int); } } -- (void)windowShouldClose:(NSNotification *)notification { - if( hasListeners(EventWindowShouldClose) ) { - processWindowEvent(self.windowId, EventWindowShouldClose); - } -} - - (void)windowWillBecomeKey:(NSNotification *)notification { if( hasListeners(EventWindowWillBecomeKey) ) { processWindowEvent(self.windowId, EventWindowWillBecomeKey); diff --git a/v3/pkg/events/events.txt b/v3/pkg/events/events.txt index 8f579f20..51af3aae 100644 --- a/v3/pkg/events/events.txt +++ b/v3/pkg/events/events.txt @@ -63,7 +63,7 @@ mac:WindowDidUpdateShadow mac:WindowDidUpdateTitle mac:WindowDidUpdateToolbar mac:WindowDidUpdateVisibility -mac:WindowShouldClose +mac:WindowShouldClose! mac:WindowWillBecomeKey mac:WindowWillBecomeMain mac:WindowWillBeginSheet diff --git a/v3/tasks/events/generate.go b/v3/tasks/events/generate.go index e098b357..b7ac0f2c 100644 --- a/v3/tasks/events/generate.go +++ b/v3/tasks/events/generate.go @@ -178,41 +178,6 @@ func main() { } windowsEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n") windowsEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n") - // cHeaderEvents.WriteString("#define Event" + eventTitle + " " + strconv.Itoa(id) + "\n") - // if ignoreEvent { - // continue - // } - // // Check if this is a window event - // if strings.HasPrefix(event, "Window") { - // windowDelegateEvents.WriteString(`- (void)` + delegateEventFunction + `:(NSNotification *)notification { - // if( hasListeners(Event` + eventTitle + `) ) { - // processWindowEvent(self.windowId, Event` + eventTitle + `); - // } - //} - // - //`) - // } - // // Check if this is a webview event - // if strings.HasPrefix(event, "WebView") { - // webViewFunction := strings.TrimPrefix(event, "WebView") - // webViewFunction = string(bytes.ToLower([]byte{webViewFunction[0]})) + webViewFunction[1:] - // webviewDelegateEvents.WriteString(`- (void)webView:(WKWebView *)webview ` + webViewFunction + `:(WKNavigation *)navigation { - // if( hasListeners(Event` + eventTitle + `) ) { - // processWindowEvent(self.windowId, Event` + eventTitle + `); - // } - //} - // - //`) - // } - // if strings.HasPrefix(event, "Application") { - // applicationDelegateEvents.WriteString(`- (void)` + delegateEventFunction + `:(NSNotification *)notification { - // if( hasListeners(Event` + eventTitle + `) ) { - // processApplicationEvent(Event` + eventTitle + `); - // } - //} - // - //`) - // } } }