11import { ITabsRepository } from "./tabs-repository-interface" ;
22import { Tab } from "../entity/tab" ;
3- import Browser from 'webextension-polyfill' ;
43import { injecStorage } from "../storage/inject-storage" ;
5- import { isValidPage } from '../compositions/valid-page' ;
64import { isInBlackList } from "../compositions/black-list" ;
7- import { extractHostname } from "../compositions/extract-hostname" ;
85import { StorageDeserializeParam } from "../storage/storage-params" ;
96
107export class TabsRepository implements ITabsRepository {
11- private tabs : Tab [ ] ;
8+ private tabs : Tab [ ] ;
129
13- constructor ( ) {
14- this . tabs = [ ] ;
15- }
16-
17- async initAsync ( ) {
18- this . tabs = await injecStorage ( ) . getDeserializeList ( StorageDeserializeParam . TABS ) as Tab [ ] ;
19- }
10+ constructor ( ) {
11+ this . tabs = [ ] ;
12+ }
2013
21- getTabs ( ) : Tab [ ] {
22- return this . tabs ;
23- }
14+ async initAsync ( ) {
15+ this . tabs = ( await injecStorage ( ) . getDeserializeList (
16+ StorageDeserializeParam . TABS
17+ ) ) as Tab [ ] ;
18+ }
2419
25- getTab ( domain : string ) : Tab | undefined {
26- return this . tabs ?. find ( x => x . url === domain ) ;
27- }
20+ getTabs ( ) : Tab [ ] {
21+ return this . tabs ;
22+ }
2823
29- async addTab ( tab : Browser . Tabs . Tab ) : Promise < Tab | undefined > {
30- if ( isValidPage ( tab ) ) {
31- if ( tab . id && ( tab . id != 0 ) ) {
32- const domain = extractHostname ( tab . url ) ;
33- const tabFromStorage = this . getTab ( domain ) ;
34- const isInBlackListFlag = await isInBlackList ( domain ) ;
35-
36- if ( ! isInBlackListFlag ) {
37- if ( ! tabFromStorage ) {
38- let favicon = tab . favIconUrl ;
39- if ( ! favicon ) {
40- favicon = 'chrome://favicon/' + domain ;
41- }
42- const newTab = new Tab ( ) ;
43- newTab . init ( domain , favicon ) ;
44- this . tabs . push ( newTab ) ;
45- return newTab ;
46- }
47- }
48- }
49- }
24+ getTab ( domain : string ) : Tab | undefined {
25+ return this . tabs ?. find ( ( x ) => x . url === domain ) ;
26+ }
27+
28+ async addTab ( domain : string , favicon : string | undefined ) : Promise < Tab | undefined > {
29+ const tabFromStorage = this . getTab ( domain ) ;
30+ const isInBlackListFlag = await isInBlackList ( domain ) ;
5031
51- return undefined ;
32+ if ( ! isInBlackListFlag ) {
33+ if ( ! tabFromStorage ) {
34+ if ( ! favicon ) {
35+ favicon = "chrome://favicon/" + domain ;
36+ }
37+ const newTab = new Tab ( ) ;
38+ newTab . init ( domain , favicon ) ;
39+ this . tabs . push ( newTab ) ;
40+ return newTab ;
41+ }
5242 }
53- }
43+
44+ return undefined ;
45+ }
46+ }
0 commit comments