diff options
author | Determinant <ted.sybil@gmail.com> | 2019-02-06 18:44:02 -0500 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2019-02-06 18:44:02 -0500 |
commit | a8b8cd7d51cafea253f3e7b2e3d1e76054d97135 (patch) | |
tree | 55fb977be1d525a642a5b19edc0313796ea83cb0 /src/background.js | |
parent | d3d4345a7ab82e9715b1cbf398d43206d43737f6 (diff) |
WIP: settings
Diffstat (limited to 'src/background.js')
-rw-r--r-- | src/background.js | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/background.js b/src/background.js index 177ec68..e9b0f60 100644 --- a/src/background.js +++ b/src/background.js @@ -1,7 +1,8 @@ import * as gapi from './gapi'; import { msgType, Msg } from './msg'; -let patterns = []; +let mainPatterns = []; +let analyzePatterns = []; let calendars = {}; let calData = {}; @@ -11,9 +12,18 @@ chrome.runtime.onConnect.addListener(function(port) { let msg = Msg.inflate(_msg); console.log(msg); if (msg.type == msgType.updatePatterns) { - patterns = msg.data; + if (msg.data.id == 'analyze') + analyzePatterns = msg.data.patterns; + else + mainPatterns = msg.data.patterns; + port.postMessage(msg.genResp(null)); } else if (msg.type == msgType.getPatterns) { + let patterns; + if (msg.data.id == 'analyze') + patterns = analyzePatterns; + else + patterns = mainPatterns; port.postMessage(msg.genResp(patterns)); } else if (msg.type == msgType.updateCalendars) { @@ -22,9 +32,17 @@ chrome.runtime.onConnect.addListener(function(port) { if (!calData.hasOwnProperty(id)) calData[id] = new gapi.GCalendar(id, calendars[id].summary); } + port.postMessage(msg.genResp(null)); } else if (msg.type == msgType.getCalendars) { - port.postMessage(msg.genResp(calendars)); + let cals = calendars; + if (msg.data.enabledOnly) + { + cals = Object.keys(calendars) + .filter(id => calendars[id].enabled) + .reduce((res, id) => (res[id] = calendars[id], res), {}); + } + port.postMessage(msg.genResp(cals)); } else if (msg.type == msgType.getCalEvents) { calData[msg.data.id].getEvents(new Date(msg.data.start), new Date(msg.data.end)) |