File 在electron中,从dialog.showSaveDialog调用BrowserWindow.getFocusedWindow时返回null
在electron中,在调用File 在electron中,从dialog.showSaveDialog调用BrowserWindow.getFocusedWindow时返回null,file,dialog,focus,electron,File,Dialog,Focus,Electron,在electron中,在调用dialog.showsavedilog期间,是否有方法获取当前聚焦窗口?这在对话框.showOpenDialog中工作正常,但在对话框.showSaveDialog中执行时返回null 这项工作: dialog.showOpenDialog(function (filepaths) { if(filepaths !== undefined){ BrowserWindow.getFocusedWindow().send('file-open',
dialog.showsavedilog
期间,是否有方法获取当前聚焦窗口?这在对话框.showOpenDialog
中工作正常,但在对话框.showSaveDialog
中执行时返回null
这项工作:
dialog.showOpenDialog(function (filepaths) {
if(filepaths !== undefined){
BrowserWindow.getFocusedWindow().send('file-open', filepaths[0])
}
});
这将抛出类型错误:无法读取null的属性“send”:
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)
}
});
仍然对一个答案感兴趣,如果有人有一个,为什么它不起作用