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

Commit c641324

Browse files
committed
print (fix): don't try to print if we are printing already
Change-Id: Icb40c3a21b3e304ccbf487b387d686edaa9fcc32
1 parent a02b858 commit c641324

File tree

3 files changed

+107
-78
lines changed

3 files changed

+107
-78
lines changed

src/js/chromakeying.js

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ let mainImage;
44
let mainImageWidth;
55
let mainImageHeight;
66
let backgroundImage;
7+
let isPrinting = false;
78

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

135-
setTimeout(function () {
136-
$.ajax({
137-
method: 'GET',
138-
url: 'api/print.php',
139-
data: {
140-
filename: filename
141-
},
142-
success: (data) => {
143-
console.log('Picture processed: ', data);
144-
145-
if (data.error) {
146-
console.log('An error occurred: ', data.error);
136+
if (isPrinting) {
137+
console.log('Printing already: ' + isPrinting);
138+
} else {
139+
isPrinting = true;
140+
setTimeout(function () {
141+
$.ajax({
142+
method: 'GET',
143+
url: 'api/print.php',
144+
data: {
145+
filename: filename
146+
},
147+
success: (data) => {
148+
console.log('Picture processed: ', data);
149+
150+
if (data.error) {
151+
console.log('An error occurred: ', data.error);
152+
$('#print_mesg').empty();
153+
$('#print_mesg').html(
154+
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
155+
);
156+
}
157+
158+
setTimeout(function () {
159+
$('#print_mesg').removeClass('modal--show');
160+
if (data.error) {
161+
$('#print_mesg').empty();
162+
$('#print_mesg').html(
163+
'<div class="modal__body"><span>' + i18n('printing') + '</span></div>'
164+
);
165+
}
166+
cb();
167+
isPrinting = false;
168+
}, config.printing_time);
169+
},
170+
error: (jqXHR, textStatus) => {
171+
console.log('An error occurred: ', textStatus);
147172
$('#print_mesg').empty();
148173
$('#print_mesg').html(
149-
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
174+
'<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>'
150175
);
151-
}
152176

153-
setTimeout(function () {
154-
$('#print_mesg').removeClass('modal--show');
155-
if (data.error) {
177+
setTimeout(function () {
178+
$('#print_mesg').removeClass('modal--show');
156179
$('#print_mesg').empty();
157180
$('#print_mesg').html('<div class="modal__body"><span>' + i18n('printing') + '</span></div>');
158-
}
159-
cb();
160-
}, config.printing_time);
161-
},
162-
error: (jqXHR, textStatus) => {
163-
console.log('An error occurred: ', textStatus);
164-
$('#print_mesg').empty();
165-
$('#print_mesg').html('<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>');
166-
167-
setTimeout(function () {
168-
$('#print_mesg').removeClass('modal--show');
169-
$('#print_mesg').empty();
170-
$('#print_mesg').html('<div class="modal__body"><span>' + i18n('printing') + '</span></div>');
171-
cb();
172-
}, 5000);
173-
}
174-
});
175-
}, 1000);
181+
cb();
182+
isPrinting = false;
183+
}, 5000);
184+
}
185+
});
186+
}, 1000);
187+
}
176188
}
177189

178190
function saveImage(cb) {

src/js/core.js

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const photoBooth = (function () {
2222
videoSensor = document.querySelector('#video--sensor');
2323

2424
let timeOut,
25+
isPrinting = false,
2526
takingPic = false,
2627
nextCollageNumber = 0,
2728
currentCollageFile = '',
@@ -617,54 +618,63 @@ const photoBooth = (function () {
617618
};
618619

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

623-
setTimeout(function () {
624-
$.ajax({
625-
method: 'GET',
626-
url: 'api/print.php',
627-
data: {
628-
filename: imageSrc
629-
},
630-
success: (data) => {
631-
console.log('Picture processed: ', data);
632-
633-
if (data.error) {
634-
console.log('An error occurred: ', data.error);
623+
if (isPrinting) {
624+
console.log('Printing already: ' + isPrinting);
625+
} else {
626+
modal.open('#print_mesg');
627+
isPrinting = true;
628+
setTimeout(function () {
629+
$.ajax({
630+
method: 'GET',
631+
url: 'api/print.php',
632+
data: {
633+
filename: imageSrc
634+
},
635+
success: (data) => {
636+
console.log('Picture processed: ', data);
637+
638+
if (data.error) {
639+
console.log('An error occurred: ', data.error);
640+
$('#print_mesg').empty();
641+
$('#print_mesg').html(
642+
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
643+
);
644+
}
645+
646+
setTimeout(function () {
647+
modal.close('#print_mesg');
648+
if (data.error) {
649+
$('#print_mesg').empty();
650+
$('#print_mesg').html(
651+
'<div class="modal__body"><span>' + i18n('printing') + '</span></div>'
652+
);
653+
}
654+
cb();
655+
isPrinting = false;
656+
}, config.printing_time);
657+
},
658+
error: (jqXHR, textStatus) => {
659+
console.log('An error occurred: ', textStatus);
635660
$('#print_mesg').empty();
636661
$('#print_mesg').html(
637-
'<div class="modal__body"><span style="color:red">' + data.error + '</span></div>'
662+
'<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>'
638663
);
639-
}
640664

641-
setTimeout(function () {
642-
modal.close('#print_mesg');
643-
if (data.error) {
665+
setTimeout(function () {
666+
modal.close('#print_mesg');
644667
$('#print_mesg').empty();
645668
$('#print_mesg').html(
646669
'<div class="modal__body"><span>' + i18n('printing') + '</span></div>'
647670
);
648-
}
649-
cb();
650-
}, config.printing_time);
651-
},
652-
error: (jqXHR, textStatus) => {
653-
console.log('An error occurred: ', textStatus);
654-
$('#print_mesg').empty();
655-
$('#print_mesg').html(
656-
'<div class="modal__body"><span style="color:red">' + errormsg + '</span></div>'
657-
);
658-
659-
setTimeout(function () {
660-
modal.close('#print_mesg');
661-
$('#print_mesg').empty();
662-
$('#print_mesg').html('<div class="modal__body"><span>' + i18n('printing') + '</span></div>');
663-
cb();
664-
}, 5000);
665-
}
666-
});
667-
}, 1000);
671+
cb();
672+
isPrinting = false;
673+
}, 5000);
674+
}
675+
});
676+
}, 1000);
677+
}
668678
};
669679

670680
api.deleteImage = function (imageName, cb) {

src/js/photoinit.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
function initPhotoSwipeFromDOM(gallerySelector) {
55
let gallery,
66
ssRunning = false,
7-
ssOnce = false;
7+
ssOnce = false,
8+
isPrinting = false;
89

910
const ssDelay = config.gallery_pictureTime,
1011
ssButtonClass = '.pswp__button--playpause';
@@ -230,11 +231,17 @@ function initPhotoSwipeFromDOM(gallerySelector) {
230231
e.preventDefault();
231232
e.stopPropagation();
232233

233-
const img = gallery.currItem.src.split('\\').pop().split('/').pop();
234+
if (isPrinting) {
235+
console.log('Printing already in progress!');
236+
} else {
237+
isPrinting = true;
238+
const img = gallery.currItem.src.split('\\').pop().split('/').pop();
234239

235-
photoBooth.printImage(img, () => {
236-
gallery.close();
237-
});
240+
photoBooth.printImage(img, () => {
241+
gallery.close();
242+
isPrinting = false;
243+
});
244+
}
238245
});
239246

240247
// Close Gallery while Taking a Picture or Collage

0 commit comments

Comments
 (0)