   return
 
 refreshModels = ->
-  getWatchedShows (_watchedShows) ->
-    console.log "Returned watchedShows: #{JSON.stringify _watchedShows}"
-    model.watchedShows = _watchedShows
-    getToWatchList (_toWatchList) ->
-      console.log 'toWatchList updated: ' + JSON.stringify _toWatchList
-      model.toWatchList = _toWatchList
-
-checkWatched = (episode) ->
-  console.log("Check watched! episode: #{JSON.stringify(episode)}")
+ traktvRequest 'sync/watched/shows', (response, status, req) ->
+    shows = response
+    # console.log "Returned shows: #{JSON.stringify shows.map (e)->e.show}"
+    getToWatchList shows, (toWatchList) ->
+      console.log 'toWatchList updated'
+      model.shows = toWatchList
+
+checkWatched = (episode, success, failure) ->
+  # console.log("Check watched! episode: #{JSON.stringify(episode)}")
   request =
     shows: [
-      episode.show
+      title: episode.show.title
+      year: episode.show.year
+      ids: episode.show.ids
       seasons: [
         number: episode.season
         episodes: [

  url = if opt.url
    opt.url
  else
    if opt.action[0] != '/'
      opt.action = '/' + opt.action
    "https://api-v2launch.trakt.tv" : opt.action

  data = opt.data


async = require('async')
require 'Object.observe.poly'

CONFIG_BASE_URL = 'http://bobby.alessiobogon.com:8020/'

console.log "accessToken: #{Settings.option 'accessToken'}"

mainMenu = undefined
signInWindow = undefined
detailedItemCard = undefined
mainMenu = undefined

model =
  shows: undefined


getToWatchList = (showList, callback) ->
  showListUpdated = showList[..]
  async.each(
    showListUpdated
    (item, doneItem) ->
      traktvRequest(
        "https://api-v2launch.trakt.tv/shows/#{item.show.ids.trakt}/progress/watched"
        (response, status, req) ->
          # console.log "getToWatchList: asked "
          # console.log "returned: #{JSON.stringify response.seasons}"
          if status != 200
            doneItem(response: response, status: status, req: req)
          item.next_episode = response.next_episode
          item.seasons = response.seasons
          for season in item.seasons
            for episode in season.episodes
              episode.completed ?= false
          doneItem()
      )
    (err) ->
      if err?
        console.log "Failed response (#{err.status}): #{err.response}"
        console.log "Request was: #{err.req}"
      console.log "getToWatchList returning"
      callback(showListUpdated)
  )

displaySignInWindow = ->
