From 8baf386abdf611acd855e61578f06cf7ac8f014f Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 9 Jul 2020 14:40:25 -0300 Subject: rename handlePlaylistSource & let accept grouplike It's called loadPlaylistOrSource now, and can take a grouplike (which it will process with processSmartPlaylist as usual) instead of a URL to pass to a crawler. This is so that all functionality for loading a playlist can be collected in and accessed through one interface, so that modifications to the way playlists are loaded will be reflected across everywhere that loads a playlist. --- client.js | 3 +-- index.js | 2 +- ui.js | 34 +++++++++++++++++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/client.js b/client.js index 33cc62a..645fe42 100644 --- a/client.js +++ b/client.js @@ -70,8 +70,7 @@ const setupClient = async ({backend, writable, interfacer, appConfig}) => { ' or pass mtui your own playlist.json file!)'), source: ['crawl-local', os.homedir() + '/Music'] } - grouplike = await processSmartPlaylist(grouplike) - appElement.tabber.currentElement.loadGrouplike(grouplike) + await appElement.loadPlaylistOrSource(grouplike, true) root.select(appElement) diff --git a/index.js b/index.js index c40bbb9..4b7654d 100755 --- a/index.js +++ b/index.js @@ -125,7 +125,7 @@ async function main() { const loadPlaylists = async () => { for (const source of playlistSources) { - await appElement.handlePlaylistSource(source, true) + await appElement.loadPlaylistOrSource(source, true) } } diff --git a/ui.js b/ui.js index 04c65c0..41ab4cc 100644 --- a/ui.js +++ b/ui.js @@ -295,8 +295,8 @@ class AppElement extends FocusElement { this.openPlaylistDialog = new OpenPlaylistDialog() this.setupDialog(this.openPlaylistDialog) - this.openPlaylistDialog.on('source selected', source => this.handlePlaylistSource(source)) - this.openPlaylistDialog.on('source selected (new tab)', source => this.handlePlaylistSource(source, true)) + this.openPlaylistDialog.on('source selected', source => this.loadPlaylistOrSource(source)) + this.openPlaylistDialog.on('source selected (new tab)', source => this.loadPlaylistOrSource(source, true)) this.alertDialog = new AlertDialog() this.setupDialog(this.alertDialog) @@ -944,7 +944,7 @@ class AppElement extends FocusElement { openSpecialOrThroughSystem(item) { if (item.url.endsWith('.json')) { - return this.handlePlaylistSource(item.url, true) + return this.loadPlaylistOrSource(item.url, true) /* } else if (item.url.endsWith('.txt')) { if (this.textInfoPane.visible) { @@ -1094,7 +1094,7 @@ class AppElement extends FocusElement { }) } - async handlePlaylistSource(source, newTab = false) { + async loadPlaylistOrSource(sourceOrPlaylist, newTab = false) { if (this.openPlaylistDialog.visible) { this.openPlaylistDialog.close() } @@ -1102,18 +1102,22 @@ class AppElement extends FocusElement { this.alertDialog.showMessage('Opening playlist...', false) let grouplike - try { - grouplike = await this.openPlaylist(source) - } catch (error) { - if (error === 'unknown argument') { - this.alertDialog.showMessage('Could not figure out how to load a playlist from: ' + source) - } else if (typeof error === 'string') { - this.alertDialog.showMessage(error) - } else { - throw error - } + if (typeof sourceOrPlaylist === 'object' && isGroup(sourceOrPlaylist) || sourceOrPlaylist.source) { + grouplike = sourceOrPlaylist + } else { + try { + grouplike = await this.openPlaylist(sourceOrPlaylist) + } catch (error) { + if (error === 'unknown argument') { + this.alertDialog.showMessage('Could not figure out how to load a playlist from: ' + sourceOrPlaylist) + } else if (typeof error === 'string') { + this.alertDialog.showMessage(error) + } else { + throw error + } - return + return + } } this.alertDialog.close() -- cgit 1.3.0-6-gf8a5