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

Change native code execution to use async ipcRenderer.invoke #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Inrixia
Copy link
Contributor

@Inrixia Inrixia commented Oct 17, 2024

As stated this changes the invoke calls to use async and will require build scripts to be changed to use:

return {
	contents: `
	import { addUnloadable } from "@plugin";
	const scopeId = await NeptuneNative.createEvalScope(${JSON.stringify(outputCode)}, "${globalName}");
	${builtExports.reduce((exports, exp) => (exports += `export ${exp == "default" ? "default " : `const ${exp} =`} (...args) => NeptuneNative.invokeEvalScope(scopeId, "${exp}", ...args);`), "")}
	addUnloadable(() => NeptuneNative.deleteEvalScope(scopeId))`,
};

I looked into identifying the calling function constructor to determine if the response was async or not. But there is no safe way to determine this as a synchronous function can return a promise.

Since all calls to the native side should be async anyway re the official electron docs and general best practises:
image

As this results in exported native methods needing to return promises docs should reflect the need to use async methods.

Switching to invoke fixes issues with serialization and performance especially on initial load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant