Example #1
0
/**
 * AlarmListPanel displays the list of alarms on the Clock tab.
 */
function AlarmListPanel(element) {
  this.alarms = element;

  this.newAlarmButton.addEventListener(
    'click', this.onClickNewAlarm.bind(this));
  this.alarms.addEventListener('click', this.onClickAlarmItem.bind(this));

  this.banner = new Banner('banner-countdown');

  alarmDatabase.getAll().then((alarms) => {
    for (var i = 0; alarms && i < alarms.length; i++) {
      this.addOrUpdateAlarm(alarms[i]);
    }
    this.updateAlarmStatusBar();
    App.alarmListLoaded();
  });

  window.addEventListener('alarm-changed', (evt) => {
    var alarm = evt.detail.alarm;
    this.addOrUpdateAlarm(alarm);
    if (evt.detail.showBanner) {
      this.banner.show(alarm.getNextAlarmFireTime());
    }
    this.updateAlarmStatusBar();
  });
  window.addEventListener('alarm-removed', (evt) => {
    this.removeAlarm(evt.detail.alarm);
    this.updateAlarmStatusBar();
  });
}
Example #2
0
    _notifyChanged: function(removed) {
      // Only update the application if this alarm was actually saved
      // (i.e. it has an ID).
      if (this.id) {
        var alarmDatabase = require('alarm_database');
        // Updating Alarm info from the DataStore
        alarmDatabase.getAll()
        .then((alarms) => {
          var storeAlarms = [];

          alarms.forEach(function(a) {
            // Grabbing alarms that are 'normal'
            if(a.registeredAlarms.normal) {
              storeAlarms.push(a.getNextAlarmFireTime());
            }
          });

          return this.getNextAlarm(storeAlarms);
        }).then((nextAlarm) => {

          navigator.getDataStores('alarms')
          .then((stores) => {
            return [stores[0].getLength(), stores[0]];
          }).then(([len, store]) => {
            if(0 === len) {
              return store.add(nextAlarm);
            } else {
              return store.put(nextAlarm, 1);
            }
          }).then((id) => {
            if(id) {
              console.log('[Clock] ==== Updated Alarm on LockScreen ====');
            }
          });

        });
        window.dispatchEvent(
          new CustomEvent(removed ? 'alarm-removed' : 'alarm-changed', {
            detail: { alarm: this }
          })
        );
      }
    },
Example #3
0
  function logForAlarmDebugging() {
    // The following logs are included for debugging reported
    // problems with alarm firing times: <https://bugzil.la/1052245>
    console.log('[Clock] =====================================\n');
    console.log('[Clock] Alarm Debug:', JSON.stringify({
      'now': new Date().toJSON(),
      'tz': new Date().getTimezoneOffset()
    }));

    alarmDatabase.getAll().then((alarms) => {
      console.log('[Clock] ===== Raw IndexedDB Alarm Data: =====\n');
      // Logging in a loop to ensure we don't overrun the line buffer:
      alarms.forEach(function(a) {
        console.log('[Clock]   ', JSON.stringify(a.toJSON()));
      });
      console.log('[Clock] -------------------------------------\n');
    });

    // var request = navigator.mozAlarms.getAll();
    // request.onsuccess = function() {
    //   console.log('[Clock] ======= Remaining mozAlarms: ========\n');

    //   if (!request.result) {
    //     console.log('[Clock] mozAlarm API invariant failure?');
    //   } else {
    //     request.result.forEach(function(alarm) {
    //       console.log('[Clock]   ', JSON.stringify(alarm));
    //     });
    //   }

    //   console.log('[Clock] -------------------------------------\n');
    // };

    // request.onerror = function() {
    //   console.error('[Clock] Failed to get list of mozAlarms:', this.error);
    // };
  }