Skip to content

Commit

Permalink
fixed audio
Browse files Browse the repository at this point in the history
  • Loading branch information
markovic-nikola committed Mar 4, 2024
1 parent 2a29781 commit 73b7bd8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
9 changes: 1 addition & 8 deletions chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var Timer = function() {
},

this.play = function() {

if (that.isRunning() || that.limitReached) {
return;
}
Expand Down Expand Up @@ -89,7 +88,6 @@ var Timer = function() {

this.playReminderSound = function(isReminder) {
chrome.storage.sync.get('sound_option', function(obj) {

var fileName;
if (obj.sound_option && obj.sound_option == 'no_sound') {
return false;
Expand All @@ -101,10 +99,7 @@ var Timer = function() {
fileName = 'pause';
}

that.audio = new Audio();
that.audio.src = "/assets/" + fileName + ".mp3";
that.audio.play();

that.sendMessage({playSound: "/assets/" + fileName + ".mp3"});
});
},

Expand Down Expand Up @@ -158,12 +153,10 @@ var Timer = function() {
chrome.runtime.onConnect.addListener(function(port) {
that.port = port;
port.onMessage.addListener(function(msg) {

var callable_actions = ['play', 'pause', 'stop', 'update', 'checkExtensionUpdate', 'checkTimerLimitReached'];
if (msg.action && callable_actions.includes(msg.action)) {
that[msg.action]();
}

});

port.onDisconnect.addListener(function() {
Expand Down
2 changes: 1 addition & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Kronos Timer",
"version": "1.4.1",
"version": "1.4.2",
"description": "Simple tool for tracking your working time.",
"author": "Nikola Markovic",
"icons": {
Expand Down
8 changes: 6 additions & 2 deletions chrome/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ document.addEventListener('DOMContentLoaded', function() {
$playPauseBtn.setAttribute('title', manifest.commands.play_pause.suggested_key.default);

port.onMessage.addListener(function(msg) {

if (msg.time) {
document.getElementById('timer').innerHTML = '';
document.getElementById('timer').appendChild(document.createTextNode(msg.time));
Expand All @@ -61,14 +60,19 @@ document.addEventListener('DOMContentLoaded', function() {
current_time = msg.timeRaw;
}

if (msg.playSound) {
let audio = new Audio();
audio.src = msg.playSound;
audio.play();
}

if (msg.extensionUpdated) {
showUpdateLink(msg.extensionUpdated);
}

if (msg.timerLimitReached !== null && typeof msg.timerLimitReached !== 'undefined') {
$playPauseBtn.disabled = msg.timerLimitReached;
}

});

function showUpdateLink(version) {
Expand Down
1 change: 0 additions & 1 deletion firefox/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ document.addEventListener('DOMContentLoaded', function() {
var $playPauseBtn = document.querySelector('#play_pause');

$stopBtn.addEventListener('click', function(event) {
console.log('x');
port.postMessage({
action: "stop"
});
Expand Down

0 comments on commit 73b7bd8

Please sign in to comment.