diff --git a/chrome/background.js b/chrome/background.js index 0d05765..7b45b1e 100644 --- a/chrome/background.js +++ b/chrome/background.js @@ -18,7 +18,6 @@ var Timer = function() { }, this.play = function() { - if (that.isRunning() || that.limitReached) { return; } @@ -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; @@ -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"}); }); }, @@ -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() { diff --git a/chrome/manifest.json b/chrome/manifest.json index 50d71b1..e7e4661 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -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": { diff --git a/chrome/popup/popup.js b/chrome/popup/popup.js index 7dedcde..6b70f74 100644 --- a/chrome/popup/popup.js +++ b/chrome/popup/popup.js @@ -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)); @@ -61,6 +60,12 @@ 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); } @@ -68,7 +73,6 @@ document.addEventListener('DOMContentLoaded', function() { if (msg.timerLimitReached !== null && typeof msg.timerLimitReached !== 'undefined') { $playPauseBtn.disabled = msg.timerLimitReached; } - }); function showUpdateLink(version) { diff --git a/firefox/popup/popup.js b/firefox/popup/popup.js index fef2232..c782f08 100644 --- a/firefox/popup/popup.js +++ b/firefox/popup/popup.js @@ -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" });