Skip to content

Commit

Permalink
Merge pull request GoogleChrome#359 from beaufortfrancois/addGalleryW…
Browse files Browse the repository at this point in the history
…atch

[media-gallery] Added Gallery Watch feature
  • Loading branch information
benfredwells committed Feb 15, 2015
2 parents 591fc9c + 65f54db commit eb038f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samples/media-gallery/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Media Gallery Sample",
"version": "0.2.4",
"version": "0.2.5",
"manifest_version": 2,
"description": "Used to test Media Gallery API",
"permissions": [{
Expand Down
19 changes: 19 additions & 0 deletions samples/media-gallery/media-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ function scanGalleries(fs) {
gGalleryData[gGalleryIndex] = new GalleryData(mData.galleryId);
gGalleryReader = fs.root.createReader();
gGalleryReader.readEntries(scanGallery, errorPrintFactory('readEntries'));

chrome.mediaGalleries.addGalleryWatch(mData.galleryId, onGalleryWatchAdded);
}

function getGalleriesInfo(results) {
Expand All @@ -234,9 +236,23 @@ function getGalleriesInfo(results) {
else {
document.getElementById("status").innerText = 'No galleries found';
document.getElementById("read-button").disabled = "disabled";
clearList();
}
}

function onGalleryChanged(result) {
if (result.type === 'contents_changed') {
// read galleries again if change was detected.
document.getElementById('read-button').click();
}
}

function onGalleryWatchAdded() {
if (chrome.runtime.lastError) {
console.log("Gallery watch not added", chrome.runtime.lastError.message);
}
}

window.addEventListener("load", function() {
// __MGA__bRestart is set in the launcher code to indicate that the app was
// restarted instead of being normally launched
Expand Down Expand Up @@ -264,6 +280,7 @@ window.addEventListener("load", function() {
document.getElementById('read-button').addEventListener("click", function () {
clearContentDiv();
clearList();
gGalleryIndex = 0;
if (gGalleryArray.length > 0) {
scanGalleries(gGalleryArray[0]);
}
Expand Down Expand Up @@ -295,3 +312,5 @@ chrome.mediaGalleries.onScanProgress.addListener(function(details) {
if (details.type != 'start')
document.getElementById('scan-button').innerHTML = 'Search for Galleries';
});

chrome.mediaGalleries.onGalleryChanged.addListener(onGalleryChanged);

0 comments on commit eb038f4

Please sign in to comment.