Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support electron main.js injection #768

Merged
merged 2 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/rnv-engine-rn-electron/src/sdks/sdk-electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ const configureProject = c => new Promise((resolve, reject) => {
browserWindow = merge(browserWindow, browserWindowExt);
}
const browserWindowStr = JSON.stringify(browserWindow, null, 2);

const electronConfigExt = getConfigProp(c, platform, 'electronConfig');
const mainInjection = electronConfigExt?.mainInjection || '';

if (bundleAssets) {
const injects = [
Expand All @@ -144,6 +145,10 @@ const configureProject = c => new Promise((resolve, reject) => {
{
pattern: '{{PLUGIN_INJECT_ICON_LOCATION}}',
override: browserWindow.icon
},
{
pattern: '{{PLUGIN_INJECT_MAIN_PROCESS}}',
override: mainInjection
}
];

Expand All @@ -167,6 +172,10 @@ const configureProject = c => new Promise((resolve, reject) => {
{
pattern: '{{PLUGIN_INJECT_ICON_LOCATION}}',
override: browserWindow.icon
},
{
pattern: '{{PLUGIN_INJECT_MAIN_PROCESS}}',
override: mainInjection
}
];

Expand Down Expand Up @@ -216,9 +225,8 @@ const configureProject = c => new Promise((resolve, reject) => {
macConfig
);

const electronConfigExt = getConfigProp(c, platform, 'electronConfig');

if (electronConfigExt) {
delete electronConfigExt.mainInjection;
electronConfig = merge(electronConfig, electronConfigExt);
}
writeFileSync(electronConfigPath, electronConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ if (isMacos) {
app.dock.setIcon(image);
}

{{PLUGIN_INJECT_MAIN_PROCESS}}
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ if (isMacos) {
const image = nativeImage.createFromPath("{{PLUGIN_INJECT_ICON_LOCATION}}");
app.dock.setIcon(image);
}

{{PLUGIN_INJECT_MAIN_PROCESS}}
1 change: 1 addition & 0 deletions packages/rnv/src/core/schemaManager/schemaRenativeJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const engineRnElectronConfig = {
type: 'distribution',
hardenedRuntime: false,
},
mainInjection: 'console.log("Hello from main.js!");',
},
],
},
Expand Down