OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function WindowStateManager() { |
| 6 this.savedWindow = []; |
| 7 } |
| 8 |
| 9 /** |
| 10 * Minimize all opening windows and save their states. |
| 11 */ |
| 12 WindowStateManager.prototype.saveStates = function() { |
| 13 var focusedWindowId; |
| 14 chrome.windows.getLastFocused(function(focusedWindow) { |
| 15 focusedWindowId = focusedWindow.id; |
| 16 }); |
| 17 var self = this; |
| 18 chrome.windows.getAll(null, function(windows) { |
| 19 for (var i in windows) { |
| 20 if (windows[i].state != 'minimized' && |
| 21 windows[i].id != focusedWindowId) { |
| 22 self.savedWindow.push(windows[i]); |
| 23 chrome.windows.update(windows[i].id, {'state': 'minimized'}, |
| 24 function() {}); |
| 25 } |
| 26 } |
| 27 }); |
| 28 }; |
| 29 |
| 30 /** |
| 31 * Restore the states of all windows. |
| 32 */ |
| 33 WindowStateManager.prototype.restoreStates = function() { |
| 34 for (var i in this.savedWindow) { |
| 35 var state = this.savedWindow[i].state; |
| 36 chrome.windows.update(this.savedWindow[i].id, {'state': state}, |
| 37 function() {}); |
| 38 } |
| 39 }; |
| 40 |
| 41 /** |
| 42 * Remove the saved state of the current focused window. |
| 43 * @param {integer} windowId The ID of the window. |
| 44 */ |
| 45 WindowStateManager.prototype.removeSavedState = function(windowId) { |
| 46 for (var i in this.savedWindow) { |
| 47 if (windowId == this.savedWindow[i].id) |
| 48 this.savedWindow.splice(i, 1); |
| 49 } |
| 50 }; |
| 51 |
| 52 var windowStateManager = new WindowStateManager(); |
| 53 |
| 54 // If a window gets focused before wallpaper manager close. The saved state |
| 55 // is no longer correct. |
| 56 chrome.windows.onFocusChanged.addListener( |
| 57 windowStateManager.removeSavedState.bind(windowStateManager)); |
OLD | NEW |