avm99963 | 3a4946d | 2021-02-05 21:27:12 +0100 | [diff] [blame] | 1 | // IMPORTANT: keep this file in sync with sw.js |
Adrià Vilanova Martínez | 413cb44 | 2021-09-06 00:30:45 +0200 | [diff] [blame] | 2 | import {cleanUpOptions} from './common/optionsUtils.js'; |
| 3 | import KillSwitchMechanism from './killSwitch/index.js'; |
avm99963 | 1a1d2b7 | 2020-08-20 03:15:20 +0200 | [diff] [blame] | 4 | |
| 5 | chrome.browserAction.onClicked.addListener(function() { |
| 6 | chrome.runtime.openOptionsPage(); |
| 7 | }); |
Adrià Vilanova Martínez | 413cb44 | 2021-09-06 00:30:45 +0200 | [diff] [blame] | 8 | |
| 9 | const killSwitchMechanism = new KillSwitchMechanism(); |
| 10 | |
| 11 | chrome.alarms.create('updateKillSwitchStatus', { |
| 12 | periodInMinutes: PRODUCTION ? 30 : 1, |
| 13 | }); |
| 14 | |
| 15 | chrome.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. |
| 21 | chrome.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. |
| 27 | chrome.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 | }); |