1- import React from 'react' ;
1+ import React , { useState } from 'react' ;
22import classnames from 'classnames' ;
33
44import ProcessingIcon from '../images/logo-processing.svg' ;
55
6- import * as css from './CopyButton.module.css' ;
6+ import * as css from './OpenWithButton.module.css' ;
7+
8+ const OpenWithButton = ( { pdes } ) => {
9+ const main = pdes [ 0 ]
10+ let sketchURL = `pde://sketch/base64/${ stringToBase64 ( main . code ) } ?pde=`
11+ for ( let pde of pdes ) {
12+ if ( pde === main ) continue
13+ sketchURL += `${ pde . name } :${ stringToBase64 ( pde . code ) } ,`
14+ }
15+ const [ showInstructions , setShowInstructions ] = useState ( false )
716
8- const OpenWithButton = ( { text } ) => {
917 return (
1018 < a
11- href = { `pde://sketch/base64/ ${ stringToBase64 ( text ) } ` }
19+ href = { sketchURL }
1220 type = "button"
1321 className = { classnames ( css . root ) }
22+ onClick = { ( ) => setShowInstructions ( true ) }
1423 >
1524 < ProcessingIcon /> { 'Open With Processing' }
25+ { showInstructions && (
26+ < div className = { classnames ( css . instructions ) } >
27+ < p > If this did not open Processing, make sure you have it installed and opened at least once.</ p >
28+ < p > Currently only versions of Processing later than 4.4 are supported</ p >
29+ < a href = "https://www.processing.org/download/" target = "_black" > Download Processing</ a >
30+ </ div >
31+ ) }
1632 </ a >
1733 )
1834}
@@ -23,5 +39,5 @@ function stringToBase64(str) {
2339 if ( typeof Buffer !== 'undefined' ) {
2440 return Buffer . from ( str ) . toString ( 'base64' ) ;
2541 }
26- return btoa ( str ) ;
27- }
42+ return btoa ( str )
43+ }
0 commit comments