我正在尝试找到关闭Electron应用程序的正确方法。我在应用程序中使用了React和TypeScript。我找到了this post并找到了一种有效的方法:
const remote = require('electron').remote;
let w = remote.getCurrentWindow();
w.close();
但是,TSLint现在告诉我,禁止使用require()
样式。有没有更清洁的方法来关闭Electron应用程序?
在TypeScript中更好的方法是避免使用require()
。因此,不要像你那样需要Electron,而是在导入部分中更好地导入remote
,然后访问远程变量。现在TSLint应该再次开心。
import { remote } from 'electron';
...
private closeWindow() {
remote.getCurrentWindow().close();
}