在 Firefox 中广播事件 OS

Broadcast events in Firefox OS

我想知道是否有办法让 Firefox OS 应用程序向所有其他应用程序广播 一个事件,并让感兴趣的应用程序挂钩该事件并触发相应的动作。

我想到的一个用例示例:相机应用程序广播事件 "picture taken" 并且另一个应用程序挂钩此事件并对已拍摄的新照片采取一些措施(例如,上传它到服务器)。

来自这篇文章[1]:

App authors can build an app that will handle one or more activities. That means that the app will be callable by another app to perform some specific actions defined by the activity. For example, let's pretend we want to build a photo manager. It could be used by another application to pick a photo. As an activity handler our app will become part of the other application's workflow.

[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Activities

目前 Firefox OS 中没有网络 API 可以向所有打开的 and/or 感兴趣的应用广播事件。

对于相机拍摄新照片时通知应用程序的特定用例,最好的方法可能是为 "pictures" 打开 DeviceStorage 并收听 "change" 事件。

相关文档位于:

https://developer.mozilla.org/en-US/docs/Web/API/DeviceStorage

存在替代方案,但在功能上受到更多限制,并且在较少的版本和上下文中可用:

注意:对于此处的每个示例,您的应用必须 运行 才能运行。没有机制可以在特定操作或事件发生时唤醒应用程序。 Web Activities 是最接近事件特定应用程序加载的 API。计时器 API 用于非特定应用程序加载。