Skip to content

Commit e342d2c

Browse files
committed
Add a 'quit' parameter to 'close' event cb
On OSX, when user hit 'Cmd-Q', the close event is sent with a 'quit' parameter to distinguish with other cases for closing window Fix nwjs#430
1 parent a0de620 commit e342d2c

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/api/app/app.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ void App::Call(Shell* shell,
133133
}
134134

135135
// static
136-
void App::CloseAllWindows(bool force) {
136+
void App::CloseAllWindows(bool force, bool quit) {
137137
std::vector<Shell*> windows = Shell::windows();
138138

139139
for (size_t i = 0; i < windows.size(); ++i) {
140140
// Only send close event to browser windows, since devtools windows will
141141
// be automatically closed.
142142
if (!windows[i]->is_devtools()) {
143143
// If there is no js object bound to the window, then just close.
144-
if (force || windows[i]->ShouldCloseWindow())
144+
if (force || windows[i]->ShouldCloseWindow(quit))
145145
// we used to delete the Shell object here
146146
// but it should be deleted on native window destruction
147147
windows[i]->window()->Close();

src/api/app/app.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class App {
4747
base::ListValue* result);
4848

4949
// Try to close all windows (then will cause whole app to quit).
50-
static void CloseAllWindows(bool force = false);
50+
static void CloseAllWindows(bool force = false, bool quit = false);
5151

5252
// Quit the whole app.
5353
static void Quit(content::RenderProcessHost* rph = NULL);

src/browser/native_window_mac.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ @interface ShellNSWindow : ChromeEventProcessingWindow {
235235
}
236236
- (void)setShell:(const base::WeakPtr<content::Shell>&)shell;
237237
- (void)showDevTools:(id)sender;
238-
- (void)closeAllWindows:(id)sender;
238+
- (void)closeAllWindowsQuit:(id)sender;
239239
@end
240240

241241
@implementation ShellNSWindow
@@ -249,8 +249,8 @@ - (void)showDevTools:(id)sender {
249249
shell_->ShowDevTools();
250250
}
251251

252-
- (void)closeAllWindows:(id)sender {
253-
nwapi::App::CloseAllWindows();
252+
- (void)closeAllWindowsQuit:(id)sender {
253+
nwapi::App::CloseAllWindows(false, true);
254254
}
255255

256256
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen

src/browser/standard_menus_mac.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ - (void)setAppleMenu:(NSMenu *)menu;
7171
[appleMenu addItem:[NSMenuItem separatorItem]];
7272

7373
[appleMenu addItemWithTitle:l10n_util::GetNSStringFWithFixup(IDS_EXIT_MAC, name)
74-
action:@selector(closeAllWindows:)
74+
action:@selector(closeAllWindowsQuit:)
7575
keyEquivalent:@"q"];
7676

7777
// Add to menubar.

src/nw_shell.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ void Shell::SendEvent(const std::string& event, const base::ListValue& args) {
248248
web_contents->GetRoutingID(), id(), event, args));
249249
}
250250

251-
bool Shell::ShouldCloseWindow() {
251+
bool Shell::ShouldCloseWindow(bool quit) {
252252
if (id() < 0 || force_close_)
253253
return true;
254254

255-
SendEvent("close");
255+
SendEvent("close", quit ? "quit" : "");
256256
return false;
257257
}
258258

src/nw_shell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Shell : public WebContentsDelegate,
105105
void SendEvent(const std::string& event, const base::ListValue& args);
106106

107107
// Decide whether we should close the window.
108-
bool ShouldCloseWindow();
108+
bool ShouldCloseWindow(bool quit = false);
109109

110110
virtual GURL OverrideDOMStorageOrigin(const GURL& origin);
111111

0 commit comments

Comments
 (0)