feat: redesign preload APIs (#45329)
* feat: redesign preload APIs Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * docs: remove service-worker mentions for now Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * fix lint Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * remove service-worker ipc code Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * add filename Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * fix: web preferences preload not included Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * fix: missing common init Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * fix: preload bundle script error Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com>
This commit is contained in:
parent
e9b3e4cc91
commit
9d696ceffe
19 changed files with 459 additions and 149 deletions
|
@ -1,4 +1,5 @@
|
|||
import { fetchWithSession } from '@electron/internal/browser/api/net-fetch';
|
||||
import * as deprecate from '@electron/internal/common/deprecate';
|
||||
|
||||
import { net } from 'electron/main';
|
||||
|
||||
|
@ -36,6 +37,31 @@ Session.prototype.setDisplayMediaRequestHandler = function (handler, opts) {
|
|||
}, opts);
|
||||
};
|
||||
|
||||
const getPreloadsDeprecated = deprecate.warnOnce('session.getPreloads', 'session.getPreloadScripts');
|
||||
Session.prototype.getPreloads = function () {
|
||||
getPreloadsDeprecated();
|
||||
return this.getPreloadScripts()
|
||||
.filter((script) => script.type === 'frame')
|
||||
.map((script) => script.filePath);
|
||||
};
|
||||
|
||||
const setPreloadsDeprecated = deprecate.warnOnce('session.setPreloads', 'session.registerPreloadScript');
|
||||
Session.prototype.setPreloads = function (preloads) {
|
||||
setPreloadsDeprecated();
|
||||
this.getPreloadScripts()
|
||||
.filter((script) => script.type === 'frame')
|
||||
.forEach((script) => {
|
||||
this.unregisterPreloadScript(script.id);
|
||||
});
|
||||
preloads.map(filePath => ({
|
||||
type: 'frame',
|
||||
filePath,
|
||||
_deprecated: true
|
||||
}) as Electron.PreloadScriptRegistration).forEach(script => {
|
||||
this.registerPreloadScript(script);
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
fromPartition,
|
||||
fromPath,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue