现在正在开发一个电子应用程序。 我需要本地上传文件的功能,我正在尝试 showOpenDialog()。单击上传按钮,按预期打开文件选择器,但终端中显示错误:
[4801:0205/172224.193666:错误:browser_main_loop.cc(276)] GLib-GObject:从“GtkFileChooserNative”到“GtkWidget”的转换无效
选择文件会引发另一个错误:
[4801:0205/172226.571068:错误:browser_main_loop.cc(276)] GLib-GObject:../glib/gobject/gsignal.c:2777:实例'0x12b000ac7bf0'没有ID为'3139'的处理程序
这是我的 main.js 中的代码:
ipcMain.handle('gallery-add-files', (e) => {
var files = dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
properties:[
'openFile',
'multiSelections'
]
}, function(files){
console.log(files)
});
})
我正在使用 arch,我认为这是相关的,因为之前这个错误还显示了一些错误,但安装“xdg-desktop-portal”和“xdg-desktop-portal-gtk”解决了这些问题。
ipcMain.handle('gallery-add-files', async (e) => {
try {
const { canceled, filePaths } = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
properties: ['openFile', 'multiSelections']
});
if (!canceled) {
console.log(filePaths);
// Process the selected files
}
} catch (error) {
console.error('Failed to open dialog:', error);
}
});