diff --git a/frontend/src/app.js b/frontend/src/app.js index ee4b14f..957251f 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -138,7 +138,13 @@ const sendUpdate = ( update ) => { connectedClients[ client ].write( 'data: ' + JSON.stringify( { 'type': 'pos', 'data': currentDetails[ 'pos' ] } ) + '\n\n' ); } } else if ( update === 'playingSong' ) { - currentDetails[ update ][ 'startTime' ] = new Date().getTime(); + if ( !currentDetails[ 'playingSong' ] ) { + currentDetails[ 'playingSong' ] = {}; + } + currentDetails[ 'playingSong' ][ 'startTime' ] = new Date().getTime(); + for ( let client in connectedClients ) { + connectedClients[ client ].write( 'data: ' + JSON.stringify( { 'type': 'pos', 'data': currentDetails[ 'pos' ] } ) + '\n\n' ); + } } else if ( update === 'isPlaying' ) { currentDetails[ 'playingSong' ][ 'startTime' ] = new Date().getTime(); for ( let client in connectedClients ) { diff --git a/frontend/src/appleMusicRoutes.js b/frontend/src/appleMusicRoutes.js index 9fb0af1..f863dcb 100644 --- a/frontend/src/appleMusicRoutes.js +++ b/frontend/src/appleMusicRoutes.js @@ -8,6 +8,8 @@ */ const path = require( 'path' ); +const fs = require( 'fs' ); +const csv = require( 'csv-parser' ); const dialog = require( 'electron' ).dialog; const analyzeFile = ( filepath ) => { @@ -27,6 +29,8 @@ const analyzeFile = ( filepath ) => { } ); } else if ( filepath.includes( '.json' ) ) { resolve( JSON.parse( fs.readFileSync( filepath ) ) ); + } else { + reject( 'NO_CSV_OR_JSON_FILE' ); } } ); } @@ -58,14 +62,22 @@ module.exports = ( app ) => { title: 'Open file with additional data on the songs', filters: [ { - name: 'CSV', extensions: [ '.csv' ], - name: 'JSON', extensions: [ '.json' ] + name: 'All supported files (.csv, .json)', + extensions: [ 'csv', 'json' ], + }, + { + name: 'JSON', + extensions: [ 'json' ], + }, + { + name: 'CSV', + extensions: [ 'csv' ], } - ] - } ); + ], + } )[ 0 ]; analyzeFile( filepath ).then( analyzedFile => { - res.send( analyzeFile ); - } ).catch( err => { + res.send( analyzedFile ); + } ).catch( () => { res.status( 500 ).send( 'no csv / json file' ); } ) } ); diff --git a/frontend/src/client/appleMusic/index.html b/frontend/src/client/appleMusic/index.html index a22b534..27f371c 100644 --- a/frontend/src/client/appleMusic/index.html +++ b/frontend/src/client/appleMusic/index.html @@ -40,18 +40,19 @@