【问题标题】:How to close Electron app via TypeScript?如何通过 TypeScript 关闭 Electron 应用程序?
【发布时间】:2019-07-23 21:36:42
【问题描述】:

我正在尝试找到关闭 Electron 应用程序的正确方法。我在应用程序中使用 React 和 TypeScript。我找到了this post 并找到了一种可行的方法:

const remote = require('electron').remote;
let w = remote.getCurrentWindow();
w.close();

但是,TSLint 现在告诉我 require() 样式导入是被禁止的。有没有更简洁的方法来关闭 Electron 应用?

【问题讨论】:

  • 关于做类似的旧帖子(虽然有错别字) - stackoverflow.com/questions/43314039/…
  • tslint 可以重新配置...和 ​​tslint != typescript
  • @trebleCode 你发的链接和我发的链接一样。
  • @smnbbrv 换句话说,我发布的代码示例是关闭 Electron 应用程序的正确方法吗?我必须在 TSLint 中重新配置什么?

标签: typescript electron tslint


【解决方案1】:

在 TypeScript 中一个更好的方法是避免 require()。因此,与其像您那样需要 Electron,不如在导入部分中导入 remote,然后访问远程变量。现在 TSLint 应该又高兴了。

import { remote } from 'electron';

...

private closeWindow() {
    remote.getCurrentWindow().close();
}

【讨论】:

    猜你喜欢
    • 2021-09-29
    • 2022-01-12
    • 2017-09-04
    • 2022-07-11
    • 2013-06-06
    • 2020-05-08
    • 2019-02-05
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多