Skip to content

Commit

Permalink
Added exception processing to device-browser SelectSource method.
Browse files Browse the repository at this point in the history
  • Loading branch information
thlucas1 committed Oct 22, 2024
1 parent d258e00 commit 6985d23
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/sections/device-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { MediaPlayer } from '../model/media-player';
import { formatTitleInfo } from '../utils/media-browser-utils';
import { ISpotifyConnectDevice } from '../types/spotifyplus/spotify-connect-device';

// debug logging.
import Debug from 'debug/src/browser.js';
import { DEBUG_APP_NAME } from '../constants';
const debuglog = Debug(DEBUG_APP_NAME + ":device-browser");


@customElement("spc-device-browser")
export class DeviceBrowser extends FavBrowserBase {
Expand Down Expand Up @@ -138,25 +143,53 @@ export class DeviceBrowser extends FavBrowserBase {
*/
protected override onItemSelected = (args: CustomEvent) => {

if (debuglog.enabled) {
debuglog("onItemSelected - device item selected:\n%s",
JSON.stringify(args.detail, null, 2),
);
}

const mediaItem = args.detail;
this.SelectSource(mediaItem);

};
}


/**
* Calls the mediaplayer select_source service to select a source.
*
* @param mediaItem The medialist item that was selected.
*/
private async SelectSource(mediaItem: ISpotifyConnectDevice) {
private async SelectSource(mediaItem: ISpotifyConnectDevice): Promise<void> {

// call service to select the source.
await this.store.mediaControlService.select_source(this.player, mediaItem.Name || '');

}
try {

// show progress indicator.
this.progressShow();

// select the source.
await this.store.mediaControlService.select_source(this.player, mediaItem.Name || '');

// show player section.
this.store.card.SetSection(Section.PLAYER);

}
catch (error) {

// set error message and reset scroll position to zero so the message is displayed.
this.alertErrorSet("Could not select source. " + (error as Error).message);
this.mediaBrowserContentElement.scrollTop = 0;

}
finally {

// hide progress indicator.
this.progressHide();

}

}


/**
Expand Down

0 comments on commit 6985d23

Please sign in to comment.