Skip to content

Commit

Permalink
Electron preload scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jun 30, 2023
1 parent bcdaec9 commit 0328ac3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/packager/electron-preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const {contextBridge} = require('electron')

contextBridge.exposeInMainWorld('ExampleAPI', {
doSomething: () => {
return 'Hello!';
}
});
4 changes: 4 additions & 0 deletions src/packager/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {APP_NAME, WEBSITE, COPYRIGHT_NOTICE, ACCENT_COLOR} from './brand';
import {OutdatedPackagerError} from '../common/errors';
import {darken} from './colors';
import {Adapter} from './adapter';
import electronPreloadJS from '!raw-loader!./electron-preload.js';

const PROGRESS_LOADED_SCRIPTS = 0.1;

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

const icon = await Adapter.getAppIcon(this.options.app.icon);
Expand Down Expand Up @@ -558,6 +560,7 @@ const createWindow = (windowOptions) => {
sandbox: true,
contextIsolation: true,
nodeIntegration: false,
preload: path.resolve(__dirname, ${JSON.stringify(electronPreloadName)}),
},
show: true,
width: 480,
Expand Down Expand Up @@ -697,6 +700,7 @@ app.whenReady().then(() => {
});
`;
zip.file(`${resourcesPrefix}${electronMainName}`, mainJS);
zip.file(`${resourcesPrefix}${electronPreloadName}`, electronPreloadJS);

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

0 comments on commit 0328ac3

Please sign in to comment.