(FFOS Gecko & Gaia) OTA

  代码位置:gaia/apps/system/js/update_manager.js

1. update_manager.js向全局的window对象导出了一个对象UpdateManager,其他的js module可以直接访问UpdateManager。

exports.UpdateManager = UpdateManager;

2. UpdateManager监听了settings app中对于‘gaia.system.checkForUpdates’的设置,也就是当‘gaia.system.checkForUpdates’的值发生变化时,UpdateManager会得到通知,并bind了一个function来处理变化后的值。

SettingsListener.observe('gaia.system.checkForUpdates', false,
    this.checkForUpdates.bind(this));

3. 查看checkForUpdates函数发现,它也没有做什么真正的check工作,而是发送了一个‘force-update-check’事件。

checkForUpdates: function su_checkForUpdates(shouldCheck) {
  if (!shouldCheck) {
    return;
  }

  this._dispatchEvent('force-update-check');

  if (!this._settings) {
    return;
  }

  var lock = this._settings.createLock();
  lock.set({
    'gaia.system.checkForUpdates': false
  });
},


_dispatchEvent: function um_dispatchEvent(type, result) {
  var event = document.createEvent('CustomEvent');
  var data = { type: type };
  if (result) {
    data.result = result;
  }

  event.initCustomEvent('mozContentEvent', true, true, data);
  window.dispatchEvent(event);
},
原文地址:https://www.cnblogs.com/code-4-fun/p/4702767.html