Skip to content

Commit e64acd7

Browse files
committed
Better handling of "shouldclose"
1 parent 0cc0224 commit e64acd7

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

v3/pkg/application/webview_window_darwin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWa
4343
// Set delegate
4444
[window setDelegate:delegate];
4545
delegate.windowId = id;
46+
delegate.shouldClose = false;
4647
4748
// Add NSView to window
4849
NSView* view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, width-1, height-1)];
@@ -600,8 +601,17 @@ void windowSetShadow(void* nsWindow, bool hasShadow) {
600601
}
601602
602603
604+
// windowSetShouldClose sets the shouldClose flag on the window delegate
605+
static void windowSetShouldClose(void *window, bool shouldClose) {
606+
WebviewWindow* nsWindow = (WebviewWindow*)window;
607+
WebviewWindowDelegate* delegate = (WebviewWindowDelegate*)[nsWindow delegate];
608+
delegate.shouldClose = shouldClose;
609+
}
610+
603611
// windowClose closes the current window
604612
static void windowClose(void *window) {
613+
// Set the shouldClose flag to allow the window to close
614+
windowSetShouldClose(window, true);
605615
[(WebviewWindow*)window close];
606616
}
607617

v3/pkg/application/webview_window_darwin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@property unsigned int invisibleTitleBarHeight;
2626
@property BOOL showToolbarWhenFullscreen;
2727
@property NSWindowStyleMask previousStyleMask; // Used to restore the window style mask when using frameless
28+
@property BOOL shouldClose; // Flag to indicate if the window should close unconditionally
2829

2930
- (void)handleLeftMouseUp:(NSWindow *)window;
3031
- (void)handleLeftMouseDown:(NSEvent*)event;

v3/pkg/application/webview_window_darwin.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ - (void)performZoomReset:(id)sender {
231231
@implementation WebviewWindowDelegate
232232
- (BOOL)windowShouldClose:(NSWindow *)sender {
233233
WebviewWindowDelegate* delegate = (WebviewWindowDelegate*)[sender delegate];
234+
// Check if this window should close unconditionally (called from Close() method)
235+
if (delegate.shouldClose) {
236+
return true;
237+
}
238+
// Otherwise, emit the WindowClosing event and let the application decide
234239
processWindowEvent(delegate.windowId, EventWindowShouldClose);
235240
return false;
236241
}

v3/pkg/events/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var defaultWindowEventMapping = map[string]map[WindowEventType]WindowEventType{
4040
Mac.WindowZoomIn: Common.WindowZoomIn,
4141
Mac.WindowZoomOut: Common.WindowZoomOut,
4242
Mac.WindowZoomReset: Common.WindowZoomReset,
43-
Mac.WindowWillClose: Common.WindowClosing,
43+
Mac.WindowShouldClose: Common.WindowClosing,
4444
},
4545
"linux": {
4646
Linux.WindowDeleteEvent: Common.WindowClosing,

0 commit comments

Comments
 (0)