Skip to content

Commit

Permalink
Merge pull request #1 from itsmoops/feature/hammer-the-horn
Browse files Browse the repository at this point in the history
I propose that repeated hits of the horn shouldn’t overlap.
  • Loading branch information
iammenasco authored Jul 6, 2017
2 parents e960944 + 9594002 commit 888c7b4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/rap-horn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import { CompositeDisposable } from 'atom';
export default {
subscriptions: null,

audio: document.createElement('audio'),

activate (state) {
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
this.subscriptions = new CompositeDisposable();

// Setting up default audio properties
this.audio.src = 'atom://rap-horn/lib/rap-horn.ogg';
this.audio.currentTime = 0;

// Register command that toggles this view
this.subscriptions.add(atom.commands.add('atom-workspace', {
'rap-horn:play': () => this.rapHorn()
Expand All @@ -25,10 +31,14 @@ export default {
},

rapHorn() {
this.audio = document.createElement('audio');
this.audio.src = 'atom://rap-horn/lib/rap-horn.ogg';
this.audio.currentTime = 0;
this.audio.play();
if (this.audio.currentTime > 0 && !this.audio.paused) {
this.audio.pause();
// Resetting the timer back to 0 sounds awkward - start it a little later for a better sound
this.audio.currentTime = .12;
this.audio.play();
} else {
this.audio.play();
}
}

};

0 comments on commit 888c7b4

Please sign in to comment.