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

Framework functions receive arguments boxed twice in an Array #214

Open
goffioul opened this issue Nov 3, 2021 · 1 comment
Open

Framework functions receive arguments boxed twice in an Array #214

goffioul opened this issue Nov 3, 2021 · 1 comment

Comments

@goffioul
Copy link

goffioul commented Nov 3, 2021

I'm not sure this is intentional or not, but I don't see the reason for the arguments to be boxed twice in an array when reaching the main process of a framework plugin/element. That is:

  • cordova.exec transfers the array of argument to _cdvElectronIpc, which in turns send the array to the main process
  • the cdv-plugin-exec handler uses vararg for the last argument, which basically boxes the argument into another array
  • the framework function receives a single argument, which is then an array or arrays

Is this intentional?

@fabiofabbri84
Copy link

Hi, I noticed the same as I was working on upgrading an app from cordova-electron 1.x to 3.x

With 1.x I was able to access the main process using the options nodeIntegration = true and contextIsolation = false in browserWindow.webPreferences, but as this is not supported anymore in cordova-electron 3.x, I deep dived into the code to understand how it works and how can I create a plugin that runs in the main process.

I'm going to fork cordova-electron to try to this, and also to call the framework function with parameters (succes, fail, args) to make it more similar to "browser" platform and address the fact that if you have to run the error function, Electron returns a string wrapped in an Error object.

fabiofabbri84 added a commit to cimatti/cordova-electron that referenced this issue Jul 6, 2022
…cdv-plugin-exec

The main goal was to allow passing to the error callback an unaltered copy of the argument, as with the previous implementation you have to throw an exception or return a rejected promise, and this is forwarded to the ipcRenderer.invoke as a string encapsulated in an Error object. See electron/electron#24427

Moreover, with the previous implementation, args for the action were encapsulated twice in an Array ( see apache#214 ). To make it more coherent with Cordova standards, and to allow backward support easily with a simple check, the first and the second arguments are success and error functions, and the third argument is the args array. So if the first argument is a function, we are using this cordova-electron~4 proposal, otherwise we are using cordova-electron~3, and it is the "arguments" array.

Finally, _cdvElectronIPC.exec checks if success and error parameters are actually functions before calling them, in order to avoid annoying error log messages if they were not defined.
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

No branches or pull requests

2 participants