Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
print (fix): don't try to print if we are printing already
Browse files Browse the repository at this point in the history
Change-Id: Icb40c3a21b3e304ccbf487b387d686edaa9fcc32
  • Loading branch information
andi34 committed Sep 16, 2020
1 parent a02b858 commit c641324
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 78 deletions.
82 changes: 47 additions & 35 deletions src/js/chromakeying.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let mainImage;
let mainImageWidth;
let mainImageHeight;
let backgroundImage;
let isPrinting = false;

function greenToTransparency(imageIn, imageOut) {
for (let y = 0; y < imageIn.getHeight(); y++) {
Expand Down Expand Up @@ -132,47 +133,58 @@ function calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) {
function printImage(filename, cb) {
const errormsg = i18n('error');

setTimeout(function () {
$.ajax({
method: 'GET',
url: 'api/print.php',
data: {
filename: filename
},
success: (data) => {
console.log('Picture processed: ', data);

if (data.error) {
console.log('An error occurred: ', data.error);
if (isPrinting) {
console.log('Printing already: ' + isPrinting);
} else {
isPrinting = true;
setTimeout(function () {
$.ajax({
method: 'GET',
url: 'api/print.php',
data: {
filename: filename
},
success: (data) => {
console.log('Picture processed: ', data);

if (data.error) {
console.log('An error occurred: ', data.error);
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
);
}

setTimeout(function () {
$('#print_mesg').removeClass('modal--show');
if (data.error) {
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span>' + i18n('printing') + '</span></div>'
);
}
cb();
isPrinting = false;
}, config.printing_time);
},
error: (jqXHR, textStatus) => {
console.log('An error occurred: ', textStatus);
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
'<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>'
);
}

setTimeout(function () {
$('#print_mesg').removeClass('modal--show');
if (data.error) {
setTimeout(function () {
$('#print_mesg').removeClass('modal--show');
$('#print_mesg').empty();
$('#print_mesg').html('<div class="modal__body"><span>' + i18n('printing') + '</span></div>');
}
cb();
}, config.printing_time);
},
error: (jqXHR, textStatus) => {
console.log('An error occurred: ', textStatus);
$('#print_mesg').empty();
$('#print_mesg').html('<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>');

setTimeout(function () {
$('#print_mesg').removeClass('modal--show');
$('#print_mesg').empty();
$('#print_mesg').html('<div class="modal__body"><span>' + i18n('printing') + '</span></div>');
cb();
}, 5000);
}
});
}, 1000);
cb();
isPrinting = false;
}, 5000);
}
});
}, 1000);
}
}

function saveImage(cb) {
Expand Down
86 changes: 48 additions & 38 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const photoBooth = (function () {
videoSensor = document.querySelector('#video--sensor');

let timeOut,
isPrinting = false,
takingPic = false,
nextCollageNumber = 0,
currentCollageFile = '',
Expand Down Expand Up @@ -617,54 +618,63 @@ const photoBooth = (function () {
};

api.printImage = function (imageSrc, cb) {
modal.open('#print_mesg');
const errormsg = i18n('error');

setTimeout(function () {
$.ajax({
method: 'GET',
url: 'api/print.php',
data: {
filename: imageSrc
},
success: (data) => {
console.log('Picture processed: ', data);

if (data.error) {
console.log('An error occurred: ', data.error);
if (isPrinting) {
console.log('Printing already: ' + isPrinting);
} else {
modal.open('#print_mesg');
isPrinting = true;
setTimeout(function () {
$.ajax({
method: 'GET',
url: 'api/print.php',
data: {
filename: imageSrc
},
success: (data) => {
console.log('Picture processed: ', data);

if (data.error) {
console.log('An error occurred: ', data.error);
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
);
}

setTimeout(function () {
modal.close('#print_mesg');
if (data.error) {
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span>' + i18n('printing') + '</span></div>'
);
}
cb();
isPrinting = false;
}, config.printing_time);
},
error: (jqXHR, textStatus) => {
console.log('An error occurred: ', textStatus);
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
'<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>'
);
}

setTimeout(function () {
modal.close('#print_mesg');
if (data.error) {
setTimeout(function () {
modal.close('#print_mesg');
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span>' + i18n('printing') + '</span></div>'
);
}
cb();
}, config.printing_time);
},
error: (jqXHR, textStatus) => {
console.log('An error occurred: ', textStatus);
$('#print_mesg').empty();
$('#print_mesg').html(
'<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>'
);

setTimeout(function () {
modal.close('#print_mesg');
$('#print_mesg').empty();
$('#print_mesg').html('<div class="modal__body"><span>' + i18n('printing') + '</span></div>');
cb();
}, 5000);
}
});
}, 1000);
cb();
isPrinting = false;
}, 5000);
}
});
}, 1000);
}
};

api.deleteImage = function (imageName, cb) {
Expand Down
17 changes: 12 additions & 5 deletions src/js/photoinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
function initPhotoSwipeFromDOM(gallerySelector) {
let gallery,
ssRunning = false,
ssOnce = false;
ssOnce = false,
isPrinting = false;

const ssDelay = config.gallery_pictureTime,
ssButtonClass = '.pswp__button--playpause';
Expand Down Expand Up @@ -230,11 +231,17 @@ function initPhotoSwipeFromDOM(gallerySelector) {
e.preventDefault();
e.stopPropagation();

const img = gallery.currItem.src.split('\\').pop().split('/').pop();
if (isPrinting) {
console.log('Printing already in progress!');
} else {
isPrinting = true;
const img = gallery.currItem.src.split('\\').pop().split('/').pop();

photoBooth.printImage(img, () => {
gallery.close();
});
photoBooth.printImage(img, () => {
gallery.close();
isPrinting = false;
});
}
});

// Close Gallery while Taking a Picture or Collage
Expand Down

0 comments on commit c641324

Please sign in to comment.