Skip to content

Commit 24f3061

Browse files
committed
Fix nwjs#6677: nw.App.closeAllWindows() crashes on Mac OSX
1 parent 1054dd9 commit 24f3061

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/api/nw_app_api.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,25 @@ NwAppQuitFunction::Run() {
6060
return RespondNow(NoArguments());
6161
}
6262

63-
ExtensionFunction::ResponseAction
64-
NwAppCloseAllWindowsFunction::Run() {
65-
AppWindowRegistry* registry = AppWindowRegistry::Get(browser_context());
66-
if (!registry)
67-
return RespondNow(Error(""));
68-
63+
void NwAppCloseAllWindowsFunction::DoJob(AppWindowRegistry* registry, std::string id) {
6964
AppWindowRegistry::AppWindowList windows =
70-
registry->GetAppWindowsForApp(extension()->id());
65+
registry->GetAppWindowsForApp(id);
7166

7267
for (AppWindow* window : windows) {
7368
if (window->NWCanClose())
7469
window->GetBaseWindow()->Close();
7570
}
71+
}
72+
73+
ExtensionFunction::ResponseAction
74+
NwAppCloseAllWindowsFunction::Run() {
75+
AppWindowRegistry* registry = AppWindowRegistry::Get(browser_context());
76+
if (!registry)
77+
return RespondNow(Error(""));
78+
base::MessageLoop::current()->task_runner()->PostTask(
79+
FROM_HERE,
80+
base::Bind(&NwAppCloseAllWindowsFunction::DoJob, registry, extension()->id()));
81+
7682
return RespondNow(NoArguments());
7783
}
7884

src/api/nw_app_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "extensions/browser/extension_function.h"
99

1010
namespace extensions {
11+
class AppWindowRegistry;
1112

1213
class NwAppQuitFunction : public UIThreadExtensionFunction {
1314
public:
@@ -27,6 +28,7 @@ class NwAppCloseAllWindowsFunction : public UIThreadExtensionFunction {
2728
public:
2829
NwAppCloseAllWindowsFunction() {}
2930

31+
static void DoJob(AppWindowRegistry* registry, std::string id);
3032
protected:
3133
~NwAppCloseAllWindowsFunction() override {}
3234

0 commit comments

Comments
 (0)