Skip to content

Commit b185bf5

Browse files
committed
UI/AppKit: Request closure instead of always force closing tabs
1 parent 376937c commit b185bf5

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

UI/AppKit/Application/ApplicationDelegate.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ - (void)initializeTabController:(TabController*)controller
197197
- (void)closeCurrentTab:(id)sender
198198
{
199199
auto* current_window = [NSApp keyWindow];
200-
[current_window close];
200+
[current_window performClose:self];
201201
}
202202

203203
- (void)clearHistory:(id)sender

UI/AppKit/Interface/LadybirdWebView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,6 @@
6363
- (void)findInPageNextMatch;
6464
- (void)findInPagePreviousMatch;
6565

66+
- (void)requestClose;
67+
6668
@end

UI/AppKit/Interface/LadybirdWebView.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ - (void)findInPagePreviousMatch
204204
m_web_view_bridge->find_in_page_previous_match();
205205
}
206206

207+
- (void)requestClose
208+
{
209+
m_web_view_bridge->request_close();
210+
}
211+
207212
#pragma mark - Private methods
208213

209214
- (void)updateViewportRect

UI/AppKit/Interface/TabController.mm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ @interface TabController () <NSToolbarDelegate, NSSearchFieldDelegate, Autocompl
5555
OwnPtr<WebView::Autocomplete> m_autocomplete;
5656
}
5757

58+
@property (nonatomic, assign) BOOL already_requested_close;
59+
5860
@property (nonatomic, strong) Tab* parent;
5961

6062
@property (nonatomic, strong) NSToolbar* toolbar;
@@ -397,6 +399,21 @@ - (void)windowDidBecomeMain:(NSNotification*)notification
397399
[delegate setActiveTab:[self tab]];
398400
}
399401

402+
- (BOOL)windowShouldClose:(NSWindow*)sender
403+
{
404+
// Prevent closing on first request so WebContent can cleanly shutdown (e.g. asking if the user is sure they want
405+
// to leave, closing WebSocket connections, etc.)
406+
if (!self.already_requested_close) {
407+
self.already_requested_close = true;
408+
[[[self tab] web_view] requestClose];
409+
return false;
410+
}
411+
412+
// If the user has already requested a close, then respect the user's request and just close the tab.
413+
// For example, the WebContent process may not be responding.
414+
return true;
415+
}
416+
400417
- (void)windowWillClose:(NSNotification*)notification
401418
{
402419
auto* delegate = (ApplicationDelegate*)[NSApp delegate];

0 commit comments

Comments
 (0)