检测是否有其他Chrome应用正在运行

时间:2016-06-15 16:09:41

标签: javascript google-chrome-extension google-chrome-app

我有一个Chrome扩展程序和一个Chrome应用程序,它可以通过消息传递相互通信。我希望扩展程序仅在Chrome应用未运行时执行某些操作。鉴于Chrome应用的ID,我如何从Chrome扩展程序中检测到它是否正在运行?

我尝试使用Chrome应用程序中的关闭和暂停生命周期事件来协助,但由于各种原因,这条路线似乎不可能。还有其他方法可以检测吗?

2 个答案:

答案 0 :(得分:0)

好吧,你已经在使用Messaging了,所以即使你的应用程序没有启动,假设App的活动页面也会被唤醒以回答你的问题。

你定义"运行"打开窗户。在活动页面中,您可以check that

chrome.runtime.onMessageExternal.addListener(function(message, sender, sendResponse) {
    /* ... */
    if (chrome.app.window.getAll().length) {
      // Launched
    } else {
      // Not launched
    }
});

答案 1 :(得分:-1)

类似的东西:

chrome.management.get(appId,function(theapp){
    if(theapp.enabled){
        // it is running
    } else {
        // it is not running
    }
});