Electron.IpcMain.Send and Arrays (in Electron.Net Api Demos) #317

Closed
opened 2026-01-29 16:36:20 +00:00 by claunia · 1 comment
Owner

Originally created by @KinNeko-De on GitHub (May 20, 2019).

Hello,
i am new to Electron.Net and have a question. I am not very familar with javascript btw.

I used the Electron.Net Api Demos to open a file dialog that allows multiple selection.
I nearly copied everything from DialogsController.

string[] files = await Electron.Dialog.ShowOpenDialogAsync(mainWindow, options); Electron.IpcMain.Send(mainWindow, "select-directory-reply", files);

files is an array.
I expected to get an array on the javascript side too.
But i only get a string. The related javascript code in the example expect only a single path.

The code in IpcMain goes over the array and creates multiple objects.
I think it was designed to do so. Right?

After i debugged the IpcMain code i decide to use :
'Electron.IpcMain.Send(mainWindow, "select-directory-reply", new object[] { files });'

Is that the simplest solution or do i miss something?
Should the example be edited to make it clearer how parameters should be passed?

Originally created by @KinNeko-De on GitHub (May 20, 2019). Hello, i am new to Electron.Net and have a question. I am not very familar with javascript btw. I used the _Electron.Net Api Demos_ to open a file dialog that allows multiple selection. I nearly copied everything from _DialogsController_. `string[] files = await Electron.Dialog.ShowOpenDialogAsync(mainWindow, options); Electron.IpcMain.Send(mainWindow, "select-directory-reply", files);` _**files**_ is an array. I expected to get an array on the javascript side too. But i only get a string. The related javascript code in the example expect only a single path. The code in IpcMain goes over the array and creates multiple objects. I think it was designed to do so. Right? After i debugged the IpcMain code i decide to use : 'Electron.IpcMain.Send(mainWindow, "select-directory-reply", new object[] { files });' Is that the simplest solution or do i miss something? Should the example be edited to make it clearer how parameters should be passed?
Author
Owner

@netpoetica commented on GitHub (May 28, 2019):

Are you able to use the JS inspector/dev tools and provide exactly what your run-time JS object looks like?

I suspect you might want to use JSON.Serialize on your files array in order to send JSON to the front-end, and then use JSON.parse(files) in your JavaScript to get an array instead of a string.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

@netpoetica commented on GitHub (May 28, 2019): Are you able to use the JS inspector/dev tools and provide exactly what your run-time JS object looks like? I suspect you might want to use JSON.Serialize on your files array in order to send JSON to the front-end, and then use JSON.parse(files) in your JavaScript to get an array instead of a string. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#317