Mercurial > addons > firefox-addons > tab-mover
comparison background.js @ 10:2a87d7a3863f
Clean up code
Remove unused method
Remove unused parameters
Add comments
author | Guido Berhoerster <guido+tab-mover@berhoerster.name> |
---|---|
date | Mon, 20 Feb 2017 17:00:03 +0100 |
parents | 480f8e4f4500 |
children | 5d7914307782 |
comparison
equal
deleted
inserted
replaced
9:7b9766eb014f | 10:2a87d7a3863f |
---|---|
25 super(...args); | 25 super(...args); |
26 | 26 |
27 this._observers = new Map(); | 27 this._observers = new Map(); |
28 } | 28 } |
29 | 29 |
30 addObserver(eventName, observer, thisArg) { | 30 addObserver(eventName, observer) { |
31 if (!this._observers.has(eventName)) { | 31 if (!this._observers.has(eventName)) { |
32 this._observers.set(eventName, new Set()); | 32 this._observers.set(eventName, new Set()); |
33 } | 33 } |
34 | 34 |
35 this._observers.get(eventName).add(observer); | 35 this._observers.get(eventName).add(observer); |
56 constructor() { | 56 constructor() { |
57 super(); | 57 super(); |
58 | 58 |
59 this.windows = new Map(); | 59 this.windows = new Map(); |
60 this.focusedWindowId = browser.windows.WINDOW_ID_NONE; | 60 this.focusedWindowId = browser.windows.WINDOW_ID_NONE; |
61 } | |
62 | |
63 hasWindow(id) { | |
64 return this.windows.has(id); | |
65 } | 61 } |
66 | 62 |
67 getWindow(id) { | 63 getWindow(id) { |
68 return this.windows.get(id); | 64 return this.windows.get(id); |
69 } | 65 } |
98 | 94 |
99 this.notifyObservers('window-title-updated', id, title); | 95 this.notifyObservers('window-title-updated', id, title); |
100 } | 96 } |
101 | 97 |
102 focusWindow(id) { | 98 focusWindow(id) { |
103 let oldId = this.focusedWindowId; | |
104 this.focusedWindowId = this.windows.has(id) ? id : | 99 this.focusedWindowId = this.windows.has(id) ? id : |
105 browser.windows.WINDOW_ID_NONE; | 100 browser.windows.WINDOW_ID_NONE; |
106 | 101 |
107 this.notifyObservers('window-focus-changed', oldId, id); | 102 this.notifyObservers('window-focus-changed', id); |
108 } | 103 } |
109 | 104 |
110 closeWindow(id) { | 105 closeWindow(id) { |
111 if (!this.windows.has(id)) { | 106 if (!this.windows.has(id)) { |
112 return; | 107 return; |
177 } | 172 } |
178 | 173 |
179 onWindowOpened(eventName, windowId) { | 174 onWindowOpened(eventName, windowId) { |
180 let focusedWindowId = this.model.getfocusedWindowId(); | 175 let focusedWindowId = this.model.getfocusedWindowId(); |
181 if (focusedWindowId === browser.windows.WINDOW_ID_NONE) { | 176 if (focusedWindowId === browser.windows.WINDOW_ID_NONE) { |
177 // no window is focused so there is no need to update the menu | |
182 return; | 178 return; |
183 } | 179 } |
184 | 180 |
185 let menuId = String(windowId); | 181 let menuId = String(windowId); |
186 let windowInfo = this.model.getWindow(windowId); | 182 let windowInfo = this.model.getWindow(windowId); |
206 } | 202 } |
207 | 203 |
208 onWindowTitleUpdated(eventName, windowId, title) { | 204 onWindowTitleUpdated(eventName, windowId, title) { |
209 if (this.model.getfocusedWindowId() === | 205 if (this.model.getfocusedWindowId() === |
210 browser.windows.WINDOW_ID_NONE) { | 206 browser.windows.WINDOW_ID_NONE) { |
207 // no window is focused so there is no need to update the menu | |
211 return; | 208 return; |
212 } | 209 } |
213 | 210 |
214 browser.contextMenus.update(String(windowId), {title}).catch(error => { | 211 browser.contextMenus.update(String(windowId), {title}).catch(error => { |
215 console.log('Error:', error); | 212 console.log('Error:', error); |
216 }); | 213 }); |
217 } | 214 } |
218 | 215 |
219 onWindowFocusChanged(eventName, oldWindowId, newWindowId) { | 216 onWindowFocusChanged(eventName, newWindowId) { |
220 let promises = [ | 217 let promises = [ |
221 // disable submenus | 218 // disable submenus |
222 browser.contextMenus.update('move-menu', { | 219 browser.contextMenus.update('move-menu', { |
223 enabled: false | 220 enabled: false |
224 }), | 221 }), |