首页 \ 问答 \ Firefox插件工具栏按钮在首次运行后消失(Firefox addon toolbar button disappears after first run)

Firefox插件工具栏按钮在首次运行后消失(Firefox addon toolbar button disappears after first run)

我有一个使用附加SDK制作的Firefox插件。

https://addons.mozilla.org/es/firefox/addon/board-notes/

要添加工具栏按钮,我使用SDK toolbarbutton.js的流行库:

https://github.com/erikvold/toolbarbutton-jplib/blob/master/lib/toolbarbutton.js

我只想在第一次安装时添加图标并且它可以工作,图标出现但是在重新启动浏览器后图标消失了。 用户必须使用右键单击按钮打开设置浏览器栏并再次将图标拖到栏中。 然后,如果他重新启动图标继续在其位置正确。

我想修复此行为,因为大多数用户可能不知道他们可以使用设置选项恢复图标。

我已经测试了一些函数来检测图标是否不在他的位置再次移动,但是如果用户隐藏图标,那么当他重新启动它时它将再次出现。 这是Firefox政策禁止的。

我会感激任何帮助,我会发疯的。

我使用的代码是这样的:

 button = createButton(options);

 if (options.loadReason == "install")
 {
    button.moveTo({
       toolbarID: "nav-bar",
       insertbefore: "home-button"
    });
 }

 function createButton(options) {
   return toolbarbutton.ToolbarButton({
     id: "NoteBoard",
     label: "Note Board",
     tooltiptext: "Note Board",
     image: data.url("noteboardMini.png"),
     onCommand: function() {
         openPopup();
     },
     onContext: (function () {
       var installed = false;
       return function (e, menupopup, _menuitem) {
       //Install command event listener
         if (!installed) {
            menupopup.addEventListener("command", function (e) {
               var link = e.originalTarget.value;
               if (link) open(link.replace(/\?.*/ , ""));
            });
            installed = true;
         }
         var temp = (function (arr) {
            arr.forEach(function (item, index) {
               for (var i = index + 1; i < arr.length; i++) {
                  if (arr[i] && item.label == arr[i].label) {delete arr[index]}
               }
            });

         return arr.filter(function (item){return item});
    })(loggedins);
    //remove old items
     while (menupopup.firstChild) {
      menupopup.removeChild(menupopup.firstChild)
     }
     function addChild (label, value) {
      var item = _menuitem.cloneNode(true);
      item.setAttribute("label", label);
      item.setAttribute("value", value);
      menupopup.appendChild(item);
    }
    if (temp.length) {
      temp.forEach(function (obj) {
        addChild(obj.label, obj.link);
      });
    }
    else {
      addChild(_("context"), "");
    }
  }
 })()
 });
}

I have a Firefox addon made with the add-on SDK.

https://addons.mozilla.org/es/firefox/addon/board-notes/

To add a toolbar button I use a popular library for the SDK toolbarbutton.js:

https://github.com/erikvold/toolbarbutton-jplib/blob/master/lib/toolbarbutton.js

I only want to add the icon when it first installs and it works, the icon appears but after restarting the browser the icon disappears. The user has to use the right click button to open the setup browser bar and drag the icon again to the bar. Then if he restarts the icon continue correctly in its place.

I want to fix this behaviour because the most part of users probably don't know that they can recover the icon with the setup options.

I've tested some functions to detect if the icon is not in his place to move again, but by doing this if the user hides the icon, when he restarts it will appear again. And this is forbidden by Firefox policies.

I'll appreciate any help, I'm going crazy.

The code I use is this:

 button = createButton(options);

 if (options.loadReason == "install")
 {
    button.moveTo({
       toolbarID: "nav-bar",
       insertbefore: "home-button"
    });
 }

 function createButton(options) {
   return toolbarbutton.ToolbarButton({
     id: "NoteBoard",
     label: "Note Board",
     tooltiptext: "Note Board",
     image: data.url("noteboardMini.png"),
     onCommand: function() {
         openPopup();
     },
     onContext: (function () {
       var installed = false;
       return function (e, menupopup, _menuitem) {
       //Install command event listener
         if (!installed) {
            menupopup.addEventListener("command", function (e) {
               var link = e.originalTarget.value;
               if (link) open(link.replace(/\?.*/ , ""));
            });
            installed = true;
         }
         var temp = (function (arr) {
            arr.forEach(function (item, index) {
               for (var i = index + 1; i < arr.length; i++) {
                  if (arr[i] && item.label == arr[i].label) {delete arr[index]}
               }
            });

         return arr.filter(function (item){return item});
    })(loggedins);
    //remove old items
     while (menupopup.firstChild) {
      menupopup.removeChild(menupopup.firstChild)
     }
     function addChild (label, value) {
      var item = _menuitem.cloneNode(true);
      item.setAttribute("label", label);
      item.setAttribute("value", value);
      menupopup.appendChild(item);
    }
    if (temp.length) {
      temp.forEach(function (obj) {
        addChild(obj.label, obj.link);
      });
    }
    else {
      addChild(_("context"), "");
    }
  }
 })()
 });
}

原文:https://stackoverflow.com/questions/17145348
更新时间:2023-02-03 15:02

最满意答案

我解决了这个问题

错误:

错误:无法运行程序“jar”:CreateProcess error = 2,系统找不到指定的文件打包项目HelaBibleWhereUR失败(耗时10.715秒)

我只是将java bin文件夹下的jar.exe放在jre bin文件夹中。


I solved this problem

Error:

Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specified Packaging project HelaBibleWhereUR failed (took 10.715 seconds)

I simply put jar.exe that is under java bin folder in the jre bin folder.

相关问答

更多
  • 解决了这个问题。 在AT + CIPSEND之后,消息必须是这样的> POST /newtasks HTTP/1.1 (Ctrl+M + Ctrl+J) HOST: obdsam.herokuapp.com (Ctrl+M + Ctrl+J) Accept: application/json (Ctrl+M + Ctrl+J) Content-Type: application/json(Ctrl+M + Ctrl+J) Content-Length: 23 (Ctrl+M + Ctrl+J) (Ctrl+ ...
  • 我解决了这个问题 错误: 错误:无法运行程序“jar”:CreateProcess error = 2,系统找不到指定的文件打包项目HelaBibleWhereUR失败(耗时10.715秒) 我只是将java bin文件夹下的jar.exe放在jre bin文件夹中。 I solved this problem Error: Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file spec ...
  • 在AndroidManifest.xml中添加Internet权限。 Adding Internet permission in AndroidManifest.xml.
  • 显然问题在于VRaptor框架没有兑现Accept-Charset Header。 我已经提交了一个补丁,一切都应该没问题。 该参数被提交编码为ISO-8859-1,并未按预期解码为UTF-8。 Apparently the issue was with VRaptor framework that wasn't honoring the Accept-Charset Header. I've already submited a patch and everything should be fine. T ...
  • 由于您要发送用户使用表单输入的json,因此您可以考虑使用JObject类作为Web api方法参数。 所以在你的形式
    现在,在按钮 ...
  • 使用base64对图像进行编码,然后将base64字符串作为json发送。 在服务器端再次解码base64并保存它或用它做任何你想做的事情 Encode your image with base64, then send the base64 string as json. On the serverside decode the base64 again and save it or do whatever you want with it
  • 像这样从JSON发布你的数据 var myvalue = 'test'; $.ajax({ type: "POST", url: "/echo/json/", data: {getval: myvalue}, success: function (data) { alert("Successfully posted"); } });