@@ -44,6 +44,7 @@ export default class SoundscapesPlugin extends Plugin {
44
44
pauseButton : HTMLButtonElement ;
45
45
nextButton : HTMLButtonElement ;
46
46
previousButton : HTMLButtonElement ;
47
+ changeSoundscapeSelect : HTMLSelectElement ;
47
48
nowPlayingRoot : HTMLDivElement ;
48
49
nowPlaying : HTMLDivElement ;
49
50
volumeMutedIcon : HTMLDivElement ;
@@ -341,26 +342,47 @@ export default class SoundscapesPlugin extends Plugin {
341
342
* Create all the UI elements
342
343
*/
343
344
createControls ( ) {
345
+ // Previous Button
344
346
this . previousButton = this . statusBarItem . createEl ( "button" , {
345
347
cls : "soundscapesroot-previousbutton" ,
346
348
} ) ;
347
349
setIcon ( this . previousButton , "skip-back" ) ;
348
350
this . previousButton . onclick = ( ) => this . previous ( ) ;
349
351
352
+ // Play Button
350
353
this . playButton = this . statusBarItem . createEl ( "button" , { } ) ;
351
354
setIcon ( this . playButton , "play" ) ;
352
355
this . playButton . onclick = ( ) => this . play ( ) ;
353
356
357
+ // Pause Button
354
358
this . pauseButton = this . statusBarItem . createEl ( "button" , { } ) ;
355
359
setIcon ( this . pauseButton , "pause" ) ;
356
360
this . pauseButton . onclick = ( ) => this . pause ( ) ;
357
361
362
+ // Next Button
358
363
this . nextButton = this . statusBarItem . createEl ( "button" , {
359
364
cls : "soundscapesroot-nextbutton" ,
360
365
} ) ;
361
366
setIcon ( this . nextButton , "skip-forward" ) ;
362
367
this . nextButton . onclick = ( ) => this . next ( ) ;
363
368
369
+ // Change Soundscape Button
370
+ const changeSoundscapeButton = this . statusBarItem . createEl ( "button" , {
371
+ cls : "soundscapesroot-changesoundscapebutton" ,
372
+ } ) ;
373
+ setIcon ( changeSoundscapeButton , "list-music" ) ;
374
+ this . changeSoundscapeSelect = changeSoundscapeButton . createEl (
375
+ "select" ,
376
+ {
377
+ cls : "soundscapesroot-changesoundscapeselect" ,
378
+ attr : {
379
+ id : "soundscapesroot-changesoundscapeselect" ,
380
+ } ,
381
+ }
382
+ ) ;
383
+ this . populateChangeSoundscapeButton ( ) ;
384
+
385
+ // Now Playing
364
386
this . nowPlayingRoot = this . statusBarItem . createEl ( "div" , {
365
387
cls : "soundscapesroot-nowplaying" ,
366
388
} ) ;
@@ -369,6 +391,7 @@ export default class SoundscapesPlugin extends Plugin {
369
391
} ) ;
370
392
this . toggleNowPlayingScroll ( ) ;
371
393
394
+ // Volume control
372
395
const volumeIcons = this . statusBarItem . createEl ( "div" , {
373
396
cls : "soundscapesroot-volumeIcons" ,
374
397
} ) ;
@@ -405,6 +428,45 @@ export default class SoundscapesPlugin extends Plugin {
405
428
) ;
406
429
}
407
430
431
+ /**
432
+ * Populates the dropdown on the miniplayer with all available soundscapes
433
+ */
434
+ populateChangeSoundscapeButton ( ) {
435
+ this . changeSoundscapeSelect . replaceChildren ( ) ;
436
+
437
+ Object . values ( SOUNDSCAPES ) . forEach ( ( soundscape ) => {
438
+ this . changeSoundscapeSelect . createEl ( "option" , {
439
+ text : soundscape . name ,
440
+ value : soundscape . id ,
441
+ } ) ;
442
+ } ) ;
443
+
444
+ this . settings . customSoundscapes . forEach ( ( customSoundscape ) => {
445
+ if ( customSoundscape . tracks . length > 0 ) {
446
+ this . changeSoundscapeSelect . createEl ( "option" , {
447
+ text : customSoundscape . name ,
448
+ value : `${ SOUNDSCAPE_TYPE . CUSTOM } _${ customSoundscape . id } ` ,
449
+ } ) ;
450
+ }
451
+ } ) ;
452
+
453
+ this . changeSoundscapeSelect . createEl ( "option" , {
454
+ text : "My Music" ,
455
+ value : SOUNDSCAPE_TYPE . MY_MUSIC ,
456
+ } ) ;
457
+
458
+ this . changeSoundscapeSelect . value = this . settings . soundscape ;
459
+
460
+ this . changeSoundscapeSelect . addEventListener (
461
+ "change" ,
462
+ ( event : Event ) => {
463
+ this . changeSoundscape (
464
+ ( event ?. target as HTMLSelectElement ) . value
465
+ ) ;
466
+ }
467
+ ) ;
468
+ }
469
+
408
470
/******************************************************************************************************************/
409
471
//#endregion Create UI Elements
410
472
/******************************************************************************************************************/
@@ -593,6 +655,30 @@ export default class SoundscapesPlugin extends Plugin {
593
655
}
594
656
}
595
657
658
+ /**
659
+ * Changes the currently playing soundscape and triggers other downstream side effects
660
+ * @param soundscape
661
+ */
662
+ changeSoundscape ( soundscape : string ) {
663
+ this . settings . soundscape = soundscape ;
664
+
665
+ if ( this . settings . soundscape . startsWith ( `${ SOUNDSCAPE_TYPE . CUSTOM } _` ) ) {
666
+ this . currentTrackIndex = 0 ;
667
+ }
668
+
669
+ // When we select MY_MUSIC, force a re-index
670
+ // Also show the ribbon button!
671
+ if ( this . settings . soundscape === SOUNDSCAPE_TYPE . MY_MUSIC ) {
672
+ this . indexMusicLibrary ( ) ;
673
+ this . ribbonButton . show ( ) ;
674
+ } else {
675
+ this . ribbonButton . hide ( ) ;
676
+ }
677
+
678
+ this . onSoundscapeChange ( ) ;
679
+ this . saveSettings ( ) ;
680
+ }
681
+
596
682
/******************************************************************************************************************/
597
683
//#endregion Control Player
598
684
/******************************************************************************************************************/
@@ -769,6 +855,9 @@ export default class SoundscapesPlugin extends Plugin {
769
855
this . localPlayer . pause ( ) ; // Edge Case: When switching from MyMusic to Youtube, the youtube video keeps playing
770
856
}
771
857
858
+ // Keep miniplayer's soundscape selection button up to date
859
+ this . changeSoundscapeSelect . value = this . settings . soundscape ;
860
+
772
861
this . saveSettings ( ) ;
773
862
}
774
863
0 commit comments