diff --git a/src/components/playback/mediasession.js b/src/components/playback/mediasession.js index 2478c52d6e..b75fa69a8c 100644 --- a/src/components/playback/mediasession.js +++ b/src/components/playback/mediasession.js @@ -1,5 +1,6 @@ import playbackManager from 'playbackManager'; import nowPlayingHelper from 'nowPlayingHelper'; +import shell from 'shell'; import events from 'events'; /* eslint-disable indent */ @@ -127,8 +128,7 @@ import events from 'events'; }); } else { const itemImageUrl = seriesImageUrl(item, { maxHeight: 3000 }) || imageUrl(item, { maxHeight: 3000 }); - - window.NativeShell.updateMediaSession({ + shell.updateMediaSession({ action: eventName, isLocalPlayer: isLocalPlayer, itemId: itemId, @@ -182,7 +182,7 @@ import events from 'events'; /* eslint-disable-next-line compat/compat */ navigator.mediaSession.metadata = null; } else { - window.NativeShell.hideMediaSession(); + shell.hideMediaSession(); } } diff --git a/src/scripts/fileDownloader.js b/src/scripts/fileDownloader.js index f4179dcef8..c99a6c3e35 100644 --- a/src/scripts/fileDownloader.js +++ b/src/scripts/fileDownloader.js @@ -1,11 +1,8 @@ import multiDownload from 'multi-download'; +import shell from 'shell'; export function download(items) { - if (window.NativeShell) { - items.map(function (item) { - window.NativeShell.downloadFile(item); - }); - } else { + if (!shell.downloadFiles(items)) { multiDownload(items.map(function (item) { return item.url; })); diff --git a/src/scripts/shell.js b/src/scripts/shell.js index e42c7792a0..3b3635c7f4 100644 --- a/src/scripts/shell.js +++ b/src/scripts/shell.js @@ -1,20 +1,43 @@ // TODO: This seems like a good candidate for deprecation export default { - openUrl: function (url, target) { + enableFullscreen: function() { + window.NativeShell?.enableFullscreen(); + }, + disableFullscreen: function() { + window.NativeShell?.disableFullscreen(); + }, + openUrl: function(url, target) { if (window.NativeShell) { window.NativeShell.openUrl(url, target); } else { window.open(url, target || '_blank'); } }, - enableFullscreen: function () { - if (window.NativeShell) { - window.NativeShell.enableFullscreen(); - } + updateMediaSession(mediaInfo) { + window.NativeShell?.updateMediaSession(mediaInfo); }, - disableFullscreen: function () { + hideMediaSession() { + window.NativeShell?.hideMediaSession(); + }, + /** + * Notify the NativeShell about volume level changes. + * Useful for e.g. remote playback. + */ + updateVolumeLevel(volume) { + window.NativeShell?.updateVolumeLevel(volume); + }, + /** + * Download specified files with NativeShell if possible + * + * @returns true on success + */ + downloadFiles(items) { if (window.NativeShell) { - window.NativeShell.disableFullscreen(); + items.map(function(item) { + window.NativeShell.downloadFile(item); + }); + return true; } + return false; } };