author Santo Pfingsten
 *  see https import { messageUtil } from "../lib/messageUtil" ; import { settings } from "../lib/settings" ; import { loadJSONFile } from "../lib/fileHelper" ; import { browser } from "webextension-polyfill-ts" ; import { Background , CleanUrlNowConfig } from "./background" ; import { someItemsMatch } from "./backgroundShared" ; import { wetLayer } from "wet-layer" ; import { manifestVersion } from "../lib/settingsMigrations" ; const UPDATE_NOTIFICATION_ID = "UpdateNotification" ; const BADGE_SETTINGS_KEYS = [ "rules" , "fallbackRule" , "whitelistNoTLD" , "whitelistFileSystem" , "showBadge" ] ; wetLayer . reset ( ) ; settings . onReady ( ( ) => { const background = new Background ( ) ; messageUtil . receive ( "cleanAllNow" , ( ) => background . cleanAllNow ( ) ) ; messageUtil . receive ( "cleanUrlNow" , ( config ) => background . cleanUrlNow ( config ) ) ; messageUtil . receive ( "toggleSnoozingState" , ( ) => background . toggleSnoozingState ( ) ) ; messageUtil . receive ( "getSnoozingState" , ( ) => background . sendSnoozingState ( ) ) ; const badgeUpdater = ( ) => background . updateBadge ( ) ; browser . tabs . onActivated . addListener ( badgeUpdater ) ; browser . tabs . onUpdated . addListener ( badgeUpdater ) ; messageUtil . receive ( "settingsChanged" , ( changedKeys ) => { if ( someItemsMatch ( changedKeys , BADGE_SETTINGS_KEYS ) ) background . updateBadge ( ) ; } ) ; messageUtil . receive ( "import" , ( ) => { loadJSONFile ( ( json ) => { json && settings . setAll ( json ) ; } ) ; } ) ; browser . notifications . onClicked . addListener ( ( id ) => { if ( id === UPDATE_NOTIFICATION_ID ) { browser . tabs . create ( { active : true , url : browser . runtime . getURL ( "views/readme.html" ) + "#changelog" } ) ; } } ) ; function showUpdateNotification ( ) { browser . notifications . create ( UPDATE_NOTIFICATION_ID , { type : "basic" , iconUrl : browser . extension . getURL ( "icons/icon96.png" ) , title : wetLayer . getMessage ( "update_notification_title" ) , message : wetLayer . getMessage ( "update_notification_message" ) } ) ; } wetLayer . addListener ( showUpdateNotification ) ; setTimeout ( ( ) => { const previousVersion = settings . get ( "version" ) ; if ( previousVersion !== manifestVersion ) { settings . set ( "version" , manifestVersion ) ; settings . performUpgrade ( previousVersion ) ; settings . rebuildRules ( ) ; settings . save ( ) ; if ( settings . get ( "showUpdateNotification" ) ) showUpdateNotification ( ) ; } background . onStartup ( ) ; } , 1000 ) ; } ) ;