简体   繁体   English

为Firefox OS开发Cordova插件

[英]Developing Cordova plugins for Firefox OS

How does one go about creating cordova plugins on Firefox OS? 如何在Firefox OS上创建Cordova插件?

I've got a cordova plugin that I've written for iOS and Android that I'd like to add firefox OS support to. 我有一个为iOS和Android编写的cordova插件,我想向其中添加firefox OS支持。 Specifically, it enumerates the fonts that have been installed on the mobile device (my use case is a mostly-offline editor / translation tool). 具体来说,它枚举了已在移动设备上安装的字体(我的用例是主要是脱机编辑器/翻译工具)。

It looks like firefox OS uses the Android Open Source Project at a lower layer of its OS called Gonk . 看起来firefox操作系统在其操作系统的下层Gonk中使用了Android Open Source Project。 But, it also looks like Gronk is buried a couple layers deeper than the applications live. 但是,看起来Gronk似乎比应用程序的实际存在还要深几层。 Is this where I need to be writing the plugin code? 这是我需要编写插件代码的地方吗? It doesn't seem like code written there would be exposed through the gecko / gaia layers, and unfortunately the Cordova plugin developer's guide doesn't have any info on where to begin. 看起来那里编写的代码似乎不会通过gecko / gaia层公开,而且不幸的是, Cordova插件开发人员指南没有关于从何开始的任何信息。

If you could mess with Gonk at that level I think that it could be counted as a major security threat. 如果您可以在该级别上与Gonk混淆,我认为可以将其视为主要的安全威胁。 Today Fira is the system font and you can use your own font simply including it in your application with css. 今天,Fira是系统字体,您可以使用自己的字体,只需将其包含在CSS中即可。

I guess that now there isn't such a thing in Firefox OS but I will keep you updated in case I find something. 我想现在Firefox OS中没有这样的东西了,但是我会及时通知您,以防万一。

I'm afraid that there is no ability to get any info from "Android" layer in Firefox OS. 恐怕无法从Firefox OS的“ Android”层获取任何信息。 You could certainly do it for your machine, but as there is no Javascript font API it's not possible to create such a code in JavaScript. 您当然可以为您的机器执行此操作,但是由于没有Java字体字体API,因此无法在JavaScript中创建这样的代码。 All Cordova apps have exactly the same rights as other Firefox OS apps. 所有Cordova应用程序都具有与其他Firefox OS应用程序完全相同的权限。

Okay, it looks like this is a two-part answer: 好的,这看起来像是一个分为两个部分的答案:

  1. For the general question of "how does one create a cordova plugin for firefox os?" 对于“如何为firefox os创建cordova插件?”这一一般性问题。 the answer is "in javascript." 答案是“使用javascript”。 If you go poking around in the source code for Cordova's own plugins , drilling down into the src/firefoxos directories, you'll note that each of the plugins that do implement the functionality on firefox os do so with javascript. 如果您翻阅Cordova自己的插件的源代码,并深入到src / firefoxos目录,您会注意到,确实在firefox os上实现功能的每个插件都使用javascript来实现。 This kind of brings up the point that EdoPut and zalun make -- Cordova plugins don't drill down and expose anything that isn't already exposed via javascript, and conversely anything that isn't exposed to javascript is unavailable to client apps. 这种说法提出了EdoPut和zalun的观点-Cordova插件不会向下钻取并公开任何尚未通过javascript公开的内容,相反,未公开给javascript的任何内容都将对客户端应用程序不可用。 This is the glory and pain of firefox os. 这是Firefox OS的荣耀和痛苦。
  2. For my specific case of "I want to dynamically retrieve the fonts installed on the device" the answer is you can't . 对于我的特定情况“我想动态检索安装在设备上的字体”,答案是“ 不能” There isn't a direct way to do this with the current API, and as this google group topic adds, returning a static list isn't guaranteed to be correct between versions or vendors . 没有使用当前API来执行此操作的直接方法,并且随着该Google Group主题的添加, 不能保证在版本或供应商之间返回静态列表是正确的

There is kind of a hack-y way to dynamically get fonts based on whether a browser is doing font substitution here: http://www.lalit.org/lab/javascript-css-font-detect/ . 一种黑客攻击-Y方式动态获取基于浏览器是否在这里做字体替换字体: http://www.lalit.org/lab/javascript-css-font-detect/ I had tried this earlier and it did work on firefox, but not on webkit/chrome -- hence my desire to make this plugin for iOS/Android in the first place. 我之前曾尝试过,但它确实在firefox上起作用,但在webkit / chrome上却不起作用-因此,我希望首先将其用于iOS / Android。 I might end up using this method for the firefoxos port of my plugin. 我可能最终将这种方法用于插件的firefoxos端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM