diff options
author | Florrie <towerofnix@gmail.com> | 2020-07-09 14:40:25 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2020-07-09 16:19:17 -0300 |
commit | 8baf386abdf611acd855e61578f06cf7ac8f014f (patch) | |
tree | 357d36d07df7ce57a78394c942c7baa013ffc4f2 | |
parent | 0e0cb91ffc1e7a28a03428528d437e074145a72e (diff) |
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.
-rw-r--r-- | client.js | 3 | ||||
-rwxr-xr-x | index.js | 2 | ||||
-rw-r--r-- | 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() |