Skip to content

Commit

Permalink
Merge pull request #8 from WesleyBranton/Version-1.6
Browse files Browse the repository at this point in the history
Version 1.6
  • Loading branch information
WesleyBranton authored Nov 13, 2019
2 parents e3fd907 + 830ffec commit c1142e6
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 89 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@ To develop and test the extension, you need to open the "about:debugging" page i
Further documentation about developing Firefox extensions can be found [here](https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension).

## Release Notes
### Version 1.6
**[NEW]** Added ability to adjust chime volume (issue #6)
**[FIXED]** Improved invalid alarm detection to reset an alarm that's set too far into the future (issue #7)

### Version 1.5
* **[NEW]** Chime can now be stopped (issue #3)
* **[NEW]** Added toolbar icon
* **[FIXED]** Issue with chime not activating (issue #4)
* **[FIXED]** Various code optimizations to improve performance
**[NEW]** Chime can now be stopped (issue #3)
**[NEW]** Added toolbar icon
**[FIXED]** Issue with chime not activating (issue #4)
**[FIXED]** Various code optimizations to improve performance

### Version 1.4
* **[NEW]** Added "Fix Timing" button to the add-on options
* **[FIXED]** Removed unnecessary developer code
**[NEW]** Added "Fix Timing" button to the add-on options
**[FIXED]** Removed unnecessary developer code

### Version 1.3.1
* **[FIXED]** Chime is no longer 1 hour behind
**[FIXED]** Chime is no longer 1 hour behind

### Version 1.3
* **[NEW]** Changed to the more stable and reliable Javascript Alarm API
* **[FIXED]** Repaired issues with add-on not working after a period of time
**[NEW]** Changed to the more stable and reliable Javascript Alarm API
**[FIXED]** Repaired issues with add-on not working after a period of time

### Version 1.2.1
* **[FIXED]** Removed unnecessary developer testing code
**[FIXED]** Removed unnecessary developer testing code

### Version 1.2
* **[FIXED]** Default settings not loading on first install
* **[FIXED]** Timing system not firing when computer is put in sleep mode
* **[FIXED]** Improved timing system reliability
**[FIXED]** Default settings not loading on first install
**[FIXED]** Timing system not firing when computer is put in sleep mode
**[FIXED]** Improved timing system reliability

### Version 1.1
* **[NEW]** Added audio sample button to the add-on options
**[NEW]** Added audio sample button to the add-on options
33 changes: 24 additions & 9 deletions firefox/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
// Get chime from settings on startup
async function firstLoad() {
var setting = await browser.storage.local.get('chime');
chimeName = setting.chime;
load();
}

// Set default
function handleInstalled(details) {
if (details.reason == 'install') {
if (setting.chime) {
chimeName = setting.chime;
} else {
chimeName = 'default';
browser.storage.local.set({
chime: 'default'
});
}

setting = await browser.storage.local.get('volume');
if (setting.volume) {
chimeVolume = setting.volume;
} else {
chimeVolume = 1;
browser.storage.local.set({
'volume': 1
});
}

load();
}

// Create alarm
Expand All @@ -40,7 +49,7 @@ async function alarmCheck() {
var alarmTime = alarm.scheduledTime;
var currentTime = new Date().getTime();

if (alarmTime < currentTime) {
if (alarmTime < currentTime || (alarmTime - currentTime) > 3600000) {
listenMessage('reload');
}
}
Expand All @@ -60,6 +69,7 @@ function hourTrigger(alarmInfo) {
audio.addEventListener('ended', audioEnded);
audio.addEventListener('pause', audioEnded);
audio.addEventListener('play', audioStarted);
audio.volume = chimeVolume;
audio.play();
}

Expand Down Expand Up @@ -95,9 +105,14 @@ function storageChange(changes) {
if (changes.chime) {
chimeName = changes.chime.newValue;
}

if (changes.volume) {
chimeVolume = changes.volume.newValue;
audio.volume = chimeVolume;
}
}

var chimeName, audio;
var chimeName, chimeVolume, audio;
firstLoad();
browser.runtime.onInstalled.addListener(handleInstalled);
browser.alarms.onAlarm.addListener(hourTrigger);
Expand Down
5 changes: 3 additions & 2 deletions firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Grandfather Fox",
"version": "1.5",
"version": "1.6",
"description": "Turn Firefox into a grandfather clock that plays a tune at the top of each hour!",

"icons": {
Expand All @@ -16,7 +16,8 @@
},

"options_ui": {
"page": "options/options.html"
"page": "options/options.html",
"browser_style": false
},

"browser_action": {
Expand Down
52 changes: 21 additions & 31 deletions firefox/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,27 @@
<link rel="stylesheet" href="theme.css">
</head>
<body>
<form>
<fieldset>
<legend>Add-on Settings</legend>
<label>Chime Noise: </label>
<select id="chimeNoise">
<option value="tower">Clock Tower</option>
<option value="cuckoo">Cuckoo Clock</option>
<option value="default" selected>Grandfather Clock (Default)</option>
<option value="multibeep">Multiple Beeps</option>
<option value="singlebeep">Single Beep</option>
</select>
<button id="sample" type="button">Sample Audio</button>
</fieldset><br>
Do you notice the chimes playing too early or too late? Do they not play at all? Did you recently change your computer's time settings? Press the <i>Fix Timing</i> button to fix issues with the timing function.<br>
<button id="reload" type="button">Fix Timing</button>
<audio id="tower">
<source src="../audio/tower/3.ogg" type="audio/ogg">
</audio>
<audio id="cuckoo">
<source src="../audio/cuckoo/3.ogg" type="audio/ogg">
</audio>
<audio id="default">
<source src="../audio/default/3.ogg" type="audio/ogg">
</audio>
<audio id="multibeep">
<source src="../audio/multibeep/3.ogg" type="audio/ogg">
</audio>
<audio id="singlebeep">
<source src="../audio/singlebeep/3.ogg" type="audio/ogg">
</audio>
</form>
<fieldset>
<legend>Add-on Settings</legend>
<label for="chimeVolume">Chime Volume: </label>
<label id="volumeOutput">100%</label>
<button id="volumeSave" class="hide">Save</button>
<br>
<input type="range" min="1" max="100" value="100" id="chimeVolume">
<br>
<label for="chimeNoise">Chime Noise: </label>
<br>
<select id="chimeNoise">
<option value="tower">Clock Tower</option>
<option value="cuckoo">Cuckoo Clock</option>
<option value="default" selected>Grandfather Clock (Default)</option>
<option value="multibeep">Multiple Beeps</option>
<option value="singlebeep">Single Beep</option>
</select>
<button id="sample">Sample Audio</button>
</fieldset><br>
Do you notice the chimes playing too early or too late? Do they not play at all? Did you recently change your computer's time settings? Press the <i>Fix Timing</i> button to fix issues with the timing function.<br>
<button id="reload" type="button">Fix Timing</button>
<script src="options.js"></script>
</body>
</html>
81 changes: 50 additions & 31 deletions firefox/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,68 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// Save options
function saveOptions() {
var setting = document.getElementById('chimeNoise').value;
browser.storage.local.set({'chime': setting});
// Save chime option
function saveChime() {
browser.storage.local.set({
'chime': chimeNoise.value
});
}

// Load options from storage
function restoreOptions() {
browser.storage.local.get('chime', (res) => {
var setting = document.getElementById('chimeNoise');
setting.value = res.chime;
// Save volume option
function saveVolume() {
volumeSave.className = "hide";
chimeVolume = volumeSlider.value / 100;
audio.volume = chimeVolume;
browser.storage.local.set({
'volume': chimeVolume
});
}

// Load options from storage
async function restoreOptions() {
var setting = await browser.storage.local.get('chime');
chimeNoise.value = setting.chime;

setting = await browser.storage.local.get('volume');
chimeVolume = setting.volume;
volumeSlider.value = chimeVolume * 100;
updateVolumeOutput();
}

// Play audio sample
function playAudio() {
var sound = document.getElementById('tower');
sound.pause();
sound.currentTime = 0;
sound = document.getElementById('cuckoo');
sound.pause();
sound.currentTime = 0;
sound = document.getElementById('default');
sound.pause();
sound.currentTime = 0;
sound = document.getElementById('multibeep');
sound.pause();
sound.currentTime = 0;
sound = document.getElementById('singlebeep');
sound.pause();
sound.currentTime = 0;

var audioType = document.getElementById('chimeNoise').value;
var x = document.getElementById(audioType);
x.play();
audio.pause();
var audioType = chimeNoise.value;
audio = new Audio('../audio/' + audioType + '/3.ogg');
audio.volume = chimeVolume;
audio.play();
}

// Reload the alarm
function reload() {
chrome.runtime.sendMessage('reload');
}

// Update volume output number
function updateVolumeOutput() {
volumeOutput.textContent = volumeSlider.value + '%';

if (volumeSlider.value / 100 != chimeVolume) {
volumeSave.className = "";
} else {
volumeSave.className = "hide";
}
}

var chimeNoise = document.getElementById('chimeNoise');
var volumeOutput = document.getElementById('volumeOutput');
var volumeSlider = document.getElementById('chimeVolume');
var volumeSave = document.getElementById('volumeSave');
var audio = new Audio();
var chimeVolume = 1;
restoreOptions();
document.getElementsByTagName('form')[0].addEventListener('change', saveOptions);
document.getElementById('sample').addEventListener('click',playAudio);
document.getElementById('reload').addEventListener('click',reload);
document.getElementById('sample').addEventListener('click', playAudio);
document.getElementById('reload').addEventListener('click', reload);
volumeSlider.addEventListener('input', updateVolumeOutput);
chimeNoise.addEventListener('change', saveChime);
volumeSave.addEventListener('click', saveVolume);
10 changes: 8 additions & 2 deletions firefox/options/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

fieldset {
border: 2px solid #0996F8;
border: 2px solid #963;
border-radius: 5px;
}

legend {
background: #0996F8;
background: #963;
color: white;
border-radius: 3px;
padding: 10px 15px;
font-weight: bold;
}

#reload {
float: right;
}

.hide {
display: none !important;
}

0 comments on commit c1142e6

Please sign in to comment.