@@ -47,6 +47,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
4747 constructor ( props ) {
4848 super ( props ) ;
4949 bindAll ( this , [
50+ 'getProjectThumbnail' ,
5051 'leavePageConfirm' ,
5152 'tryToAutoSave'
5253 ] ) ;
@@ -57,6 +58,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
5758 // but then it'd be hard to turn this listening off in our tests
5859 window . onbeforeunload = e => this . leavePageConfirm ( e ) ;
5960 }
61+ this . props . onSetProjectThumbnailer ( this . getProjectThumbnail ) ;
6062 }
6163 componentDidUpdate ( prevProps ) {
6264 if ( this . props . projectChanged && ! prevProps . projectChanged ) {
@@ -104,6 +106,8 @@ const ProjectSaverHOC = function (WrappedComponent) {
104106 // i.e. if another of this component has been mounted before this one gets unmounted
105107 // which happens when going from project to editor view.
106108 // window.onbeforeunload = undefined; // eslint-disable-line no-undefined
109+ // Remove project thumbnailer function since the components are unmounting
110+ this . props . onSetProjectThumbnailer ( null ) ;
107111 }
108112 leavePageConfirm ( e ) {
109113 if ( this . props . projectChanged ) {
@@ -282,20 +286,25 @@ const ProjectSaverHOC = function (WrappedComponent) {
282286 */
283287 storeProjectThumbnail ( projectId ) {
284288 try {
285- this . props . vm . postIOData ( 'video' , { forceTransparentPreview : true } ) ;
286- this . props . vm . renderer . requestSnapshot ( dataURI => {
287- this . props . vm . postIOData ( 'video' , { forceTransparentPreview : false } ) ;
288- this . props . onUpdateProjectThumbnail (
289- projectId , dataURItoBlob ( dataURI ) ) ;
289+ this . getProjectThumbnail ( dataURI => {
290+ this . props . onUpdateProjectThumbnail ( projectId , dataURItoBlob ( dataURI ) ) ;
290291 } ) ;
291- this . props . vm . renderer . draw ( ) ;
292292 } catch ( e ) {
293293 log . error ( 'Project thumbnail save error' , e ) ;
294294 // This is intentionally fire/forget because a failure
295295 // to save the thumbnail is not vitally important to the user.
296296 }
297297 }
298298
299+ getProjectThumbnail ( callback ) {
300+ this . props . vm . postIOData ( 'video' , { forceTransparentPreview : true } ) ;
301+ this . props . vm . renderer . requestSnapshot ( dataURI => {
302+ this . props . vm . postIOData ( 'video' , { forceTransparentPreview : false } ) ;
303+ callback ( dataURI ) ;
304+ } ) ;
305+ this . props . vm . renderer . draw ( ) ;
306+ }
307+
299308 render ( ) {
300309 const {
301310 /* eslint-disable no-unused-vars */
@@ -318,6 +327,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
318327 onProjectError,
319328 onRemixing,
320329 onSetProjectUnchanged,
330+ onSetProjectThumbnailer,
321331 onShowAlert,
322332 onShowCopySuccessAlert,
323333 onShowRemixSuccessAlert,
@@ -378,7 +388,8 @@ const ProjectSaverHOC = function (WrappedComponent) {
378388 } ;
379389 ProjectSaverComponent . defaultProps = {
380390 autoSaveIntervalSecs : 120 ,
381- onRemixing : ( ) => { }
391+ onRemixing : ( ) => { } ,
392+ onSetProjectThumbnailer : ( ) => { }
382393 } ;
383394 const mapStateToProps = ( state , ownProps ) => {
384395 const loadingState = state . scratchGui . projectState . loadingState ;
0 commit comments