   store.rename 'update_progress', 'updates', {}
   store.modify 'updates', (updates) ->
     updates.settings ?= []
+    # Determine whether or not the user has just installed Template.
+    isNewInstall = updates.settings.length is 0
     # Check if the settings need updated for 0.1.0.0.
     if '0.1.0.0' not in updates.settings
       # Update the settings for 0.1.0.0.

  # Info requests are simple, just send some useful information back. Done!
  if request.type in ['info', 'version']
    return sendResponse? id: EXTENSION_ID, version: ext.version
  chrome.windows.getCurrent (win) ->
    chrome.tabs.query
      active:   yes
      windowId: win.id
    , (tabs) ->
      data             = {}
      popup            = chrome.extension.getViews(type: 'popup')[0]
      shortCalled      = no
      shortPlaceholder = "short#{utils.random 1000, 99999}"
      tab              = tabs[0]
      # Attempt to copy `str` to the system clipboard while handling the
      # potential for failure.  
      # Finally, increment the usage of `template` and update the statistics.
      copyOutput = (template, str) ->
        if str
          ext.copy str
        else
          ext.message = i18n.get 'copy_fail_empty'
          ext.status  = no
          showNotification()
        updateTemplateUsage template.key
        updateStatistics()
      # Called whenever the `short` tag is found to indicate that the URL
      # needs shortened.  
      # Replace the `short` tag with the unique placeholder so that it can be
      # rendered again later with the short URL.
      shortCallback = ->
        shortCalled = yes
        "{#{shortPlaceholder}}"
      # If the popup is currently displayed, hide the template list and show a
      # loading animation.
      if popup
        $('#item', popup.document).hide()
        $('#loadDiv', popup.document).show()
      # Attempt to derive the contextual template data.
      try
        switch request.type
          when 'menu'
            data     = buildDerivedData tab, request.data, shortCallback
            template = getTemplateWithMenuId request.data.menuItemId
          when 'popup'
            data     = buildStandardData tab, shortCallback
            template = getTemplateWithKey request.data.key
          when 'shortcut'
            data     = buildStandardData tab, shortCallback
            template = getTemplateWithShortcut request.data.key
      catch error
        # Oops! Something went wrong so we should probably let the user know.
        if error instanceof URIError
          ext.message = i18n.get 'copy_fail_uri'
        else
          ext.message = i18n.get 'copy_fail_error'
        ext.status = no
        showNotification()
        return
      if template
        addAdditionalData tab, data, ->
          unless template.content
            # Display the *empty template* error message.
            copyOutput template
            return
          output = Mustache.to_html template.content, data
          if shortCalled
            # At least one `short` tag was found and replaced, so now we need
            # to call the URL shortener service and replace that with the
            # actual short URL.
            callUrlShortener data.url, (response) ->
              if response.success and response.shortUrl
                # Short URL was successfully returned, so get rendering.
                newData = {}
                newData[shortPlaceholder] = response.shortUrl
                copyOutput template, Mustache.to_html output, newData
              else
                # Aw man, something went wrong. Let the user down gently.
                unless response.message
                  response.message = i18n.get 'shortener_error',
                    response.shortener
                ext.message = response.message
                ext.status  = no
                showNotification()
          else
            copyOutput template, output
      else
        # Close the popup if it's still open and the user wants it closed.
        # Otherwise, reset the popup so that it can be used further.
        if popup
          if store.get 'toolbar.close'
            popup.close()
          else
            $('#loadDiv', popup.document).hide()
            $('#item', popup.document).show()

# Display a desktop notification informing the user on whether or not the copy
# request was successful.  

showNotification = ->
  if store.get 'notifications.enabled'
    webkitNotifications.createHTMLNotification(
      utils.url 'pages/notification.html'
    ).show()
  else
    ext.reset()
