             click: -> action 'toggleshowtray'
         }
     ]
-    if os == 'darwin'
+    if platform == 'darwin'
         tmpl.push {
             label: 'Hide Dock icon'
             type: 'checkbox'

Menu = remote.Menu

acceleratorMap = {
    hideyakyak:           {others: 'Control+H', osx: 'Command+H'}
    hideothers:           {others: '', osx: 'Command+Shift+H'}
    showall:              {others: '', osx: ''}
    openinspector:        {others: 'Control+Alt+I', osx: 'Command+Alt+I'}
    quit:                 {others: 'Control+Q', osx: 'Command+Q'}
    undo:                 {others: 'Control+Z', osx: 'Command+Z'}
    redo:                 {others: 'Control+Shift+Z', osx: 'Command+Shift+Z'}
    cut:                  {others: '', osx: 'Command+X'}
    copy:                 {others: '', osx: 'Command+C'}
    paste:                {others: '', osx: 'Command+V'}
    selectall:            {others: '', osx: 'Command+A'}
    togglefullscreen:     {others: 'Control+Alt+F', osx: 'Command+Control+F'}
    zoomin:               {others: 'Control+Plus', osx: 'Command+Plus'}
    zoomout:              {others: 'Control+-', osx: 'Command+-'}
    resetzoom:            {others: 'Control+0', osx: 'Command+0'}
    previousconversation: {others: 'Control+K', osx: 'Command+Shift+Tab'}
    nextconversation:     {others: 'Control+J', osx: 'Command+Tab'}
    conversation1:        {others: 'Alt+1', osx: 'Command+1'}
    conversation2:        {others: 'Alt+2', osx: 'Command+2'}
    conversation3:        {others: 'Alt+3', osx: 'Command+3'}
    conversation4:        {others: 'Alt+4', osx: 'Command+4'}
    conversation5:        {others: 'Alt+5', osx: 'Command+5'}
    conversation6:        {others: 'Alt+6', osx: 'Command+6'}
    conversation7:        {others: 'Alt+7', osx: 'Command+7'}
    conversation8:        {others: 'Alt+8', osx: 'Command+8'}
    conversation9:        {others: 'Alt+9', osx: 'Command+9'}
    minimize:             {others: '', osx: 'Command+M'}
    close:                {others: '', osx: 'Command+W'}
}

templateYakYak = (viewstate, os) ->
    tmpl = []
    if os == 'darwin'
        tmpl.push [
            { label: 'About YakYak', selector: 'orderFrontStandardAboutPanel:' }
            #{ type: 'separator' }
            # { label: 'Preferences...', accelerator: 'Command+,',
            # click: => delegate.openConfig() }
            { type: 'separator' }
        ]
    tmpl.push [
        {
            label: 'Hide YakYak'
            accelerator: acceleratorMap['hideyakyak'][os]
            selector: 'hide:'
        }
    ]

    if os == 'darwin'
        tmpl.push [{
              label: 'Hide Others'
              accelerator: acceleratorMap['hideother'][os]
              selector: 'hideOtherApplications:'
        }
        { label: 'Show All', selector: 'unhideAllApplications:' }
        ]
    tmpl.push [
      { type: 'separator' }
      {
          label: 'Open Inspector'
          accelerator: acceleratorMap['openinspector'][os]
          click: -> action 'devtools'
      }
      { type: 'separator' }
      {
          label: 'Logout',
          click: -> action 'logout'
          enabled: viewstate.loggedin
      }
      {
          label: 'Quit'
          accelerator: acceleratorMap['quit'][os]
          click: -> action 'quit'
      }
  ]

templateEdit = (viewstate, os) ->
    tmpl = [
        { label: 'Undo', accelerator: acceleratorMap['undo'][os], selector: 'undo:' }
        { label: 'Redo', accelerator: acceleratorMap['redo'][os], selector: 'redo:' }
    ]
    if os == 'darwin'
        tmpl.push [
          { type: 'separator' }
          { label: 'Cut', accelerator: acceleratorMap['cut'][os], selector: 'cut:' }
          { label: 'Copy', accelerator: acceleratorMap['copy'][os], selector: 'copy:' }
          { label: 'Paste', accelerator: acceleratorMap['paste'][os], selector: 'paste:' }
          { label: 'Select All', accelerator: acceleratorMap['selectall'][os], selector: 'selectAll:' }
        ]
    tmpl

templateView = (viewstate, os) ->
    tmpl = [
        {
            label: 'Conversation List'

        }
    tmpl

templateWindow = (viewstate, platform) -> [
    {
        label: 'Minimize'
        accelerator: acceleratorMap['minimize'][platform]
        selector: 'performMiniaturize:' if platform == 'darwin'
    }, {
        label: 'Close'
        accelerator: acceleratorMap['close'][platform]
        selector: 'performClose:' if platform == 'darwin'
    }, {
        type: 'separator'
    }, {
        label: 'Bring All to Front',
        selector: 'arrangeInFront:' if platform == 'darwin'
    }
]

templateMenu = (viewstate) ->
    platform = if require('os').platform() == 'darwin' then 'darwin' else 'others'
    tmpl = [{
            label: 'YakYak'
            submenu: templateYakYak viewstate, platform
        }, {
            label: 'Edit'
            submenu: templateEdit viewstate, platform
        },{
            label: 'View'
            submenu: templateView viewstate, platform
        }
    ]
    if platform == 'darwin'
        tmpl.push {
            label: 'Window'
            submenu: templateWindow viewstate, platform
        }
    tmpl

module.exports = (viewstate) ->
    console.log "b4"
    Menu.setApplicationMenu Menu.buildFromTemplate templateMenu(viewstate)
    console.log "done!"
