@@ -46,9 +46,11 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
46
46
{
47
47
if ( chrome . runtime . lastError ) {
48
48
console . log ( "Error: " , chrome . runtime . lastError ) ;
49
- } else {
50
- updateIcon ( response . status , tabId ) ;
49
+ return ;
51
50
}
51
+
52
+ // Update the icon
53
+ updateIcon ( response . status , tabId ) ;
52
54
}
53
55
) ;
54
56
} ) ;
@@ -99,14 +101,14 @@ chrome.commands.onCommand.addListener(function(command)
99
101
} ,
100
102
function ( response )
101
103
{
102
- // If state is debugging (1) toggle to disabled (0), else toggle to debugging
103
- var newState = ( 1 == response . status ) ? 0 : 1 ;
104
+ // Get new status by current status
105
+ const newStatus = getNewStatus ( response . status ) ;
104
106
105
107
chrome . tabs . sendMessage (
106
108
tabs [ 0 ] . id ,
107
109
{
108
110
cmd : "setStatus" ,
109
- status : newState ,
111
+ status : newStatus ,
110
112
idekey : ideKey ,
111
113
traceTrigger : traceTrigger ,
112
114
profileTrigger : profileTrigger
@@ -123,13 +125,98 @@ chrome.commands.onCommand.addListener(function(command)
123
125
}
124
126
} ) ;
125
127
128
+ // Will not be called, if popup is disabled, so not needed to wrap this in a if statement
129
+ chrome . browserAction . onClicked . addListener ( ( tab ) => {
130
+ var ideKey = "XDEBUG_ECLIPSE" ;
131
+ var traceTrigger = ideKey ;
132
+ var profileTrigger = ideKey ;
133
+
134
+ // Check if localStorage is available and get the settings out of it
135
+ if ( localStorage )
136
+ {
137
+ if ( localStorage [ "xdebugIdeKey" ] )
138
+ {
139
+ ideKey = localStorage [ "xdebugIdeKey" ] ;
140
+ }
141
+
142
+ if ( localStorage [ "xdebugTraceTrigger" ] )
143
+ {
144
+ traceTrigger = localStorage [ "xdebugTraceTrigger" ] ;
145
+ }
146
+
147
+ if ( localStorage [ "xdebugProfileTrigger" ] )
148
+ {
149
+ profileTrigger = localStorage [ "xdebugProfileTrigger" ] ;
150
+ }
151
+ }
152
+
153
+ // Get the current state
154
+ chrome . tabs . sendMessage (
155
+ tab . id ,
156
+ {
157
+ cmd : "getStatus" ,
158
+ idekey : ideKey ,
159
+ traceTrigger : traceTrigger ,
160
+ profileTrigger : profileTrigger
161
+ } ,
162
+ function ( response )
163
+ {
164
+ // Get new status by current status
165
+ const newStatus = getNewStatus ( response . status ) ;
166
+
167
+ chrome . tabs . sendMessage (
168
+ tab . id ,
169
+ {
170
+ cmd : "setStatus" ,
171
+ status : newStatus ,
172
+ idekey : ideKey ,
173
+ traceTrigger : traceTrigger ,
174
+ profileTrigger : profileTrigger
175
+ } ,
176
+ function ( response )
177
+ {
178
+ // Update the icon
179
+ updateIcon ( response . status , tab . id ) ;
180
+ }
181
+ ) ;
182
+ }
183
+ ) ;
184
+ } ) ;
185
+
186
+ /**
187
+ * Get new status by current status.
188
+ *
189
+ * @param {number } status - Current status from sendMessage() cmd: 'getStatus'.
190
+ *
191
+ * @returns {number }
192
+ */
193
+ function getNewStatus ( status ) {
194
+ // Reset status, when trace or profile is selected and popup is disabled
195
+ if ( ( localStorage . xdebugDisablePopup === '1' )
196
+ && ( ( status === 2 ) || ( status === 3 ) )
197
+ ) {
198
+ return 0 ;
199
+ }
200
+
201
+ // If state is debugging (1) toggle to disabled (0), else toggle to debugging
202
+ return ( status === 1 ) ? 0 : 1 ;
203
+ }
204
+
126
205
function updateIcon ( status , tabId )
127
206
{
128
- // Figure the correct title/image with the given state
129
- var title = "Debugging, profiling & tracing disabled" ,
130
- image = "images/bug-gray.png" ;
207
+ // Reset status, when trace or profile is selected and popup is disabled
208
+ if ( ( localStorage . xdebugDisablePopup === '1' )
209
+ && ( ( status === 2 ) || ( status === 3 ) )
210
+ ) {
211
+ status = 0 ;
212
+ }
131
213
132
- if ( status == 1 )
214
+ // Figure the correct title / image by the given state
215
+ let image = "images/bug-gray.png" ;
216
+ let title = ( localStorage . xdebugDisablePopup === '1' )
217
+ ? 'Debugging disabled' : 'Debugging, profiling & tracing disabled' ;
218
+
219
+ if ( status == 1 )
133
220
{
134
221
title = "Debugging enabled" ;
135
222
image = "images/bug.png" ;
@@ -158,6 +245,10 @@ function updateIcon(status, tabId)
158
245
} ) ;
159
246
}
160
247
248
+ /**
249
+ * @deprecated
250
+ * @todo to remove silver
251
+ */
161
252
function isValueInArray ( arr , val )
162
253
{
163
254
for ( i = 0 ; i < arr . length ; i ++ )
@@ -171,3 +262,14 @@ function isValueInArray(arr, val)
171
262
172
263
return false ;
173
264
}
265
+
266
+ // Disable / Enable Popup by localStorage
267
+ if ( localStorage . xdebugDisablePopup === '1' ) {
268
+ chrome . browserAction . setPopup ( {
269
+ popup : '' ,
270
+ } ) ;
271
+ } else {
272
+ chrome . browserAction . setPopup ( {
273
+ popup : 'popup.html' ,
274
+ } ) ;
275
+ }
0 commit comments