mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 16:19:17 +03:00
Call window.shutdown when native window is closed
The root view will now be serialized and saved to local storage when the window is closed or the application is terminated.
This commit is contained in:
parent
b3ce062be9
commit
8c0f443c75
@ -168,6 +168,11 @@
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)notification {
|
||||
NSInteger windowCount = [[self windows] count];
|
||||
for(int i = 0; i < windowCount; i++) {
|
||||
NSWindow *window = [[self windows] objectAtIndex:i];
|
||||
[window performClose:0];
|
||||
}
|
||||
CefShutdown();
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,8 @@ class AtomCefRenderProcessHandler : public CefRenderProcessHandler {
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
||||
|
||||
|
||||
|
||||
void Reload(CefRefPtr<CefBrowser> browser);
|
||||
void Shutdown(CefRefPtr<CefBrowser> browser);
|
||||
bool CallMessageReceivedHandler(CefRefPtr<CefV8Context> context, CefRefPtr<CefProcessMessage> message);
|
||||
|
||||
IMPLEMENT_REFCOUNTING(AtomCefRenderProcessHandler);
|
||||
|
@ -27,6 +27,10 @@ bool AtomCefRenderProcessHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser>
|
||||
Reload(browser);
|
||||
return true;
|
||||
}
|
||||
else if (name == "shutdown") {
|
||||
Shutdown(browser);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return CallMessageReceivedHandler(browser->GetMainFrame()->GetV8Context(), message);
|
||||
}
|
||||
@ -47,6 +51,17 @@ void AtomCefRenderProcessHandler::Reload(CefRefPtr<CefBrowser> browser) {
|
||||
context->Exit();
|
||||
}
|
||||
|
||||
void AtomCefRenderProcessHandler::Shutdown(CefRefPtr<CefBrowser> browser) {
|
||||
CefRefPtr<CefV8Context> context = browser->GetMainFrame()->GetV8Context();
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
context->Enter();
|
||||
CefV8ValueList arguments;
|
||||
CefRefPtr<CefV8Value> shutdownFunction = global->GetValue("shutdown");
|
||||
shutdownFunction->ExecuteFunction(global, arguments);
|
||||
context->Exit();
|
||||
}
|
||||
|
||||
bool AtomCefRenderProcessHandler::CallMessageReceivedHandler(CefRefPtr<CefV8Context> context, CefRefPtr<CefProcessMessage> message) {
|
||||
context->Enter();
|
||||
|
||||
|
@ -143,8 +143,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)windowShouldClose:(id)window {
|
||||
- (void)windowWillClose:(NSNotification *)notification {
|
||||
if (_cefClient && _cefClient->GetBrowser()) {
|
||||
_cefClient->GetBrowser()->SendProcessMessage(PID_RENDERER, CefProcessMessage::Create("shutdown"));
|
||||
}
|
||||
[self autorelease];
|
||||
}
|
||||
|
||||
- (BOOL)windowShouldClose:(id)window {
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user