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 this.savedWindow = []; | |
18 var self = this; | |
19 chrome.windows.getAll(null, function(windows) { | |
20 for (var i in windows) { | |
21 if (windows[i].state != 'minimized') | |
22 self.savedWindow.push(windows[i]); | |
23 if (windows[i].id != focusedWindowId) | |
24 chrome.windows.update(windows[i].id, {'state': 'minimized'}, | |
25 function() {}); | |
26 } | |
27 }); | |
28 }; | |
29 | |
30 /** | |
31 * Restore the states of all windows. | |
32 */ | |
33 WindowStateManager.prototype.restoreStates = function() { | |
34 var self = this; | |
35 chrome.windows.getAll(null, function(windows) { | |
36 for (var i in windows) { | |
37 for (var j in self.savedWindow) { | |
flackr
2012/07/06 12:28:53
You can probably avoid the need for a background p
bshe
2012/07/06 18:58:06
Done. Also added a focus event listener. So when t
| |
38 if (windows[i].id == self.savedWindow[j].id) { | |
39 var state = self.savedWindow[j].state; | |
40 chrome.windows.update(windows[i].id, {'state': state}, | |
41 function() {}); | |
42 } | |
43 } | |
44 } | |
45 }); | |
46 }; | |
47 | |
48 var windowStateManager = new WindowStateManager(); | |
OLD | NEW |