Skip to content

Commit 0328ac3

Browse files
committed
Electron preload scaffolding
1 parent bcdaec9 commit 0328ac3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/packager/electron-preload.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {contextBridge} = require('electron')
2+
3+
contextBridge.exposeInMainWorld('ExampleAPI', {
4+
doSomething: () => {
5+
return 'Hello!';
6+
}
7+
});

src/packager/packager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {APP_NAME, WEBSITE, COPYRIGHT_NOTICE, ACCENT_COLOR} from './brand';
1111
import {OutdatedPackagerError} from '../common/errors';
1212
import {darken} from './colors';
1313
import {Adapter} from './adapter';
14+
import electronPreloadJS from '!raw-loader!./electron-preload.js';
1415

1516
const PROGRESS_LOADED_SCRIPTS = 0.1;
1617

@@ -512,6 +513,7 @@ cd "$(dirname "$0")"
512513
const contentsPrefix = isMac ? `${rootPrefix}${packageName}.app/Contents/` : rootPrefix;
513514
const resourcesPrefix = isMac ? `${contentsPrefix}Resources/app/` : `${contentsPrefix}resources/app/`;
514515
const electronMainName = 'electron-main.js';
516+
const electronPreloadName = 'electron-preload.js';
515517
const iconName = 'icon.png';
516518

517519
const icon = await Adapter.getAppIcon(this.options.app.icon);
@@ -558,6 +560,7 @@ const createWindow = (windowOptions) => {
558560
sandbox: true,
559561
contextIsolation: true,
560562
nodeIntegration: false,
563+
preload: path.resolve(__dirname, ${JSON.stringify(electronPreloadName)}),
561564
},
562565
show: true,
563566
width: 480,
@@ -697,6 +700,7 @@ app.whenReady().then(() => {
697700
});
698701
`;
699702
zip.file(`${resourcesPrefix}${electronMainName}`, mainJS);
703+
zip.file(`${resourcesPrefix}${electronPreloadName}`, electronPreloadJS);
700704

701705
for (const [path, data] of Object.entries(projectZip.files)) {
702706
setFileFast(zip, `${resourcesPrefix}${path}`, data);

0 commit comments

Comments
 (0)