Permalink
Browse files

Do not use localStorage for schedule storing

Refs #1
  • Loading branch information...
1 parent 00eb7b4 commit 02505216fae2fac2aec7b2972b48b641006bf67c @alexeykuzmin committed Oct 26, 2013
Showing with 27 additions and 3 deletions.
  1. +23 −1 src/background.js
  2. +4 −2 src/popup.js
View
@@ -136,8 +136,10 @@
return (h < 10 ? "0" + h : h) + (d.getSeconds() % 2 == 0 ? ":" : ":") + (m < 10 ? "0" + m : m);
}
+ var schedule = null;
+
function save (found) {
- window.localStorage.setItem("schedule", JSON.stringify(found));
+ schedule = found;
}
function distance (h1, m1, h2, m2) {
@@ -167,6 +169,12 @@
return window.localStorage.getItem("rasp");
}
+ function handleMessage(message, sender, sendResponse) {
+ if ('getSchedule' === message) {
+ sendResponse(schedule);
+ }
+ }
+
/**
* @return {number} Integer number of seconds till next minute [1; 60].
*/
@@ -175,7 +183,21 @@
return 60 - nowDate.getSeconds();
}
+ function cleanUpLocalStorage() {
+ localStorage.removeItem('schedule');
+ }
+
function init() {
+ // Listen for request from popup.
+ chrome.runtime.onMessage.addListener(handleMessage);
+
+ // Clean up localStorage on extension update.
+ chrome.runtime.onInstalled.addListener(function(details) {
+ if (details.reason === 'update') {
+ cleanUpLocalStorage();
+ }
+ });
+
// Update now.
refreshSchedule();
View
@@ -18,8 +18,10 @@
}
function refresh () {
- var raw = window.localStorage.getItem("schedule");
- var found = JSON.parse(raw);
+ chrome.runtime.sendMessage('getSchedule', renderSchedule);
+ }
+
+ function renderSchedule(found) {
for (var i = 0; i < 4; ++i) {
var td = document.getElementById('autobus_' + i);
var d = new Date(), h = d.getHours(), m = d.getMinutes();

0 comments on commit 0250521

Please sign in to comment.