@@ -10,11 +10,24 @@ class Preferences {
1010 static readonly PAGE_NOTIFICATIONS_ENABLED_KEY = 'page_notifications_enabled' ;
1111 static readonly DEFAULT_DOMAIN_EXCLUSIONS = [ 'rossmanngroup.com' ] ;
1212
13+ static readonly PAGE_NOTIFICATIONS_AUTOHIDETIME_KEY = 'page_notifications_autohide' ;
14+ static readonly PAGE_NOTIFICATIONS_DISMISSTIME_KEY = 'page_notifications_dismiss_time' ;
15+ static readonly PAGE_NOTIFICATIONS_SHOWMORE_KEY = 'page_notifications_show_more' ;
16+ static readonly PAGE_NOTIFICATIONS_SHOWMUTE_KEY = 'page_notifications_show_mute' ;
17+ static readonly PAGE_NOTIFICATIONS_SHOWHIDE_KEY = 'page_notifications_show_hide' ;
18+
1319 static isEnabled = new ObservableValue < boolean > ( true ) ;
1420 static domainExclusions = new ObservableSet < string > ( ) ;
1521 static browserNotificationsEnabled = new ObservableValue < boolean > ( true ) ;
1622 static pageNotificationsEnabled = new ObservableValue < boolean > ( true ) ;
1723
24+ //in page options
25+ static pageNotificationsAutoHideTime = new ObservableValue < number > ( 5 ) ;
26+ static pageNotificationsDismissTime = new ObservableValue < number > ( 1 ) ;
27+ static pageNotificationsShowMore = new ObservableValue < boolean > ( true ) ;
28+ static pageNotificationsShowMute = new ObservableValue < boolean > ( true ) ;
29+ static pageNotificationsShowHide = new ObservableValue < boolean > ( true ) ;
30+
1831 // Injected storage backends (TODO: do we need both?)
1932 // Sync is used to share data across browsers if logged in, e.g. plugin settings
2033 // Local is for 'this' browser only storage and can have more space available, e.g. for the pages db
@@ -37,27 +50,54 @@ class Preferences {
3750 static async initDefaults ( preferenceStore : IStorageBackend , localStore : IStorageBackend ) {
3851 console . log ( 'Defaulting settings' ) ;
3952 this . setBackingStores ( preferenceStore , localStore ) ;
53+
4054 // Reset callbacks
4155 this . isEnabled . removeAllListeners ( ) ;
4256 this . domainExclusions . removeAllListeners ( ) ;
4357 this . browserNotificationsEnabled . removeAllListeners ( ) ;
4458 this . pageNotificationsEnabled . removeAllListeners ( ) ;
59+ this . pageNotificationsAutoHideTime . removeAllListeners ( ) ;
60+ this . pageNotificationsDismissTime . removeAllListeners ( ) ;
61+ this . pageNotificationsShowMore . removeAllListeners ( ) ;
62+ this . pageNotificationsShowMute . removeAllListeners ( ) ;
63+ this . pageNotificationsShowHide . removeAllListeners ( ) ;
4564
4665 // Set up default callbacks
66+
4767 this . isEnabled . addListener ( this . IS_ENABLED_KEY , ( result : boolean ) => {
48- void this . setPreference ( Preferences . IS_ENABLED_KEY , result ) ;
68+ this . setPreference ( Preferences . IS_ENABLED_KEY , result ) ;
4969 } ) ;
5070
5171 this . domainExclusions . addListener ( this . DOMAIN_EXCLUSIONS_KEY , ( result : string [ ] ) => {
52- void this . setPreference ( Preferences . DOMAIN_EXCLUSIONS_KEY , result ) ;
72+ this . setPreference ( Preferences . DOMAIN_EXCLUSIONS_KEY , result ) ;
5373 } ) ;
5474
5575 this . browserNotificationsEnabled . addListener ( this . BROWSER_NOTIFICATIONS_ENABLED_KEY , ( result : boolean ) => {
56- void this . setPreference ( Preferences . BROWSER_NOTIFICATIONS_ENABLED_KEY , result ) ;
76+ this . setPreference ( Preferences . BROWSER_NOTIFICATIONS_ENABLED_KEY , result ) ;
5777 } ) ;
5878
5979 this . pageNotificationsEnabled . addListener ( this . PAGE_NOTIFICATIONS_ENABLED_KEY , ( result : boolean ) => {
60- void this . setPreference ( Preferences . PAGE_NOTIFICATIONS_ENABLED_KEY , result ) ;
80+ this . setPreference ( Preferences . PAGE_NOTIFICATIONS_ENABLED_KEY , result ) ;
81+ } ) ;
82+
83+ this . pageNotificationsAutoHideTime . addListener ( this . PAGE_NOTIFICATIONS_AUTOHIDETIME_KEY , ( result : number ) => {
84+ this . setPreference ( Preferences . PAGE_NOTIFICATIONS_AUTOHIDETIME_KEY , result ) ;
85+ } ) ;
86+
87+ this . pageNotificationsDismissTime . addListener ( this . PAGE_NOTIFICATIONS_DISMISSTIME_KEY , ( result : number ) => {
88+ this . setPreference ( Preferences . PAGE_NOTIFICATIONS_DISMISSTIME_KEY , result ) ;
89+ } ) ;
90+
91+ this . pageNotificationsShowMore . addListener ( this . PAGE_NOTIFICATIONS_SHOWMORE_KEY , ( result : boolean ) => {
92+ this . setPreference ( Preferences . PAGE_NOTIFICATIONS_SHOWMORE_KEY , result ) ;
93+ } ) ;
94+
95+ this . pageNotificationsShowMute . addListener ( this . PAGE_NOTIFICATIONS_SHOWMUTE_KEY , ( result : boolean ) => {
96+ this . setPreference ( Preferences . PAGE_NOTIFICATIONS_SHOWMUTE_KEY , result ) ;
97+ } ) ;
98+
99+ this . pageNotificationsShowHide . addListener ( this . PAGE_NOTIFICATIONS_SHOWHIDE_KEY , ( result : boolean ) => {
100+ this . setPreference ( Preferences . PAGE_NOTIFICATIONS_SHOWHIDE_KEY , result ) ;
61101 } ) ;
62102
63103 // Attempt preference retrieval
@@ -89,14 +129,54 @@ class Preferences {
89129 } else {
90130 this . pageNotificationsEnabled . value = true ;
91131 }
132+
133+ const rawPageNotificationsAutoHide = await this . getPreference ( this . PAGE_NOTIFICATIONS_AUTOHIDETIME_KEY ) ;
134+ if ( typeof rawPageNotificationsAutoHide === 'number' ) {
135+ this . pageNotificationsAutoHideTime . value = rawPageNotificationsAutoHide ;
136+ } else {
137+ this . pageNotificationsAutoHideTime . value = 5 ;
138+ }
139+
140+ const rawPageNotificationsDismissTime = await this . getPreference ( this . PAGE_NOTIFICATIONS_DISMISSTIME_KEY ) ;
141+ if ( typeof rawPageNotificationsDismissTime === 'number' ) {
142+ this . pageNotificationsDismissTime . value = rawPageNotificationsDismissTime ;
143+ } else {
144+ this . pageNotificationsDismissTime . value = 1 ;
145+ }
146+
147+ const rawrawpageNotificationsShowMore = await this . getPreference ( this . PAGE_NOTIFICATIONS_SHOWMORE_KEY ) ;
148+ if ( typeof rawrawpageNotificationsShowMore === 'boolean' ) {
149+ this . pageNotificationsShowMore . value = rawrawpageNotificationsShowMore ;
150+ } else {
151+ this . pageNotificationsShowMore . value = true ;
152+ }
153+
154+ const rawpageNotificationsShowMute = await this . getPreference ( this . PAGE_NOTIFICATIONS_SHOWMUTE_KEY ) ;
155+ if ( typeof rawpageNotificationsShowMute === 'boolean' ) {
156+ this . pageNotificationsShowMute . value = rawpageNotificationsShowMute ;
157+ } else {
158+ this . pageNotificationsShowMute . value = true ;
159+ }
160+
161+ const rawpageNotificationsShowHide = await this . getPreference ( this . PAGE_NOTIFICATIONS_SHOWHIDE_KEY ) ;
162+ if ( typeof rawpageNotificationsShowHide === 'boolean' ) {
163+ this . pageNotificationsShowHide . value = rawpageNotificationsShowHide ;
164+ } else {
165+ this . pageNotificationsShowHide . value = true ;
166+ }
92167 }
93168
94169 public static dump ( ) : void {
95170 const msg : string =
96171 `IsEnabled = ${ Preferences . isEnabled . toString ( ) } , ` +
97172 `DomainExclusions = ${ Preferences . domainExclusions . toString ( ) } , ` +
98173 `BrowserNotificationsEnabled = ${ Preferences . browserNotificationsEnabled . toString ( ) } , ` +
99- `PageNotificationsEnabled = ${ Preferences . pageNotificationsEnabled . toString ( ) } ` ;
174+ `PageNotificationsEnabled = ${ Preferences . pageNotificationsEnabled . toString ( ) } , ` +
175+ `PageNotificationsAutoHideTime = ${ Preferences . pageNotificationsAutoHideTime . toString ( ) } , ` +
176+ `PageNotificationsDismissTime = ${ Preferences . pageNotificationsDismissTime . toString ( ) } , ` +
177+ `pageNotificationsShowMore = ${ Preferences . pageNotificationsShowMore . toString ( ) } , ` +
178+ `pageNotificationsShowMute = ${ Preferences . pageNotificationsShowMute . toString ( ) } , ` +
179+ `pageNotificationsShowHide = ${ Preferences . pageNotificationsShowHide . toString ( ) } ` ;
100180 console . log ( msg ) ;
101181 }
102182
0 commit comments