mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-03 21:25:13 +00:00
Electron.IpcMain.Send and Arrays (in Electron.Net Api Demos) #317
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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?
@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