blob: a2bb071bb4ded38a03a2a69f114fc5aa1dec5f28 [file] [log] [blame]
avm999633a4946d2021-02-05 21:27:12 +01001// IMPORTANT: keep this file in sync with sw.js
Adrià Vilanova Martínez413cb442021-09-06 00:30:45 +02002import {cleanUpOptions} from './common/optionsUtils.js';
3import KillSwitchMechanism from './killSwitch/index.js';
avm999631a1d2b72020-08-20 03:15:20 +02004
5chrome.browserAction.onClicked.addListener(function() {
6 chrome.runtime.openOptionsPage();
7});
Adrià Vilanova Martínez413cb442021-09-06 00:30:45 +02008
9const killSwitchMechanism = new KillSwitchMechanism();
10
11chrome.alarms.create('updateKillSwitchStatus', {
12 periodInMinutes: PRODUCTION ? 30 : 1,
13});
14
15chrome.alarms.onAlarm.addListener(alarm => {
16 if (alarm.name === 'updateKillSwitchStatus')
17 killSwitchMechanism.updateKillSwitchStatus();
18});
19
20// When the profile is first started, update the kill switch status.
21chrome.runtime.onStartup.addListener(() => {
22 killSwitchMechanism.updateKillSwitchStatus();
23});
24
25// When the extension is first installed or gets updated, set new options to
26// their default value and update the kill switch status.
27chrome.runtime.onInstalled.addListener(details => {
28 if (details.reason == 'install' || details.reason == 'update') {
29 chrome.storage.sync.get(null, options => {
30 cleanUpOptions(options, false);
31 });
32
33 killSwitchMechanism.updateKillSwitchStatus();
34 }
35});