Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Unified Diff: ui/file_manager/gallery/js/background.js

Issue 294593003: Gallery.app: Re-open Gallery.app when the new entries are opened. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/file_manager/gallery/js/gallery.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/gallery/js/background.js
diff --git a/ui/file_manager/gallery/js/background.js b/ui/file_manager/gallery/js/background.js
index 4572bce59591038e4eef2f03d4bc3ae30e986529..61ea019d2f1723588bc96580eeea76886ec7484a 100644
--- a/ui/file_manager/gallery/js/background.js
+++ b/ui/file_manager/gallery/js/background.js
@@ -91,6 +91,12 @@ function getChildren(entry) {
return readEntries();
}
+/**
+ * Promise to be fulfilled with single application window.
+ * @param {AppWindow}
+ */
+var appWindowPromise = null;
+
chrome.app.runtime.onLaunched.addListener(function(launchData) {
// Skip if files are not selected.
if (!launchData || !launchData.items || launchData.items.length == 0)
@@ -130,18 +136,50 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
});
});
- // Open application window.
- chrome.app.window.create(
- 'gallery.html',
- {
- id: 'gallery',
- minWidth: 160,
- minHeight: 100,
- frame: 'none'
- },
- function(appWindow) {
- appWindow.contentWindow.launchData = launchData;
- appWindow.contentWindow.backgroundComponentsPromise =
- backgroundComponentsPromise;
+ // Close previous window.
+ var closePromise;
+ if (appWindowPromise) {
+ closePromise = appWindowPromise.then(function(appWindow) {
+ return new Promise(function(fulfill) {
+ appWindow.close();
+ appWindow.onClosed.addListener(fulfill);
});
+ });
+ } else {
+ closePromise = Promise.resolve();
+ }
+ var createdWindowPromise = closePromise.then(function() {
+ return new Promise(function(fulfill) {
+ chrome.app.window.create(
+ 'gallery.html',
+ {
+ id: 'gallery',
+ minWidth: 160,
+ minHeight: 100,
+ frame: 'none'
+ },
+ function(appWindow) {
+ appWindow.contentWindow.addEventListener(
+ 'load', fulfill.bind(null, appWindow));
+ });
+ });
+ });
+ appWindowPromise = Promise.all([
+ createdWindowPromise,
+ backgroundComponentsPromise,
+ ]).then(function(args) {
+ args[0].contentWindow.initialize(args[1]);
+ return args[0];
+ });
+
+ // Open entries.
+ Promise.all([
+ appWindowPromise,
+ allEntriesPromise,
+ selectedEntriesPromise
+ ]).then(function(args) {
+ args[0].contentWindow.loadEntries(args[1], args[2]);
+ }).catch(function(error) {
+ console.error(error.stack || error);
+ });
});
« no previous file with comments | « no previous file | ui/file_manager/gallery/js/gallery.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698