fix: crashed events deprecation (#40090)
This commit is contained in:
parent
3392d9a2e7
commit
83a928f6e3
4 changed files with 15 additions and 13 deletions
|
@ -114,5 +114,11 @@ for (const name of events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecation.
|
// Deprecation.
|
||||||
deprecate.event(app, 'gpu-process-crashed', 'child-process-gone');
|
deprecate.event(app, 'gpu-process-crashed', 'child-process-gone', () => {
|
||||||
deprecate.event(app, 'renderer-process-crashed', 'render-process-gone');
|
// the old event is still emitted by App::OnGpuProcessCrashed()
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
deprecate.event(app, 'renderer-process-crashed', 'render-process-gone', (event: Electron.Event, webContents: Electron.WebContents, details: Electron.RenderProcessGoneDetails) => {
|
||||||
|
return [event, webContents, details.reason === 'killed'];
|
||||||
|
});
|
||||||
|
|
|
@ -665,8 +665,8 @@ WebContents.prototype._init = function () {
|
||||||
ipcMain.emit(channel, event, message);
|
ipcMain.emit(channel, event, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on('crashed', (event, ...args) => {
|
deprecate.event(this, 'crashed', 'render-process-gone', (event: Electron.Event, details: Electron.RenderProcessGoneDetails) => {
|
||||||
app.emit('renderer-process-crashed', event, this, ...args);
|
return [event, details.reason === 'killed'];
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on('render-process-gone', (event, details) => {
|
this.on('render-process-gone', (event, details) => {
|
||||||
|
|
|
@ -66,14 +66,17 @@ export function renameFunction<T extends Function> (fn: T, newName: string): T {
|
||||||
}
|
}
|
||||||
|
|
||||||
// change the name of an event
|
// change the name of an event
|
||||||
export function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string) {
|
export function event (emitter: NodeJS.EventEmitter, oldName: string, newName: string, transformer: (...args: any[]) => any[] | undefined = (...args) => args) {
|
||||||
const warn = newName.startsWith('-') /* internal event */
|
const warn = newName.startsWith('-') /* internal event */
|
||||||
? warnOnce(`${oldName} event`)
|
? warnOnce(`${oldName} event`)
|
||||||
: warnOnce(`${oldName} event`, `${newName} event`);
|
: warnOnce(`${oldName} event`, `${newName} event`);
|
||||||
return emitter.on(newName, function (this: NodeJS.EventEmitter, ...args) {
|
return emitter.on(newName, function (this: NodeJS.EventEmitter, ...args) {
|
||||||
if (this.listenerCount(oldName) !== 0) {
|
if (this.listenerCount(oldName) !== 0) {
|
||||||
warn();
|
warn();
|
||||||
this.emit(oldName, ...args);
|
const transformedArgs = transformer(...args);
|
||||||
|
if (transformedArgs) {
|
||||||
|
this.emit(oldName, ...transformedArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1729,13 +1729,6 @@ void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||||
|
|
||||||
void WebContents::PrimaryMainFrameRenderProcessGone(
|
void WebContents::PrimaryMainFrameRenderProcessGone(
|
||||||
base::TerminationStatus status) {
|
base::TerminationStatus status) {
|
||||||
auto weak_this = GetWeakPtr();
|
|
||||||
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
|
||||||
|
|
||||||
// User might destroy WebContents in the crashed event.
|
|
||||||
if (!weak_this || !web_contents())
|
|
||||||
return;
|
|
||||||
|
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
|
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||||
|
|
Loading…
Add table
Reference in a new issue