refactor: move extension APIs to session.extensions (#45597)

refactor: move extensions to session.extensions
This commit is contained in:
Sam Maddock 2025-02-21 18:36:51 -05:00 committed by GitHub
parent a63f6143ea
commit e3f61b465d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 508 additions and 205 deletions

View file

@ -24,6 +24,21 @@ Object.freeze(systemPickerVideoSource);
Session.prototype._init = function () {
addIpcDispatchListeners(this);
if (this.extensions) {
const rerouteExtensionEvent = (eventName: string) => {
const warn = deprecate.warnOnce(`${eventName} event`, `session.extensions ${eventName} event`);
this.extensions.on(eventName as any, (...args: any[]) => {
if (this.listenerCount(eventName) !== 0) {
warn();
this.emit(eventName, ...args);
}
});
};
rerouteExtensionEvent('extension-loaded');
rerouteExtensionEvent('extension-unloaded');
rerouteExtensionEvent('extension-ready');
}
};
Session.prototype.fetch = function (input: RequestInfo, init?: RequestInit) {
@ -67,6 +82,35 @@ Session.prototype.setPreloads = function (preloads) {
});
};
Session.prototype.getAllExtensions = deprecate.moveAPI(
function (this: Electron.Session) {
return this.extensions.getAllExtensions();
},
'session.getAllExtensions',
'session.extensions.getAllExtensions'
);
Session.prototype.getExtension = deprecate.moveAPI(
function (this: Electron.Session, extensionId) {
return this.extensions.getExtension(extensionId);
},
'session.getExtension',
'session.extensions.getExtension'
);
Session.prototype.loadExtension = deprecate.moveAPI(
function (this: Electron.Session, path, options) {
return this.extensions.loadExtension(path, options);
},
'session.loadExtension',
'session.extensions.loadExtension'
);
Session.prototype.removeExtension = deprecate.moveAPI(
function (this: Electron.Session, extensionId) {
return this.extensions.removeExtension(extensionId);
},
'session.removeExtension',
'session.extensions.removeExtension'
);
export default {
fromPartition,
fromPath,