-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Options page for setting notification sound
Settings are saved to the browser sync storage.
- Loading branch information
Showing
9 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background-color: transparent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Options - Tomato Clock</title> | ||
|
||
<link href="/lib/bootstrap-3.3.5-dist/css/bootstrap.min.css" type="text/css" rel="stylesheet"> | ||
<link href="/css/options.css" type="text/css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<form id="options-form"> | ||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" id="notification-sound-checkbox"> Notification sound | ||
</label> | ||
</div> | ||
|
||
<button type="submit" class="btn btn-primary">Save</button> | ||
</form> | ||
|
||
<hr /> | ||
|
||
<div> | ||
<button class="btn btn-xs btn-warning" id="reset-options">Reset to default</button> | ||
</div> | ||
|
||
<script src="/lib/browser-polyfill.js"></script> | ||
<script src="/js/constants.js"></script> | ||
<script src="/js/utils.js"></script> | ||
<script src="/js/settings.js"></script> | ||
<script src="/js/options.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class Options { | ||
constructor() { | ||
this.settings = new Settings(); | ||
|
||
this.domNotificationSoundCheckbox = document.getElementById('notification-sound-checkbox'); | ||
|
||
this.setOptionsOnPage(); | ||
this.setEventListeners(); | ||
} | ||
|
||
setOptionsOnPage() { | ||
this.settings.getSettings().then(settings => { | ||
const {isNotificationSoundEnabled} = settings; | ||
|
||
this.domNotificationSoundCheckbox.checked = isNotificationSoundEnabled; | ||
}); | ||
} | ||
|
||
saveOptions(e) { | ||
const isNotificationSoundEnabled = this.domNotificationSoundCheckbox.checked; | ||
|
||
this.settings.saveSettings({ | ||
[SETTINGS_KEY.IS_NOTIFICATION_SOUND_ENABLED]: isNotificationSoundEnabled | ||
}); | ||
} | ||
|
||
setEventListeners() { | ||
document.getElementById('options-form').addEventListener('submit', e => { | ||
e.preventDefault(); | ||
this.saveOptions(); | ||
}); | ||
|
||
document.getElementById('reset-options').addEventListener('click', () => { | ||
this.settings.resetSettings().then(() => { | ||
this.setOptionsOnPage(); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
|
||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const options = new Options(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class Settings { | ||
constructor() { | ||
this.storage = browser.storage.sync || browser.storage.local; | ||
} | ||
|
||
getSettings() { | ||
return new Promise((resolve, reject) => { | ||
const onSuccess = (storageResults) => { | ||
const settings = storageResults[STORAGE_KEY.SETTINGS] || DEFAULT_SETTINGS; | ||
|
||
resolve(settings); | ||
}; | ||
|
||
const onError = () => { | ||
resolve(DEFAULT_SETTINGS); | ||
} | ||
|
||
this.storage.get(STORAGE_KEY.SETTINGS).then(onSuccess, onError); | ||
}); | ||
} | ||
|
||
saveSettings(settings) { | ||
return this.storage.set({ | ||
[STORAGE_KEY.SETTINGS]: settings | ||
}); | ||
} | ||
|
||
resetSettings() { | ||
return this.storage.set({ | ||
[STORAGE_KEY.SETTINGS]: DEFAULT_SETTINGS | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8059f3d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty nice (y) ,waiting for the public release to use.