@@ -30,7 +30,7 @@ define(function (require, exports, module) {
3030 PreferencesManager = require ( "preferences/PreferencesManager" ) ,
3131 ExtensionUtils = require ( "utils/ExtensionUtils" ) ,
3232 Metrics = require ( "utils/Metrics" ) ,
33- utils = require ( "./utils " ) ,
33+ semver = require ( "thirdparty/semver.browser " ) ,
3434 NotificationBarHtml = require ( "text!./htmlContent/notificationContainer.html" ) ;
3535
3636 ExtensionUtils . loadStyleSheet ( module , "styles/styles.css" ) ;
@@ -44,6 +44,26 @@ define(function (require, exports, module) {
4444 PreferencesManager . stateManager . definePreference ( IN_APP_NOTIFICATIONS_BANNER_SHOWN_STATE ,
4545 "object" , { } ) ;
4646
47+ function _isValidForThisVersion ( versionFilter ) {
48+ return semver . satisfies ( brackets . metadata . apiVersion , versionFilter ) ;
49+ }
50+
51+ // platformFilter is a string subset of
52+ // "mac,win,linux,allDesktop,firefox,chrome,safari,allBrowser,all"
53+ function _isValidForThisPlatform ( platformFilter ) {
54+ platformFilter = platformFilter . split ( "," ) ;
55+ if ( platformFilter . includes ( "all" )
56+ || ( platformFilter . includes ( brackets . platform ) && Phoenix . isNativeApp ) // win linux and mac is only for tauri and not for browser in platform
57+ || ( platformFilter . includes ( "allDesktop" ) && Phoenix . isNativeApp )
58+ || ( platformFilter . includes ( "firefox" ) && Phoenix . browser . desktop . isFirefox && ! Phoenix . isNativeApp )
59+ || ( platformFilter . includes ( "chrome" ) && Phoenix . browser . desktop . isChromeBased && ! Phoenix . isNativeApp )
60+ || ( platformFilter . includes ( "safari" ) && Phoenix . browser . desktop . isSafari && ! Phoenix . isNativeApp )
61+ || ( platformFilter . includes ( "allBrowser" ) && ! Phoenix . isNativeApp ) ) {
62+ return true ;
63+ }
64+ return false ;
65+ }
66+
4767 /**
4868 * If there are multiple notifications, thew will be shown one after the other and not all at once.
4969 * A sample notifications is as follows:
@@ -86,21 +106,18 @@ define(function (require, exports, module) {
86106 for ( const notificationID of Object . keys ( notifications ) ) {
87107 if ( ! _InAppBannerShownAndDone [ notificationID ] ) {
88108 const notification = notifications [ notificationID ] ;
89- if ( ! utils . isValidForThisVersion ( notification . FOR_VERSIONS ) ) {
109+ if ( ! _isValidForThisVersion ( notification . FOR_VERSIONS ) ) {
90110 continue ;
91111 }
92- if ( ! utils . isValidForThisPlatform ( notification . PLATFORM ) ) {
112+ if ( ! _isValidForThisPlatform ( notification . PLATFORM ) ) {
93113 continue ;
94114 }
95- if ( ! notification . HTML_CONTENT . includes ( NOTIFICATION_ACK_CLASS )
96- && ! notification . DANGER_SHOW_ON_EVERY_BOOT ) {
115+ if ( ! notification . DANGER_SHOW_ON_EVERY_BOOT ) {
97116 // One time notification. mark as shown and never show again
117+ // all notifications are one time, we track metrics for each notification separately
98118 _markAsShownAndDone ( notificationID ) ;
99119 }
100120 await showBannerAndWaitForDismiss ( notification . HTML_CONTENT , notificationID ) ;
101- if ( ! notification . DANGER_SHOW_ON_EVERY_BOOT ) {
102- _markAsShownAndDone ( notificationID ) ;
103- }
104121 }
105122 }
106123 }
@@ -185,25 +202,21 @@ define(function (require, exports, module) {
185202 $closeIcon = $notificationBar . find ( '.close-icon' ) ;
186203
187204 $notificationContent . append ( $htmlContent ) ;
188- Metrics . countEvent ( Metrics . EVENT_TYPE . NOTIFICATIONS , "banner-" + notificationID ,
189- "shown" ) ;
205+ Metrics . countEvent ( Metrics . EVENT_TYPE . NOTIFICATIONS , "banner-shown" , notificationID ) ;
190206
191207 // Click handlers on actionable elements
192208 if ( $closeIcon . length > 0 ) {
193209 $closeIcon . click ( function ( ) {
194210 cleanNotificationBanner ( ) ;
195- Metrics . countEvent ( Metrics . EVENT_TYPE . NOTIFICATIONS , "banner-" + notificationID ,
196- "closeClick" ) ;
211+ Metrics . countEvent ( Metrics . EVENT_TYPE . NOTIFICATIONS , "banner-close" , notificationID ) ;
197212 ! resolved && resolve ( $htmlContent ) ;
198213 resolved = true ;
199214 } ) ;
200215 }
201216
202217 $notificationBar . find ( `.${ NOTIFICATION_ACK_CLASS } ` ) . click ( function ( ) {
203- // Your click event handler logic here
204218 cleanNotificationBanner ( ) ;
205- Metrics . countEvent ( Metrics . EVENT_TYPE . NOTIFICATIONS , "banner-" + notificationID ,
206- "ackClick" ) ;
219+ Metrics . countEvent ( Metrics . EVENT_TYPE . NOTIFICATIONS , "banner-ack" , notificationID ) ;
207220 ! resolved && resolve ( $htmlContent ) ;
208221 resolved = true ;
209222 } ) ;
0 commit comments