如何处理打包的Chrome应用中的选项? [英] How do I handle options in a packaged Chrome App?

查看:207
本文介绍了如何处理打包的Chrome应用中的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将现有的JS应用程序部署为Packaged Crome应用程序,以使其可在Chrome网上应用店中分发.

在旧版打包应用"中,曾经/曾经有一种方法可以指定一个options_ui页(在旧版旧版(旧版-旧版?)应用中,它是options_page),可以通过特殊链接进行访问通过您的应用,或通过chrome://extensions内部的自动链接.

关于如何迁移options_*功能似乎没有任何提及,但是如果Chrome应用程序的manifest.json具有options_ui键,则会在扩展程序页面上生成以下警告:

  • 'options_ui'仅适用于扩展程序和旧版打包的应用程序,但这是打包的应用程序.

(参考文献)

解决方案

您可以在图标上创建上下文菜单项以打开选项.

添加"contextMenus"权限,然后将以下内容添加到您的背景页面:

chrome.runtime.onInstalled.addListener(function() {
  chrome.contextMenus.create({ id: "options", title: "Options", contexts: ["launcher"] })
})

chrome.contextMenus.onClicked.addListener(function(info) {
  if(info.menuItemId == "options") {
    chrome.app.window.create("options.html")
  }
})

I want to deploy an existing JS app as a Packaged Crome App to make it distributable in the Chrome Web Store.

In "legacy packaged apps", there is/used to be a way to specify an options_ui page (in old legacy (legacy-legacy?) apps it was options_page) which would be accessible via a special link from your app, or by automatic link from from within chrome://extensions.

There doesn't seem to be any mention about how to migrate the options_* feature, but if the manifest.json of a Chrome App has the options_ui key it generates the following warning on the extensions page:

  • 'options_ui' is only allowed for extensions and legacy packaged apps, but this is a packaged app.

(References)

解决方案

You can create a context menu item on your icon to open your options.

Add the "contextMenus" permission, then add something like this to your background page:

chrome.runtime.onInstalled.addListener(function() {
  chrome.contextMenus.create({ id: "options", title: "Options", contexts: ["launcher"] })
})

chrome.contextMenus.onClicked.addListener(function(info) {
  if(info.menuItemId == "options") {
    chrome.app.window.create("options.html")
  }
})

这篇关于如何处理打包的Chrome应用中的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆