在 Electron 中,有没有一种方法可以在调用dialog.showSaveDialog
的过程中获得当前聚焦的窗口?从dialog.showOpenDialog
内可以正常工作,但从null
内完成后返回dialog.showSaveDialog
。
这有效:
dialog.showOpenDialog(function (filepaths) {
if(filepaths !== undefined){
BrowserWindow.getFocusedWindow().send('file-open', filepaths[0])
}
});
这会抛出
TypeError: Cannot read property 'send' of null
:dialog.showSaveDialog(options, function (filepath) {
if (filepath !== undefined) {
BrowserWindow.getFocusedWindow().send('file-save', filepath)
}
});
最佳答案
通过将代码更改为以下内容来解决此问题:
const activeWindow = BrowserWindow.getFocusedWindow()
dialog.showSaveDialog(options, function (filepath) {
if (filepath !== undefined) {
activeWindow.send('file-save', filepath)
}
});
仍然对为什么有人有一个为什么它不起作用的答案仍然很感兴趣。
关于file - 在 Electron 版本中,当从dialog.showSaveDialog调用时,BrowserWindow.getFocusedWindow返回null。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40638518/