prefs: keep up-to-date using prefChanged event
This commit is contained in:
		
							parent
							
								
									5c8d1950a7
								
							
						
					
					
						commit
						97c5972348
					
				
							
								
								
									
										5
									
								
								popup.js
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								popup.js
									
									
									
									
									
								
							|  | @ -59,8 +59,9 @@ function initPopup(url) { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // action buttons
 |   // action buttons
 | ||||||
|   $('#disableAll').onchange = () => |   $('#disableAll').onchange = function() { | ||||||
|     installed.classList.toggle('disabled', prefs.get('disableAll')); |     installed.classList.toggle('disabled', this.checked); | ||||||
|  |   }; | ||||||
|   setupLivePrefs(['disableAll']); |   setupLivePrefs(['disableAll']); | ||||||
| 
 | 
 | ||||||
|   $('#find-styles-link').onclick = handleEvent.openURLandHide; |   $('#find-styles-link').onclick = handleEvent.openURLandHide; | ||||||
|  |  | ||||||
							
								
								
									
										22
									
								
								prefs.js
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								prefs.js
									
									
									
									
									
								
							|  | @ -87,12 +87,16 @@ var prefs = new function Prefs() { | ||||||
|       const oldValue = deepCopy(values[key]); |       const oldValue = deepCopy(values[key]); | ||||||
|       values[key] = value; |       values[key] = value; | ||||||
|       defineReadonlyProperty(this.readOnlyValues, key, value); |       defineReadonlyProperty(this.readOnlyValues, key, value); | ||||||
|       if (!noBroadcast && !equal(value, oldValue)) { |       if (BG && BG != window) { | ||||||
|         this.broadcast(key, value, {noSync}); |         BG.prefs.set(key, BG.deepCopy(value), {noBroadcast, noSync}); | ||||||
|  |       } else { | ||||||
|  |         localStorage[key] = typeof defaults[key] == 'object' | ||||||
|  |           ? JSON.stringify(value) | ||||||
|  |           : value; | ||||||
|  |         if (!noBroadcast && !equal(value, oldValue)) { | ||||||
|  |           this.broadcast(key, value, {noSync}); | ||||||
|  |         } | ||||||
|       } |       } | ||||||
|       localStorage[key] = typeof defaults[key] == 'object' |  | ||||||
|         ? JSON.stringify(value) |  | ||||||
|         : value; |  | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     remove: key => this.set(key, undefined), |     remove: key => this.set(key, undefined), | ||||||
|  | @ -170,6 +174,14 @@ var prefs = new function Prefs() { | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  |   chrome.runtime.onMessage.addListener(msg => { | ||||||
|  |     if (msg.prefs) { | ||||||
|  |       for (const id in msg.prefs) { | ||||||
|  |         this.set(id, msg.prefs[id], {noBroadcast: true, noSync: true}); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|   function doBroadcast() { |   function doBroadcast() { | ||||||
|     const affects = {all: 'disableAll' in broadcastPrefs}; |     const affects = {all: 'disableAll' in broadcastPrefs}; | ||||||
|     if (!affects.all) { |     if (!affects.all) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user