File tree Expand file tree Collapse file tree 4 files changed +31
-9
lines changed
Expand file tree Collapse file tree 4 files changed +31
-9
lines changed Original file line number Diff line number Diff line change 11import Browser from "webextension-polyfill" ;
22import { initTracker } from "./tracker" ;
33import { logger } from "./compositions/logger" ;
4+ import { useFavicon } from "./compositions/update-favicon" ;
45
56logger . log ( "Start background script" ) ;
67
78Browser . runtime . onInstalled . addListener ( ( details ) => {
89 logger . log ( "Extension installed:" , details ) ;
910} ) ;
1011
12+ Browser . webNavigation . onCompleted . addListener ( async function ( details ) {
13+ await useFavicon ( details . tabId ) ;
14+ } ) ;
15+
1116initTracker ( ) ;
Original file line number Diff line number Diff line change 1+ import Browser from 'webextension-polyfill' ;
2+ import { isValidPage } from './valid-page' ;
3+ import { extractHostname } from './extract-hostname' ;
4+ import { injectTabsRepository } from '../repository/inject-tabs-repository' ;
5+
6+ export async function useFavicon ( tabId : number ) : Promise < void > {
7+ const repo = await injectTabsRepository ( ) ;
8+ const tab = await Browser . tabs . get ( tabId ) ;
9+ if ( isValidPage ( tab ) ) {
10+ const activeDomain = extractHostname ( tab ?. url ) ;
11+ let tabFromStoage = repo . getTab ( activeDomain ) ;
12+ if ( tabFromStoage != undefined && tabFromStoage . favicon != null ) {
13+ tabFromStoage . setFavicon ( tab ?. favIconUrl ) ;
14+ }
15+ }
16+ }
Original file line number Diff line number Diff line change @@ -8,9 +8,8 @@ export class Tab implements ISerializable<Tab> {
88 counter : number = 0
99 days : TabDay [ ] = [ ] ;
1010
11- init ( url : string , favicon : string ) {
11+ init ( url : string ) {
1212 this . url = url ;
13- this . favicon = favicon ;
1413 }
1514
1615 incSummaryTime ( ) :void {
@@ -48,6 +47,13 @@ export class Tab implements ISerializable<Tab> {
4847
4948 return this ;
5049 }
50+
51+ setFavicon ( favicon : string | undefined ) {
52+ if ( favicon != undefined )
53+ this . favicon = favicon ;
54+ else
55+ this . favicon = "chrome://favicon/" + this . url ;
56+ }
5157}
5258
5359export class TabDay implements ISerializable < TabDay > {
Original file line number Diff line number Diff line change @@ -29,16 +29,11 @@ export class TabsRepository implements ITabsRepository {
2929 const tabFromStorage = this . getTab ( domain ) ;
3030 const isInBlackListFlag = await isInBlackList ( domain ) ;
3131
32- if ( ! isInBlackListFlag ) {
33- if ( ! tabFromStorage ) {
34- if ( ! favicon ) {
35- favicon = "chrome://favicon/" + domain ;
36- }
32+ if ( ! isInBlackListFlag && ! tabFromStorage ) {
3733 const newTab = new Tab ( ) ;
38- newTab . init ( domain , favicon ) ;
34+ newTab . init ( domain ) ;
3935 this . tabs . push ( newTab ) ;
4036 return newTab ;
41- }
4237 }
4338
4439 return undefined ;
You can’t perform that action at this time.
0 commit comments