'use strict'

const {app, BrowserWindow, TouchBar} = require('electron')
const {TouchBarButton, TouchBarLabel, TouchBarSpacer} = TouchBar

module.exports = function touchBarMenu(window, soundcloud) {

  const nextTrack = new TouchBarButton({
    label: '⏭',
    click: () => {
      soundcloud.nextTrack()
    }
  })

  const previousTrack = new TouchBarButton({
    label: '⏮',
    click: () => {
      soundcloud.previousTrack()
    }
  })

  const playPause = new TouchBarButton({
    label: '⏯',
    click: () => {
      soundcloud.playPause()
    }
  })

  const likeDislike = new TouchBarButton({
    label: '❤️'
  })

  const trackInfo = new TouchBarLabel()

  soundcloud.on('play', (title, subtitle) => {
    trackInfo.label = title + ' by ' + subtitle
  })

  const touchBar = new TouchBar([
    previousTrack,
    playPause,
    nextTrack,
    likeDislike,
    new TouchBarSpacer({size: 'flexible'}),
    trackInfo,
    new TouchBarSpacer({size: 'flexible'})
  ])
  
  window.setTouchBar(touchBar)
}

@@ -541,16 +541,191 @@
 Pause()%0A
+      soundcloud.isPlaying().then(isPlaying =%3E %7B%0A        if (isPlaying) %7B%0A          playPause.label = '%E2%8F%B8'%0A        %7D else %7B%0A          playPause.label = '%E2%96%B6%EF%B8%8F'%0A        %7D%0A      %7D)%0A
     %7D%0A  
@@ -1142,18 +1142,16 @@
 %7D)%0A  %5D)%0A
-  
 %0A  windo

fix play/pause button