Skip to content

Instantly share code, notes, and snippets.

@mcav
Created April 24, 2014 21:19
Show Gist options
  • Save mcav/11269865 to your computer and use it in GitHub Desktop.
Save mcav/11269865 to your computer and use it in GitHub Desktop.
addAlert: function(alert) {
var testOpts = alert.testOpts || {};
if (this.alerts.length) {
this.removeCurrentAlert();
}
this.alerts.unshift(alert);
this._screenLock = this._screenLock || navigator.requestWakeLock('screen');
clearTimeout(this._screenTimeout);
this._screenTimeout = setTimeout(() => {
console.log('Releasing screen lock.');
this._screenLock.unlock();
this._screenLock = null;
}, testOpts.screenOnDuration || SCREEN_ON_DURATION);
this._cpuLock = this._cpuLock || navigator.requestWakeLock('cpu');
clearTimeout(this._cpuTimeout);
this._cpuTimeout = setTimeout(() => {
console.log('Releasing CPU lock and silencing alarm.');
this._cpuLock.unlock();
this._cpuLock = null;
this.silence();
}, testOpts.audibleDuration || AUDIBLE_DURATION);
this.silence();
this.ringLabel.textContent = this.alert.label ||
mozL10n.get(this.alert.type === 'alarm' ? 'alarm' : 'timer');
this.ringDisplay.dataset.ringType = this.alert.type;
this.time.innerHTML = Utils.getLocalizedTimeHtml(alert.time);
if (this.alert.sound) {
this.ringtonePlayer.playRingtone(this.alert.sound);
}
if (this.alert.vibrate && ('vibrate' in navigator)) {
clearInterval(this.vibrateInterval);
var vibrateOnce = function() {
navigator.vibrate([1000]);
};
this.vibrateInterval = setInterval(vibrateOnce, 2000);
vibrateOnce();
}
document.documentElement.classList.add('ready');
window.focus();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment