在哪里保存Firefox插件的文件?

编程入门 行业动态 更新时间:2024-10-09 00:48:55
本文介绍了在哪里保存Firefox插件的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在开发一个Firefox附加软件,其中包含了附加组件使用的网站缩略图。到目前为止,我一直使用简单的存储通过他们的图像数据URL来存储它们。两个问题:存储空间有限,发送很长的字符串似乎并不是最佳的(我假设浏览器已经优化了加载图像文件的方式,但可能不是数据URL)。我认为这不应该是一个问题,将文件保存到磁盘,问题是在哪里。我GOOGLE了很多,找不到任何东西。这是否有一个自然的地方?是否有任何限制?

解决方案

截至 Firefox 32 ,为你的加载项存储数据的地方应该是: [profile ] / extension-data / [add-on ID] 。这是通过错误915838 - 为附件提供一个标准目录来存储数据,设置。有一个后续错误,错误952304 - (JSONStore)JSON存储API的插件用于存储数据和设置,这应该提供一个API以方便访问。

对于Addon-SDK,您可以获取插件ID(你可以在 package.json 中定义):

let self = require(sdk / self ); 让addonID = self.id;

对于XUL和重新启动的扩展,您应该能够获得您的插件的ID在 install.rdf 文件中):

Components.utils.import(resource:/ /gre/modules/Services.jsm); 让addonID = Services.appInfo.ID

然后您可以执行以下操作来生成该目录中的文件的URI:

userProfileDirectoryPath = Components.classes [@ mozilla/file/directory_service;1 ] .getService(Components.interfaces.nsIProperties) .get(ProfD,Components.interfaces.nsIFile).path, $ b $ / ** *在首选项 *目录下为扩展名的数据目录中的文件名生成URI。 * / 函数generateURIForFileInPrefExtensionDataDirectory(fileName){ //考虑路径分隔符依赖于操作系统 let toReturn =file://+ userProfileDirectoryPath.replace(/ \\\/G,/); return toReturn +/ extension-data /+ addonID +/+ fileName; $ b

对象 myExtension.addonData 是我存储的 Bootstrap数据的副本提供给 bootstrap.js 。

I am working on a Firefox add-on which among other stuff generates thumbnails of websites for use by the add-on. So far I've been storing them by their image data URL using simple-storage. Two problems with this: the storage space is limited and sending very long strings around doesn't seem optimal(I assume the browser has optimized ways of loading image files, but maybe not data URLs). I think it shouldn't be a problem to save the files to disk, the question is where though. I googled quite a bit and could not find anything. Is there a natural place for this? Are there any restrictions?

解决方案

As of Firefox 32, the place to store data for your add-on is supposed to be: [profile]/extension-data/[add-on ID]. This was established by the resolution of "Bug 915838 - Provide add-ons a standard directory to store data, settings". There is a follow-on bug, "Bug 952304 - (JSONStore) JSON storage API for addons to use in storing data and settings" which is supposed to provide an API for easy access.

For the Addon-SDK, you can obtain the addon ID (which you define in package.json) with:

let self = require("sdk/self"); let addonID = self.id;

For XUL and restartless extensions, you should be able to get the ID of your addon (which you define in the install.rdf file) with:

Components.utils.import("resource://gre/modules/Services.jsm"); let addonID = Services.appInfo.ID

You can then do the following to generate a URI for a file in that directory:

userProfileDirectoryPath = Components.classes["@mozilla/file/directory_service;1"] .getService( Components.interfaces.nsIProperties) .get("ProfD", Components.interfaces.nsIFile).path, /** * Generate URI for a filename in the extension's data directory under the preferences * directory. */ function generateURIForFileInPrefExtensionDataDirectory (fileName) { //Account for the path separator being OS dependent let toReturn = "file://" + userProfileDirectoryPath.replace(/\\/g,"/"); return toReturn +"/extension-data/" + addonID + "/" + fileName; } }

The object myExtension.addonData is a copy that I store of the Bootstrap data provided to entry points in bootstrap.js.

更多推荐

在哪里保存Firefox插件的文件?

本文发布于:2023-11-26 07:45:43,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插件   文件   Firefox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!