----
*https://www.electronjs.org/docs/api/dialog
contextBridge を使用してファイル選択ダイアログを表示する
*main.js
<pre>
const { ipcMain, dialog } = require('electron');
ipcMain.handle('open-file-dialog', async (ev, msg) => {
var result = await dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'] });
if (result.canceld) {
return [];
}
return result.filePaths;
});
</pre>
*preload.js
<pre>
const electron = require('electron');
const { ipcRenderer, contextBridge } = electron;
contextBridge.exposeInMainWorld(
"api",
{
openFileDialog: (message) => {
return ipcRenderer.invoke('open-file-dialog', message);
}
}
);
</pre>
*index.html
<pre>
async function openWinFileDialog() {
var filePaths = await window.api.openFileDialog("");
alert(filePaths[0]);
}
</pre>
==構成==