@@ -19,17 +19,30 @@ export default class PlayContextButton extends Button {
1919 [ context : string ] : any
2020 } = { }
2121
22+ #forcedActiveContexts: {
23+ [ context : string ] : boolean
24+ } = { }
25+
2226 constructor ( ) {
2327 super ( )
2428 this . setStatelessImage ( 'images/states/play-context-unknown' )
29+
30+ wrapper . on ( 'playbackContextChanged' , ( ) => {
31+ for ( const context of this . contexts )
32+ if ( wrapper . playbackContext ?. uri === this . #cachedPlayContexts[ context ] ?. uri )
33+ delete this . #forcedActiveContexts[ context ]
34+
35+ for ( const context of this . contexts )
36+ this . #updatePlayContext( context , this . settings [ context ] )
37+ } )
2538 }
2639
2740 async #updatePlayContext( context : string , oldSettings : any = undefined ) {
2841 this . setUnpressable ( context , true )
2942
3043 const badUrl = ! / ^ h t t p s ? : \/ \/ o p e n \. s p o t i f y \. c o m \/ (?: i n t l - [ a - z ] { 2 } \/ ) ? (?: a l b u m | a r t i s t | p l a y l i s t ) \/ [ A - Z a - z 0 - 9 ] { 22 } (?: \/ ) ? (?: \? .* ) ? $ / . test ( this . settings [ context ] . spotify_url )
3144
32- if ( ( ! oldSettings ) || badUrl || this . settings [ context ] . spotify_url !== this . #cachedPlayContexts[ context ] ?. url || ( ! ( oldSettings . show || [ ] ) . every ( ( entry : string ) => entry === 'border ' || ( this . settings [ context ] . show || [ ] ) . includes ( entry ) ) ) || ( ! ( this . settings [ context ] . show || [ ] ) . every ( ( entry : string ) => entry === 'border ' || ( oldSettings . show || [ ] ) . includes ( entry ) ) ) )
45+ if ( ( ! oldSettings ) || badUrl || this . settings [ context ] . spotify_url !== this . #cachedPlayContexts[ context ] ?. url || ( ! ( oldSettings . show || [ ] ) . every ( ( entry : string ) => entry === 'active_border ' || entry === 'inactive_border' || ( this . settings [ context ] . show || [ ] ) . includes ( entry ) ) ) || ( ! ( this . settings [ context ] . show || [ ] ) . every ( ( entry : string ) => entry === 'active_border' || entry === 'inactive_border ' || ( oldSettings . show || [ ] ) . includes ( entry ) ) ) )
3346 this . clearMarquee ( context )
3447
3548 if ( this . settings [ context ] . spotify_url !== this . #cachedPlayContexts[ context ] ?. url || badUrl ) {
@@ -71,7 +84,7 @@ export default class PlayContextButton extends Button {
7184 this . resumeMarquee ( context )
7285
7386 if ( image )
74- await this . setImage ( context , this . processImage ( `data:image/jpeg;base64,${ image } ` , 'none' , this . settings [ context ] . show . includes ( 'border' ) ) )
87+ await this . setImage ( context , this . processImage ( `data:image/jpeg;base64,${ image } ` , 'none' , ( this . settings [ context ] . show . includes ( 'active_border' ) && ( wrapper . playbackContext ?. uri === this . #cachedPlayContexts [ context ] . uri || this . #forcedActiveContexts [ context ] === this . #cachedPlayContexts [ context ] . uri ) ) ? ( wrapper . playbackContext ?. uri === this . #cachedPlayContexts [ context ] . uri ? '#1db954' : '#dab824' ) : ( this . settings [ context ] . show . includes ( 'inactive_border' ) ? '#888888' : null ) ) )
7588 else if ( this . #cachedPlayContexts[ context ] . type === 'local' )
7689 await this . setImage ( context , 'images/states/local' )
7790 else
@@ -86,9 +99,15 @@ export default class PlayContextButton extends Button {
8699 if ( this . #cachedPlayContexts[ context ] ) {
87100 const response = await wrapper . playItem ( this . #cachedPlayContexts[ context ] )
88101
89- if ( response === constants . WRAPPER_RESPONSE_SUCCESS )
102+ if ( response === constants . WRAPPER_RESPONSE_SUCCESS ) {
103+ this . #forcedActiveContexts = { }
104+ this . #forcedActiveContexts[ context ] = this . #cachedPlayContexts[ context ] . uri
105+
106+ for ( const ctx of this . contexts )
107+ setImmediate ( ( ) => this . #updatePlayContext( ctx , this . settings [ ctx ] ) )
108+
90109 return constants . WRAPPER_RESPONSE_SUCCESS_INDICATIVE
91- else
110+ } else
92111 return response
93112 } else
94113 return constants . WRAPPER_RESPONSE_NOT_AVAILABLE
@@ -99,7 +118,7 @@ export default class PlayContextButton extends Button {
99118
100119 if ( ! this . settings [ context ] . show )
101120 await this . setSettings ( context , {
102- show : [ 'title' , 'extra' , 'subtitle' , 'border ' ]
121+ show : [ 'title' , 'extra' , 'subtitle' , 'active_border' , 'inactive_border ']
103122 } )
104123
105124 if ( this . #cachedPlayContexts[ context ] ?. url !== this . settings [ context ] . spotify_url || oldSettings . show ?. length !== this . settings [ context ] . show ?. length || ( oldSettings . show && this . settings [ context ] . show && ( ! oldSettings . show . every ( ( value : any , index : number ) => value === this . settings [ context ] . show [ index ] ) ) ) )
0 commit comments