【问题标题】:Stop Node Webkit from pausing on unfocus / when minimized停止 Node Webkit 在未聚焦/最小化时暂停
【发布时间】:2014-05-06 20:04:29
【问题描述】:

当我最小化窗口时,有没有办法让我的 Node-Webkit 应用程序不暂停?

我可以添加到 Package.json 中吗?

【问题讨论】:

  • 你看过 nohup 吗?在您的脚本块中,您可以在开头加上 nohup 前缀,例如 '"start": "nohup node ./bin/http-server"' (警告 - 尚未使用 node-webkit!)
  • 你能澄清一下当你最小化它时“暂停”是什么意思吗?您是在谈论播放音频还是其他一些事情?如果是后者,怎么判断是暂停了?
  • 我猜最小化应用程序不会暂停应用程序,但如果发生这种情况,您能否向我们提供一些有关您在问题中提到的暂停功能的详细信息。但只是为了检查,您也可以尝试最小化 window.hide() 以查看您的应用是否仍然暂停。
  • 我也有这种行为。当应用程序窗口 (nw.gui.Window.get()) 已使用 .hide() 隐藏时,似乎 setTimeout 和 setIntervals 会暂停。或者更确切地说,直到应用程序变为再次可见。

标签: javascript node.js node-webkit


【解决方案1】:

我认为为时已晚,但无论如何在 NodeWebkit 中有 2 个版本的 (setInterval/setTimeout) 函数: 1- window.setInterval/window.setTimeout (Chrome 版) 2- global.setInterval/global.setTimeout (NodeJs 版本)

NodeJS 版本将在后台运行,而 Chrome 版本将暂停,因为它意味着用于 UI 并且在您的情况下暂停它对您的应用程序更好,显然您应该通过使用 (global.设置间隔)

注意:如果您在某些内置模块中遇到此问题,您可以使用这个小技巧覆盖 chrome 版本:

// override chrome timing function with node js versions
this.setTimeout = window.setTimeout = global.setTimeout;
this.clearTimeout = window.clearTimeout = global.clearTimeout;
this.setInterval = window.setInterval = global.setInterval;
this.clearInterval = window.clearInterval = global.clearInterval;

干杯 ;)

【讨论】:

    猜你喜欢
    • 2013-12-01
    • 2019-07-04
    • 1970-01-01
    • 2016-07-25
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多