feat: add query-session-end and improve session-end events on Windows (#44598)

* feat: add query-session-end event for Windows

* fix: remove debug line

* feat: notify with reason on session-end

* docs: add comments and return params

* docs: add same docs to the BrowserWindow

* fix: add shutdown reason if lParam == 0

* docs: remove 'force' word

* docs: revert multithreading.md change

* docs: add reasons documentation, reason variable renamed to reasons

* docs: improve 'shutdown' reason wording

* docs: reword with 'can be'

* fix: pass reasons by reference

* fix: use newer approach which expose reasons value directly on Event object

* docs: add escaping

* style: linter fixes

* fix: project now should compile

* fix: EmitWithoutEvent method added, EmitWithEvent moved to private again

* docs: typo fix

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* docs: dedicated WindowSessionEndEvent type created

* docs: better wording for session-end event description

Co-authored-by: Will Anderson <will@itsananderson.com>

---------

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>
Co-authored-by: Will Anderson <will@itsananderson.com>
This commit is contained in:
Savely Krasovsky 2024-11-22 20:47:36 +01:00 committed by GitHub
parent 0285592d61
commit c5ea177b3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 135 additions and 12 deletions

View file

@ -177,8 +177,37 @@ void BaseWindow::OnWindowClosed() {
FROM_HERE, GetDestroyClosure());
}
void BaseWindow::OnWindowEndSession() {
Emit("session-end");
void BaseWindow::OnWindowQueryEndSession(
const std::vector<std::string>& reasons,
bool* prevent_default) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
gin::Handle<gin_helper::internal::Event> event =
gin_helper::internal::Event::New(isolate);
v8::Local<v8::Object> event_object = event.ToV8().As<v8::Object>();
gin::Dictionary dict(isolate, event_object);
dict.Set("reasons", reasons);
EmitWithoutEvent("query-session-end", event);
if (event->GetDefaultPrevented()) {
*prevent_default = true;
}
}
void BaseWindow::OnWindowEndSession(const std::vector<std::string>& reasons) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
gin::Handle<gin_helper::internal::Event> event =
gin_helper::internal::Event::New(isolate);
v8::Local<v8::Object> event_object = event.ToV8().As<v8::Object>();
gin::Dictionary dict(isolate, event_object);
dict.Set("reasons", reasons);
EmitWithoutEvent("session-end", event);
}
void BaseWindow::OnWindowBlur() {