2020-01-21 17:42:55 +00:00
|
|
|
// This is a temporary shim to aid in transition from the old
|
|
|
|
// BrowserWindow-based extensions stuff to the new native-backed extensions
|
|
|
|
// API.
|
|
|
|
|
2020-06-30 19:49:08 +00:00
|
|
|
import { app, session, BrowserWindow, deprecate } from 'electron';
|
2020-01-21 17:42:55 +00:00
|
|
|
|
2020-02-03 22:43:22 +00:00
|
|
|
app.whenReady().then(function () {
|
2020-06-30 19:49:08 +00:00
|
|
|
const addExtension = function (srcDirectory: string) {
|
2020-03-20 20:28:31 +00:00
|
|
|
return session.defaultSession.loadExtension(srcDirectory);
|
|
|
|
};
|
2020-01-21 17:42:55 +00:00
|
|
|
|
2020-06-30 19:49:08 +00:00
|
|
|
const removeExtension = function (name: string) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const extension = session.defaultSession.getAllExtensions().find(e => e.name === name);
|
|
|
|
if (extension) { session.defaultSession.removeExtension(extension.id); }
|
|
|
|
};
|
2020-01-21 17:42:55 +00:00
|
|
|
|
|
|
|
const getExtensions = function () {
|
2020-06-30 19:49:08 +00:00
|
|
|
const extensions: Record<string, any> = {};
|
2020-01-21 17:42:55 +00:00
|
|
|
session.defaultSession.getAllExtensions().forEach(e => {
|
2020-03-20 20:28:31 +00:00
|
|
|
extensions[e.name] = e;
|
|
|
|
});
|
|
|
|
return extensions;
|
|
|
|
};
|
2020-01-21 17:42:55 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
BrowserWindow.addExtension = deprecate.moveAPI(addExtension, 'BrowserWindow.addExtension', 'session.loadExtension');
|
|
|
|
BrowserWindow.removeExtension = deprecate.moveAPI(removeExtension, 'BrowserWindow.removeExtension', 'session.removeExtension');
|
|
|
|
BrowserWindow.getExtensions = deprecate.moveAPI(getExtensions, 'BrowserWindow.getExtensions', 'session.getAllExtensions');
|
|
|
|
BrowserWindow.addDevToolsExtension = deprecate.moveAPI(addExtension, 'BrowserWindow.addDevToolsExtension', 'session.loadExtension');
|
|
|
|
BrowserWindow.removeDevToolsExtension = deprecate.moveAPI(removeExtension, 'BrowserWindow.removeDevToolsExtension', 'session.removeExtension');
|
|
|
|
BrowserWindow.getDevToolsExtensions = deprecate.moveAPI(getExtensions, 'BrowserWindow.getDevToolsExtensions', 'session.getAllExtensions');
|
|
|
|
});
|