11/* eslint n/no-unsupported-features/node-builtins: "off" */
22/* globals initPhotoSwipeFromDOM initRemoteBuzzerFromDOM processChromaImage remoteBuzzerClient rotaryController globalGalleryHandle photoboothTools photoboothPreview virtualKeyboard */
33
4+ /* global createScreensaver */
45const photoBooth = ( function ( ) {
56 const PhotoStyle = {
67 PHOTO : 'photo' ,
@@ -40,6 +41,12 @@ const photoBooth = (function () {
4041 loaderMessage = loader . find ( '.stage-message' ) ,
4142 loaderImage = loader . find ( '.stage-image' ) ,
4243 resultPage = $ ( '.stage[data-stage="result"]' ) ,
44+ screensaverOverlay = $ ( '#screensaver-overlay' ) ,
45+ screensaverVideo = $ ( '#screensaver-video' ) ,
46+ screensaverImage = $ ( '#screensaver-image' ) ,
47+ screensaverTextTop = $ ( '#screensaver-text-top' ) ,
48+ screensaverTextCenter = $ ( '#screensaver-text-center' ) ,
49+ screensaverTextBottom = $ ( '#screensaver-text-bottom' ) ,
4350 previewIpcam = $ ( '#preview--ipcam' ) ,
4451 previewVideo = $ ( '#preview--video' ) ,
4552 previewFramePicture = $ ( '#previewframe--picture' ) ,
@@ -58,10 +65,20 @@ const photoBooth = (function () {
5865 config . preview . asBackground &&
5966 config . preview . mode === PreviewMode . DEVICE . valueOf ( ) &&
6067 ( ( config . commands . preview && ! config . preview . bsm ) || ! config . commands . preview ) ,
61- timeToLive = config . picture . time_to_live * 1000 ,
68+ timeToLive = parseInt ( config . picture . time_to_live , 10 ) * 1000 ,
6269 continuousCollageTime = config . collage . continuous_time * 1000 ,
6370 retryTimeout = config . picture . retry_timeout * 1000 ,
64- notificationTimeout = config . ui . notification_timeout * 1000 ;
71+ notificationTimeout = config . ui . notification_timeout * 1000 ,
72+ screensaverMode = config . screensaver . mode ,
73+ screensaverEnabled =
74+ config . screensaver . enabled &&
75+ config . screensaver . timeout_minutes > 0 &&
76+ ( screensaverMode === 'gallery' ||
77+ screensaverMode === 'folder' ||
78+ ( screensaverMode === 'video' ? ! ! config . screensaver . video_source : ! ! config . screensaver . image_source ) ) ,
79+ screensaverTimeoutMs = ( config . screensaver . timeout_minutes || 0 ) * 60000 ,
80+ screensaverSwitchMs = ( config . screensaver . switch_minutes || 1 ) * 60000 ,
81+ urlSafe = ( src ) => ( src ? encodeURI ( src ) : '' ) ;
6582
6683 let timeOut ,
6784 chromaFile = '' ,
@@ -86,7 +103,7 @@ const photoBooth = (function () {
86103 } ;
87104
88105 api . resetTimeOut = function ( ) {
89- if ( timeToLive == 0 ) {
106+ if ( timeToLive === 0 ) {
90107 return ;
91108 }
92109 clearTimeout ( timeOut ) ;
@@ -137,8 +154,33 @@ const photoBooth = (function () {
137154 rotaryController . focusSet ( startPage ) ;
138155
139156 initPhotoSwipeFromDOM ( '#galimages' ) ;
157+
158+ api . screensaver . resetTimer ( ) ;
159+
160+ const params = new URLSearchParams ( window . location . search ) ;
161+ if ( params . has ( 'screensaverPreview' ) ) {
162+ api . screensaver . show ( true ) ;
163+ }
140164 } ;
141165
166+ api . screensaver = createScreensaver ( {
167+ config,
168+ environment,
169+ startPage,
170+ overlay : screensaverOverlay ,
171+ videoEl : screensaverVideo ,
172+ imageEl : screensaverImage ,
173+ textTop : screensaverTextTop ,
174+ textCenter : screensaverTextCenter ,
175+ textBottom : screensaverTextBottom ,
176+ screensaverEnabled,
177+ screensaverMode,
178+ screensaverTimeoutMs,
179+ screensaverSwitchMs,
180+ urlSafe,
181+ photoboothTools
182+ } ) ;
183+
142184 api . navbar = {
143185 open : function ( ) {
144186 filternav . addClass ( 'sidenav--open' ) ;
@@ -504,6 +546,7 @@ const photoBooth = (function () {
504546 videoBackground . hide ( ) ;
505547 startPage . removeClass ( 'stage--active' ) ;
506548 loader . addClass ( 'stage--active' ) ;
549+ api . screensaver . hide ( ) ;
507550
508551 if ( config . get_request . countdown ) {
509552 let getMode ;
@@ -1254,6 +1297,8 @@ const photoBooth = (function () {
12541297 if ( config . commands . post_photo ) {
12551298 api . shellCommand ( 'post-command' , filename ) ;
12561299 }
1300+
1301+ api . screensaver . resetTimer ( ) ;
12571302 } ;
12581303
12591304 api . addImage = function ( imageName ) {
@@ -1470,6 +1515,17 @@ const photoBooth = (function () {
14701515 rotaryController . focusSet ( startPage ) ;
14711516 } ) ;
14721517
1518+ if ( screensaverEnabled ) {
1519+ $ ( document ) . on ( 'click touchstart keydown mousemove' , function ( ) {
1520+ api . screensaver . resetTimer ( ) ;
1521+ } ) ;
1522+
1523+ screensaverOverlay . on ( 'click touchstart' , function ( e ) {
1524+ e . preventDefault ( ) ;
1525+ api . screensaver . resetTimer ( ) ;
1526+ } ) ;
1527+ }
1528+
14731529 $ ( '.cups-button' ) . on ( 'click' , function ( ev ) {
14741530 ev . preventDefault ( ) ;
14751531
0 commit comments