function isUpdated(dirname, image) {

	return new Promise((resolve, reject) => {
		checkIfFileExists(dirname, 'last.png').then(function(result) {

			if(result == true) {

				//read last.png and see if the photos are the same
				cs.readFile('screenshots/' + dirname + '/last.png', function(data) {
					
					//console.log(data);

					if(data == image) {
						console.log('imaginea e la fel');
						return resolve(false);
					} else {
						console.log('imaginea nu e la fel');

						//update last.png

						cs.deleteFile('screenshots/' + dirname + '/last.png', function() {
							cs.getFile('screenshots/' + dirname + '/last.png', {create: true, exclusive: true}, function() {
								cs.write('screenshots/' + dirname + '/last.png', 'image/png', image, {create: false});
							});
						});
						

						lastPhoto = data;
						currentPhoto = image;

						chrome.browserAction.setBadgeText({text: '!'});

						resolve(true);
					}
					

				}); 

			} else { 
				//create last.png image

				console.log('cream last.png');
				cs.getFile('screenshots/' + dirname + '/last.png', {create: true, exclusive: true}, function() {
					cs.write('screenshots/' + dirname + '/last.png', 'image/png', image, {create: false});
				});
				resolve(true);
			}
		});
	});
}
/**
*	Checks if a page is updated
* @param: dirname - specific directory for followed url
* @param: image - base64 encoded screenshot of the page. 
* @return: true if the page is updated, false otherwise. The page is updated if current image is different from "last.png" image. If the image is different we update last.png with the new source
*/
Checks if a page is updated
Checks if a page is updated
function isUpdated(dirname, image) {
	return new Promise((resolve, reject) => {
		checkIfFileExists(dirname, 'last.png').then(function(result) {
			if(result == true) {
				cs.readFile('screenshots/' + dirname + '/last.png', function(data) {
					if(data == image) {
						console.log('imaginea e la fel');
						return resolve(false);
					} else {
						console.log('imaginea nu e la fel');
						cs.deleteFile('screenshots/' + dirname + '/last.png', function() {
							cs.getFile('screenshots/' + dirname + '/last.png', {create: true, exclusive: true}, function() {
								cs.write('screenshots/' + dirname + '/last.png', 'image/png', image, {create: false});
							});
						});
						lastPhoto = data;
						currentPhoto = image;
						chrome.browserAction.setBadgeText({text: '!'});
						resolve(true);
					}
				}); 
			} else { 
				console.log('cream last.png');
				cs.getFile('screenshots/' + dirname + '/last.png', {create: true, exclusive: true}, function() {
					cs.write('screenshots/' + dirname + '/last.png', 'image/png', image, {create: false});
				});
				resolve(true);
			}
		});
	});
}
function isUpdated ( dirname , image ) { return new Promise ( ( resolve , reject ) => { checkIfFileExists ( dirname , 'last.png' ) . then ( function ( result ) { if ( result == true ) { cs . readFile ( 'screenshots/' + dirname + '/last.png' , function ( data ) { if ( data == image ) { console . log ( 'imaginea e la fel' ) ; return resolve ( false ) ; } else { console . log ( 'imaginea nu e la fel' ) ; cs . deleteFile ( 'screenshots/' + dirname + '/last.png' , function ( ) { cs . getFile ( 'screenshots/' + dirname + '/last.png' , { create : true , exclusive : true } , function ( ) { cs . write ( 'screenshots/' + dirname + '/last.png' , 'image/png' , image , { create : false } ) ; } ) ; } ) ; lastPhoto = data ; currentPhoto = image ; chrome . browserAction . setBadgeText ( { text : '!' } ) ; resolve ( true ) ; } } ) ; } else { console . log ( 'cream last.png' ) ; cs . getFile ( 'screenshots/' + dirname + '/last.png' , { create : true , exclusive : true } , function ( ) { cs . write ( 'screenshots/' + dirname + '/last.png' , 'image/png' , image , { create : false } ) ; } ) ; resolve ( true ) ; } } ) ; } ) ; }
Checks if a page is updated
Checks if a page is updated
//read last.png and see if the photos are the same //console.log(data); //update last.png //create last.png image