<commit_before>var BrowserWindow = require('browser-window');
var Menu = require('menu');

/**
 * Creates a default menu. Modeled after https://github.com/atom/electron/pull/1863.
 */
var createDefaultMenu = function(app) {
  app.once('ready', function() {
    var template;
    if (process.platform == 'darwin') {
      template = [
        {
          label: app.getName(),
          submenu: [
            {
              label: 'About ' + app.getName(),
              selector: 'orderFrontStandardAboutPanel:'
            },
            {
              type: 'separator'
            },
            {
              label: 'Services',
              submenu: []
            },
            {
              type: 'separator'
            },
            {
              label: 'Hide ' + app.getName(),
              accelerator: 'Command+H',
              selector: 'hide:'
            },
            {
              label: 'Hide Others',
              accelerator: 'Command+Shift+H',
              selector: 'hideOtherApplications:'
            },
            {
              label: 'Show All',
              selector: 'unhideAllApplications:'
            },
            {
              type: 'separator'
            },
            {
              label: 'Quit',
              accelerator: 'Command+Q',
              click: function() { app.quit(); }
            },
          ]
        },
        {
          label: 'Edit',
          submenu: [
            {
              label: 'Undo',
              accelerator: 'Command+Z',
              selector: 'undo:'
            },
            {
              label: 'Redo',
              accelerator: 'Shift+Command+Z',
              selector: 'redo:'
            },
            {
              type: 'separator'
            },
            {
              label: 'Cut',
              accelerator: 'Command+X',
              selector: 'cut:'
            },
            {
              label: 'Copy',
              accelerator: 'Command+C',
              selector: 'copy:'
            },
            {
              label: 'Paste',
              accelerator: 'Command+V',
              selector: 'paste:'
            },
            {
              label: 'Select All',
              accelerator: 'Command+A',
              selector: 'selectAll:'
            },
          ]
        },
        {
          label: 'View',
          submenu: [
            {
              label: 'Reload',
              accelerator: 'Command+R',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.restart();
                }
              }
            },
            {
              label: 'Toggle Full Screen',
              accelerator: 'Ctrl+Command+F',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
                }
              }
            }
          ]
        },
        {
          label: 'Window',
          submenu: [
            {
              label: 'Minimize',
              accelerator: 'Command+M',
              selector: 'performMiniaturize:'
            },
            {
              label: 'Close',
              accelerator: 'Command+W',
              selector: 'performClose:'
            },
            {
              type: 'separator'
            },
            {
              label: 'Bring All to Front',
              selector: 'arrangeInFront:'
            },
          ]
        }
      ];
    } else {
      template = [
        {
          label: '&File',
          submenu: [
            {
              label: '&Open',
              accelerator: 'Ctrl+O',
            },
            {
              label: '&Close',
              accelerator: 'Ctrl+W',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.close();
                }
              }
            },
          ]
        },
        {
          label: '&View',
          submenu: [
            {
              label: '&Reload',
              accelerator: 'Ctrl+R',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.reload();
                }
              }
            },
            {
              label: 'Toggle &Full Screen',
              accelerator: 'F11',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
                }
              }
            }
          ]
        }
      ];
    }

    var menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);
  });
};

module.exports = createDefaultMenu;
<commit_msg>Use menu roles<commit_after>var BrowserWindow = require('browser-window');
var Menu = require('menu');

/**
 * Creates a default menu. Modeled after https://github.com/atom/electron/pull/1863, augmented with
 * the roles from https://github.com/atom/electron/blob/master/docs/api/menu.md.
 */
var createDefaultMenu = function(app) {
  app.once('ready', function() {
    var template;
    if (process.platform == 'darwin') {
      template = [
        {
          label: app.getName(),
          submenu: [
            {
              label: 'About ' + app.getName(),
              role: 'about',
            },
            {
              type: 'separator'
            },
            {
              label: 'Services',
              role: 'services',
              submenu: []
            },
            {
              type: 'separator'
            },
            {
              label: 'Hide ' + app.getName(),
              accelerator: 'Command+H',
              role: 'hide'
            },
            {
              label: 'Hide Others',
              accelerator: 'Command+Shift+H',
              role: 'hideothers'
            },
            {
              label: 'Show All',
              role: 'unhide'
            },
            {
              type: 'separator'
            },
            {
              label: 'Quit',
              accelerator: 'Command+Q',
              click: function() { app.quit(); }
            },
          ]
        },
        {
          label: 'Edit',
          submenu: [
            {
              label: 'Undo',
              accelerator: 'Command+Z',
              role: 'undo'
            },
            {
              label: 'Redo',
              accelerator: 'Shift+Command+Z',
              role: 'redo'
            },
            {
              type: 'separator'
            },
            {
              label: 'Cut',
              accelerator: 'Command+X',
              role: 'cut'
            },
            {
              label: 'Copy',
              accelerator: 'Command+C',
              role: 'copy'
            },
            {
              label: 'Paste',
              accelerator: 'Command+V',
              role: 'paste'
            },
            {
              label: 'Select All',
              accelerator: 'Command+A',
              role: 'selectall'
            },
          ]
        },
        {
          label: 'View',
          submenu: [
            {
              label: 'Reload',
              accelerator: 'Command+R',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.restart();
                }
              }
            },
            {
              label: 'Toggle Full Screen',
              accelerator: 'Ctrl+Command+F',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
                }
              }
            }
          ]
        },
        {
          label: 'Window',
          submenu: [
            {
              label: 'Minimize',
              accelerator: 'Command+M',
              role: 'minimize'
            },
            {
              label: 'Close',
              accelerator: 'Command+W',
              role: 'close'
            },
            {
              type: 'separator'
            },
            {
              label: 'Bring All to Front',
              role: 'front'
            },
          ]
        }
      ];
    } else {
      template = [
        {
          label: '&File',
          submenu: [
            {
              label: '&Open',
              accelerator: 'Ctrl+O',
            },
            {
              label: '&Close',
              accelerator: 'Ctrl+W',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.close();
                }
              }
            },
          ]
        },
        {
          label: '&View',
          submenu: [
            {
              label: '&Reload',
              accelerator: 'Ctrl+R',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.reload();
                }
              }
            },
            {
              label: 'Toggle &Full Screen',
              accelerator: 'F11',
              click: function() {
                var focusedWindow = BrowserWindow.getFocusedWindow();
                if (focusedWindow) {
                  focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
                }
              }
            }
          ]
        }
      ];
    }

    var menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);
  });
};

module.exports = createDefaultMenu;
<|endoftext|>


<commit_before>const electron = require('electron');

const app = electron.app;
const Shell = electron.shell;
const Menu = electron.Menu;
const auto_updater = require('./auto_update.js');
const is = require('electron-is');
const open = require('open');
const log = require('electron-log');

module.exports = {
  setup: function () {
    var checkForUpdates;
    if (auto_updater.isSupported()) {
      checkForUpdates = {
        label: 'Check for Updates…',
        id: 'updateCheck',
        click: function (item, focusedWindow) {
          auto_updater.check();
        }
      };
    }
    var sep = {
      type: 'separator'
    };
    var prefs = {
      label: 'Preferences…',
      accelerator: 'CmdOrCtrl+,',
      click: function (item, focusedWindow, event) {
        if (focusedWindow) {
          focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.openSettings(); }', true);
        }
      }
    };
    var show_config = {
      label: 'Edit Config File…',
      click: function (item, focusedWindow, event) {
        app.config.openInEditor();
      }
    };
    var show_log = {
      label: 'Reveal Log File…',
      click: function (item, focusedWindow, event) {
        log.crash();
        Shell.showItemInFolder(log.transports.file.findLogPath());
      }
    };
    var show_user_style = {
      id: 'show_user_style',
      label: 'Reveal User Style…',
      click: function (item, focusedWindow, event) {
        Shell.showItemInFolder(app.config.get('userStylePath'));
      },
      visible: !!app.config.get('acceptUserStyles')
    };
    var show_user_script = {
      id: 'show_user_script',
      label: 'Reveal User Script…',
      click: function (item, focusedWindow, event) {
        Shell.showItemInFolder(app.config.get('userScriptPath'));
      },
      visible: !!app.config.get('acceptUserScripts')
    };
    var app_menu = {
      label: app.getName(),
      id: 'app',
      submenu: []
    };
    app_menu.submenu.push({
      role: 'about'
    });
    if (checkForUpdates) {
      app_menu.submenu.push(checkForUpdates);
    }
    app_menu.submenu.push(sep);
    app_menu.submenu.push(prefs);
    app_menu.submenu.push(sep);
    app_menu.submenu.push(show_config);
    app_menu.submenu.push(show_log);
    app_menu.submenu.push(show_user_style);
    app_menu.submenu.push(show_user_script);
    app_menu.submenu.push(sep);
    app_menu.submenu.push({
      role: 'services',
      submenu: []
    });
    app_menu.submenu.push(sep);
    app_menu.submenu.push({
      role: 'hide'
    });
    app_menu.submenu.push({
      role: 'hideothers'
    });
    app_menu.submenu.push({
      role: 'unhide'
    });
    app_menu.submenu.push(sep);
    app_menu.submenu.push({
      role: 'quit'
    });
    var file_menu = {
      label: 'File',
      id: 'app',
      submenu: [
        {
          role: 'close'
        },
        sep,
        {
          label: 'Open in Browser',
          click: function(item, focusedWindow, event) {
            var url = focusedWindow ?
              focusedWindow.webContents.getURL() :
              app.config.get('host');
            require('electron').shell.openExternal(url);
          }
        }, {
          label: 'Open Browser Tab…',
          accelerator: 'CmdOrCtrl+T',
          click: function(item, focusedWindow, event) {
            open('http://');
          }
        },
        sep,
        {
          label: 'Add a Network…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.addNetwork(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Jump to…',
          accelerator: 'CmdOrCtrl+K',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.channelSwitcher.toggle(); }', true);
            }
          }
        }, {
          label: 'Select Next in List',
          accelerator: 'Alt+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous in List',
          accelerator: 'Alt+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Next Unread in List',
          accelerator: 'Alt+Shift+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextUnreadBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous Unread in List',
          accelerator: 'Alt+Shift+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousUnreadBuffer(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Mark Current as Read',
          accelerator: 'Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.read(); }', true);
            }
          }
        }, {
          label: 'Mark All as Read',
          accelerator: 'Shift+Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION) { SESSION.markAllAsRead(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Upload a File…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("uploadPrompt"); }', true);
            }
          }
        }, {
          label: 'Start a Pastebin…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("pastePrompt"); }', true);
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      file_menu.submenu.push(sep);
      file_menu.submenu.push(prefs);
      file_menu.submenu.push(show_config);
      file_menu.submenu.push(show_log);
      file_menu.submenu.push(show_user_style);
      file_menu.submenu.push(show_user_script);
      file_menu.submenu.push(sep);
      file_menu.submenu.push({
        label: 'Show in Tray',
        type:  'checkbox',
        checked: Boolean(app.config.get('tray')),
        click: function(item, focusedWindow, event) {
          app.config.set('tray', item.checked);
          app.toggleTray();
        }
      });
      file_menu.submenu.push({
        role: 'quit'
      });
    }

    var spellingItem;
    var spellingSubItem = {
      type: 'checkbox',
      id: 'spellingItem',
      checked: app.config.get('spellcheck'),
      click: function(item, focusedWindow, event) {
        app.config.set('spellcheck', item.checked);
        app.toggleSpellcheck();
      }
    };
    if (is.macOS()) {
      spellingSubItem.label = 'Check Spelling While Typing';
      spellingItem = {
        label: 'Spelling and Grammar',
        submenu: [spellingSubItem]
      };
    } else {
      spellingSubItem.label = 'Check spelling as you type';
      spellingItem = spellingSubItem;
    }
    var edit_menu = {
      label: 'Edit',
      id: 'edit',
      submenu: [
        {
          role: 'undo'
        }, {
          role: 'redo'
        },
        sep,
        {
          role: 'cut'
        }, {
          role: 'copy'
        }, {
          role: 'delete'
        }, {
          role: 'paste'
        }, {
          role: 'pasteandmatchstyle'
        }, {
          role: 'selectall'
        },
        sep,
        spellingItem
      ]
    };

    var view_menu = {
      label: 'View',
      id: 'view',
      submenu: [
        {
          label: 'Reload',
          accelerator: 'CmdOrCtrl+R',
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.reloadIgnoringCache();
            } else {
              app.emit('activate', {
                reload: true
              });
            }
          }
        },
        sep,
        {
          role: 'togglefullscreen'
        }, {
          label: 'Actual Size',
          id: 'zoomReset',
          enabled: false,
          accelerator: 'CmdOrCtrl+0',
          click: function(item, focusedWindow, event) {
            app.resetZoom();
          }
        }, {
          label: 'Zoom In',
          id: 'zoomIn',
          enabled: false,
          accelerator: 'CmdOrCtrl+=',
          click: function(item, focusedWindow, event) {
            app.zoomIn();
          }
        }, {
          label: 'Zoom Out',
          id: 'zoomOut',
          enabled: false,
          accelerator: 'CmdOrCtrl+-',
          click: function(item, focusedWindow, event) {
            app.zoomOut();
          }
        },
        sep,
        {
          label: 'Developer Tools',
          accelerator: (function() {
            if (is.macOS()) {
              return 'Cmd+Alt+I';
            } else {
              return 'Ctrl+Shift+I';
            }
          })(),
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.openDevTools();
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      view_menu.submenu.splice(2, 0, {
        label: 'Toggle Menu Bar',
        accelerator: 'Ctrl+Shift+M',
        click: function(item, focusedWindow, event) {
          if (focusedWindow.isMenuBarAutoHide()) {
            app.config.set('menu-bar', true);
            app.toggleMenuBar(focusedWindow);
          } else {
            app.config.set('menu-bar', false);
            app.toggleMenuBar(focusedWindow);
          }
        }
      });
    }

    var go_menu = {
      label: 'Go',
      id: 'history',
      submenu: [
        {
          label: 'Back',
          accelerator: 'CmdOrCtrl+[',
          enabled: false,
          id: 'backMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goBack();
            }
          }
        }, {
          label: 'Forward',
          accelerator: 'CmdOrCtrl+]',
          enabled: false,
          id: 'fwdMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goForward();
            }
          }
        },
        sep,
        {
          label: 'File Uploads',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.files.show(); }', true);
            }
          }
        }, {
          label: 'Pastebins',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.pastebins.show(); }', true);
            }
          }
        }
      ]
    };

    var window_menu = {
      label: 'Window',
      role: 'window',
      submenu: [
        {
          role: 'minimize'
        },
        sep,
        {
          role: 'front'
        },
        sep,
        {
          label: 'Main Window',
          accelerator: 'CmdOrCtrl+1',
          click: function (item, focusedWindow, event) {
            app.emit('activate');
          }
        }
      ]
    };

    var help_menu = {
      role: 'help',
      submenu: [
        {
          label: 'Keyboard Shortcuts',
          accelerator: 'CmdOrCtrl+/',
          click: function (item, focusedWindow, event) {
            focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.navigate("?/shortcuts", {trigger: true}); }', true);
          }
        },
        sep,
        {
          label: 'Known Issues',
          click: function(item, focusedWindow, event) {
            require('electron').shell.openExternal('https://github.com/irccloud/irccloud-desktop/issues');
          }
        }
      ]
    };
    if (checkForUpdates && !is.macOS()) {
      help_menu.submenu.push(checkForUpdates);
    }

    var menu;
    if (is.macOS()) {
      menu = Menu.buildFromTemplate([app_menu, file_menu, edit_menu, view_menu, go_menu, window_menu, help_menu]);
    } else {
      menu = Menu.buildFromTemplate([file_menu, edit_menu, view_menu, go_menu, help_menu]);
    }
    Menu.setApplicationMenu(menu);
    return menu;
  },
  setup_tray: function(app){
    var menu;
    let items = [
      // Clicking the icon to show the app only works on windows
      // May as well include this option for all anyway
      {
        label: 'Open',
        click: function (item, focusedWindow, event) {
          app.emit('activate');
        }
      },
      {
        role: 'quit'
      }
    ];
    menu = Menu.buildFromTemplate(items);
    return menu;
  }
};
<commit_msg>Remove crash test<commit_after>const electron = require('electron');

const app = electron.app;
const Shell = electron.shell;
const Menu = electron.Menu;
const auto_updater = require('./auto_update.js');
const is = require('electron-is');
const open = require('open');
const log = require('electron-log');

module.exports = {
  setup: function () {
    var checkForUpdates;
    if (auto_updater.isSupported()) {
      checkForUpdates = {
        label: 'Check for Updates…',
        id: 'updateCheck',
        click: function (item, focusedWindow) {
          auto_updater.check();
        }
      };
    }
    var sep = {
      type: 'separator'
    };
    var prefs = {
      label: 'Preferences…',
      accelerator: 'CmdOrCtrl+,',
      click: function (item, focusedWindow, event) {
        if (focusedWindow) {
          focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.openSettings(); }', true);
        }
      }
    };
    var show_config = {
      label: 'Edit Config File…',
      click: function (item, focusedWindow, event) {
        app.config.openInEditor();
      }
    };
    var show_log = {
      label: 'Reveal Log File…',
      click: function (item, focusedWindow, event) {
        Shell.showItemInFolder(log.transports.file.findLogPath());
      }
    };
    var show_user_style = {
      id: 'show_user_style',
      label: 'Reveal User Style…',
      click: function (item, focusedWindow, event) {
        Shell.showItemInFolder(app.config.get('userStylePath'));
      },
      visible: !!app.config.get('acceptUserStyles')
    };
    var show_user_script = {
      id: 'show_user_script',
      label: 'Reveal User Script…',
      click: function (item, focusedWindow, event) {
        Shell.showItemInFolder(app.config.get('userScriptPath'));
      },
      visible: !!app.config.get('acceptUserScripts')
    };
    var app_menu = {
      label: app.getName(),
      id: 'app',
      submenu: []
    };
    app_menu.submenu.push({
      role: 'about'
    });
    if (checkForUpdates) {
      app_menu.submenu.push(checkForUpdates);
    }
    app_menu.submenu.push(sep);
    app_menu.submenu.push(prefs);
    app_menu.submenu.push(sep);
    app_menu.submenu.push(show_config);
    app_menu.submenu.push(show_log);
    app_menu.submenu.push(show_user_style);
    app_menu.submenu.push(show_user_script);
    app_menu.submenu.push(sep);
    app_menu.submenu.push({
      role: 'services',
      submenu: []
    });
    app_menu.submenu.push(sep);
    app_menu.submenu.push({
      role: 'hide'
    });
    app_menu.submenu.push({
      role: 'hideothers'
    });
    app_menu.submenu.push({
      role: 'unhide'
    });
    app_menu.submenu.push(sep);
    app_menu.submenu.push({
      role: 'quit'
    });
    var file_menu = {
      label: 'File',
      id: 'app',
      submenu: [
        {
          role: 'close'
        },
        sep,
        {
          label: 'Open in Browser',
          click: function(item, focusedWindow, event) {
            var url = focusedWindow ?
              focusedWindow.webContents.getURL() :
              app.config.get('host');
            require('electron').shell.openExternal(url);
          }
        }, {
          label: 'Open Browser Tab…',
          accelerator: 'CmdOrCtrl+T',
          click: function(item, focusedWindow, event) {
            open('http://');
          }
        },
        sep,
        {
          label: 'Add a Network…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.addNetwork(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Jump to…',
          accelerator: 'CmdOrCtrl+K',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.channelSwitcher.toggle(); }', true);
            }
          }
        }, {
          label: 'Select Next in List',
          accelerator: 'Alt+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous in List',
          accelerator: 'Alt+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Next Unread in List',
          accelerator: 'Alt+Shift+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextUnreadBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous Unread in List',
          accelerator: 'Alt+Shift+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousUnreadBuffer(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Mark Current as Read',
          accelerator: 'Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.read(); }', true);
            }
          }
        }, {
          label: 'Mark All as Read',
          accelerator: 'Shift+Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION) { SESSION.markAllAsRead(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Upload a File…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("uploadPrompt"); }', true);
            }
          }
        }, {
          label: 'Start a Pastebin…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("pastePrompt"); }', true);
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      file_menu.submenu.push(sep);
      file_menu.submenu.push(prefs);
      file_menu.submenu.push(show_config);
      file_menu.submenu.push(show_log);
      file_menu.submenu.push(show_user_style);
      file_menu.submenu.push(show_user_script);
      file_menu.submenu.push(sep);
      file_menu.submenu.push({
        label: 'Show in Tray',
        type:  'checkbox',
        checked: Boolean(app.config.get('tray')),
        click: function(item, focusedWindow, event) {
          app.config.set('tray', item.checked);
          app.toggleTray();
        }
      });
      file_menu.submenu.push({
        role: 'quit'
      });
    }

    var spellingItem;
    var spellingSubItem = {
      type: 'checkbox',
      id: 'spellingItem',
      checked: app.config.get('spellcheck'),
      click: function(item, focusedWindow, event) {
        app.config.set('spellcheck', item.checked);
        app.toggleSpellcheck();
      }
    };
    if (is.macOS()) {
      spellingSubItem.label = 'Check Spelling While Typing';
      spellingItem = {
        label: 'Spelling and Grammar',
        submenu: [spellingSubItem]
      };
    } else {
      spellingSubItem.label = 'Check spelling as you type';
      spellingItem = spellingSubItem;
    }
    var edit_menu = {
      label: 'Edit',
      id: 'edit',
      submenu: [
        {
          role: 'undo'
        }, {
          role: 'redo'
        },
        sep,
        {
          role: 'cut'
        }, {
          role: 'copy'
        }, {
          role: 'delete'
        }, {
          role: 'paste'
        }, {
          role: 'pasteandmatchstyle'
        }, {
          role: 'selectall'
        },
        sep,
        spellingItem
      ]
    };

    var view_menu = {
      label: 'View',
      id: 'view',
      submenu: [
        {
          label: 'Reload',
          accelerator: 'CmdOrCtrl+R',
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.reloadIgnoringCache();
            } else {
              app.emit('activate', {
                reload: true
              });
            }
          }
        },
        sep,
        {
          role: 'togglefullscreen'
        }, {
          label: 'Actual Size',
          id: 'zoomReset',
          enabled: false,
          accelerator: 'CmdOrCtrl+0',
          click: function(item, focusedWindow, event) {
            app.resetZoom();
          }
        }, {
          label: 'Zoom In',
          id: 'zoomIn',
          enabled: false,
          accelerator: 'CmdOrCtrl+=',
          click: function(item, focusedWindow, event) {
            app.zoomIn();
          }
        }, {
          label: 'Zoom Out',
          id: 'zoomOut',
          enabled: false,
          accelerator: 'CmdOrCtrl+-',
          click: function(item, focusedWindow, event) {
            app.zoomOut();
          }
        },
        sep,
        {
          label: 'Developer Tools',
          accelerator: (function() {
            if (is.macOS()) {
              return 'Cmd+Alt+I';
            } else {
              return 'Ctrl+Shift+I';
            }
          })(),
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.openDevTools();
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      view_menu.submenu.splice(2, 0, {
        label: 'Toggle Menu Bar',
        accelerator: 'Ctrl+Shift+M',
        click: function(item, focusedWindow, event) {
          if (focusedWindow.isMenuBarAutoHide()) {
            app.config.set('menu-bar', true);
            app.toggleMenuBar(focusedWindow);
          } else {
            app.config.set('menu-bar', false);
            app.toggleMenuBar(focusedWindow);
          }
        }
      });
    }

    var go_menu = {
      label: 'Go',
      id: 'history',
      submenu: [
        {
          label: 'Back',
          accelerator: 'CmdOrCtrl+[',
          enabled: false,
          id: 'backMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goBack();
            }
          }
        }, {
          label: 'Forward',
          accelerator: 'CmdOrCtrl+]',
          enabled: false,
          id: 'fwdMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goForward();
            }
          }
        },
        sep,
        {
          label: 'File Uploads',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.files.show(); }', true);
            }
          }
        }, {
          label: 'Pastebins',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.pastebins.show(); }', true);
            }
          }
        }
      ]
    };

    var window_menu = {
      label: 'Window',
      role: 'window',
      submenu: [
        {
          role: 'minimize'
        },
        sep,
        {
          role: 'front'
        },
        sep,
        {
          label: 'Main Window',
          accelerator: 'CmdOrCtrl+1',
          click: function (item, focusedWindow, event) {
            app.emit('activate');
          }
        }
      ]
    };

    var help_menu = {
      role: 'help',
      submenu: [
        {
          label: 'Keyboard Shortcuts',
          accelerator: 'CmdOrCtrl+/',
          click: function (item, focusedWindow, event) {
            focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.navigate("?/shortcuts", {trigger: true}); }', true);
          }
        },
        sep,
        {
          label: 'Known Issues',
          click: function(item, focusedWindow, event) {
            require('electron').shell.openExternal('https://github.com/irccloud/irccloud-desktop/issues');
          }
        }
      ]
    };
    if (checkForUpdates && !is.macOS()) {
      help_menu.submenu.push(checkForUpdates);
    }

    var menu;
    if (is.macOS()) {
      menu = Menu.buildFromTemplate([app_menu, file_menu, edit_menu, view_menu, go_menu, window_menu, help_menu]);
    } else {
      menu = Menu.buildFromTemplate([file_menu, edit_menu, view_menu, go_menu, help_menu]);
    }
    Menu.setApplicationMenu(menu);
    return menu;
  },
  setup_tray: function(app){
    var menu;
    let items = [
      // Clicking the icon to show the app only works on windows
      // May as well include this option for all anyway
      {
        label: 'Open',
        click: function (item, focusedWindow, event) {
          app.emit('activate');
        }
      },
      {
        role: 'quit'
      }
    ];
    menu = Menu.buildFromTemplate(items);
    return menu;
  }
};
<|endoftext|>


<commit_before>const electron = require('electron');

const app = electron.app;
const Shell = electron.shell;
const Menu = electron.Menu;
const auto_updater = require('./auto_update.js');
const is = require('electron-is');
const open = require('open');

var checkForUpdates = {
  label: 'Check for Updates…',
  id: 'updateCheck',
  click: function (item, focusedWindow) {
    auto_updater.check();
  }
};
var prefs = {
  label: 'Preferences…',
  accelerator: 'CmdOrCtrl+,',
  click: function (item, focusedWindow, event) {
    if (focusedWindow) {
      focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.openSettings(); }', true);
    }
  }
};
var show_config = {
  label: 'Reveal Config File…',
  click: function (item, focusedWindow, event) {
    Shell.showItemInFolder(app.config.path);
  }
};

module.exports = {
  setup: function () {
    var app_menu = {
      label: app.getName(),
      id: 'app',
      submenu: [
        {
          role: 'about'
        },
        checkForUpdates,
        {
          type: 'separator'
        },
        prefs,
        show_config,
        {
          type: 'separator'
        }, {
          role: 'services',
          submenu: []
        }, {
          type: 'separator'
        }, {
          role: 'hide'
        }, {
          role: 'hideothers'
        }, {
          role: 'unhide'
        }, {
          type: 'separator'
        }, {
          role: 'quit'
        }
      ]
    };
    var file_menu = {
      label: 'File',
      submenu: [
        {
          role: 'close'
        }, {
          type: 'separator'
        }, {
          label: 'Open in Browser',
          click: function(item, focusedWindow, event) {
            var url = focusedWindow ?
              focusedWindow.webContents.getURL() :
              app.config.get('host');
            require('electron').shell.openExternal(url);
          }
        }, {
          label: 'Open Browser Tab…',
          accelerator: 'CmdOrCtrl+T',
          click: function(item, focusedWindow, event) {
            open('http://');
          }
        }, {
          type: 'separator'
        }, {
          label: 'Add a Network…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.addNetwork(); }', true);
            }
          }
        }, {
          type: 'separator'
        }, {
          label: 'Jump to…',
          accelerator: 'CmdOrCtrl+K',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.channelSwitcher.toggle(); }', true);
            }
          }
        }, {
          label: 'Select Next in List',
          accelerator: 'Alt+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous in List',
          accelerator: 'Alt+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Next Unread in List',
          accelerator: 'Alt+Shift+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextUnreadBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous Unread in List',
          accelerator: 'Alt+Shift+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousUnreadBuffer(); }', true);
            }
          }
        }, {
          type: 'separator'
        }, {
          label: 'Mark Current as Read',
          accelerator: 'Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.read(); }', true);
            }
          }
        }, {
          label: 'Mark All as Read',
          accelerator: 'Shift+Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION) { SESSION.markAllAsRead(); }', true);
            }
          }
        }, {
          type: 'separator'
        }, {
          label: 'Upload a File…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("uploadPrompt"); }', true);
            }
          }
        }, {
          label: 'Start a Pastebin…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("pastePrompt"); }', true);
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      file_menu.submenu.push({
        type: 'separator'
      });
      file_menu.submenu.push(prefs);
      file_menu.submenu.push(show_config);
      file_menu.submenu.push({
        type: 'separator'
      });
      file_menu.submenu.push({
        label: 'Show in Tray',
        type:  'checkbox',
        checked: Boolean(app.config.get('tray')),
        click: function(item, focusedWindow, event) {
          app.config.set('tray', item.checked);
          app.toggleTray();
        }
      });
      file_menu.submenu.push({
        role: 'quit'
      });
    }

    var spellingItem;
    var spellingSubItem = {
      type: 'checkbox',
      id: 'spellingItem',
      checked: app.config.get('spellcheck'),
      click: function(item, focusedWindow, event) {
        app.config.set('spellcheck', item.checked);
        app.toggleSpellcheck();
      }
    };
    if (is.macOS()) {
      spellingSubItem.label = 'Check Spelling While Typing';
      spellingItem = {
        label: 'Spelling and Grammar',
        submenu: [spellingSubItem]
      };
    } else {
      spellingSubItem.label = 'Check spelling as you type';
      spellingItem = spellingSubItem;
    }
    var edit_menu = {
      label: 'Edit',
      id: 'edit',
      submenu: [
        {
          role: 'undo'
        }, {
          role: 'redo'
        }, {
          type: 'separator'
        }, {
          role: 'cut'
        }, {
          role: 'copy'
        }, {
          role: 'delete'
        }, {
          role: 'paste'
        }, {
          role: 'pasteandmatchstyle'
        }, {
          role: 'selectall'
        }, {
          type: 'separator'
        },
        spellingItem
      ]
    };

    var view_menu = {
      label: 'View',
      id: 'view',
      submenu: [
        {
          label: 'Reload',
          accelerator: 'CmdOrCtrl+R',
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.reloadIgnoringCache();
            } else {
              app.emit('activate', {
                reload: true
              });
            }
          }
        }, {
          type: 'separator'
        }, {
          role: 'togglefullscreen'
        }, {
          label: 'Actual Size',
          id: 'zoomReset',
          enabled: false,
          accelerator: 'CmdOrCtrl+0',
          click: function(item, focusedWindow, event) {
            app.resetZoom();
          }
        }, {
          label: 'Zoom In',
          id: 'zoomIn',
          enabled: false,
          accelerator: 'CmdOrCtrl+=',
          click: function(item, focusedWindow, event) {
            app.zoomIn();
          }
        }, {
          label: 'Zoom Out',
          id: 'zoomOut',
          enabled: false,
          accelerator: 'CmdOrCtrl+-',
          click: function(item, focusedWindow, event) {
            app.zoomOut();
          }
        }, {
          type: 'separator'
        }, {
          label: 'Developer Tools',
          accelerator: (function() {
            if (is.macOS()) {
              return 'Cmd+Alt+I';
            } else {
              return 'Ctrl+Shift+I';
            }
          })(),
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.openDevTools();
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      view_menu.submenu.splice(2, 0, {
        label: 'Toggle Menu Bar',
        accelerator: 'Ctrl+Shift+M',
        click: function(item, focusedWindow, event) {
          if (focusedWindow.isMenuBarAutoHide()) {
            app.config.set('menu-bar', true);
            app.toggleMenuBar(focusedWindow);
          } else {
            app.config.set('menu-bar', false);
            app.toggleMenuBar(focusedWindow);
          }
        }
      });
    }

    var go_menu = {
      label: 'Go',
      id: 'history',
      submenu: [
        {
          label: 'Back',
          accelerator: 'CmdOrCtrl+[',
          enabled: false,
          id: 'backMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goBack();
            }
          }
        }, {
          label: 'Forward',
          accelerator: 'CmdOrCtrl+]',
          enabled: false,
          id: 'fwdMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goForward();
            }
          }
        }, {
          type: 'separator'
        }, {
          label: 'File Uploads',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.files.show(); }', true);
            }
          }
        }, {
          label: 'Pastebins',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.pastebins.show(); }', true);
            }
          }
        }
      ]
    };

    var window_menu = {
      label: 'Window',
      role: 'window',
      submenu: [
        {
          role: 'minimize'
        }, {
          type: 'separator'
        }, {
          role: 'front'
        }, {
          type: 'separator'
        }, {
          label: 'Main Window',
          accelerator: 'CmdOrCtrl+1',
          click: function (item, focusedWindow, event) {
            app.emit('activate');
          }
        }
      ]
    };

    var help_menu = {
      role: 'help',
      submenu: [
        {
          label: 'Keyboard Shortcuts',
          accelerator: 'CmdOrCtrl+/',
          click: function (item, focusedWindow, event) {
            focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.navigate("?/shortcuts", {trigger: true}); }', true);
          }
        }, {
          type: 'separator'
        }, {
          label: 'Known Issues',
          click: function(item, focusedWindow, event) {
            require('electron').shell.openExternal('https://github.com/irccloud/irccloud-desktop/issues');
          }
        }
      ]
    };
    if (!is.macOS()) {
      help_menu.submenu.push(checkForUpdates);
    }

    var menu;
    if (is.macOS()) {
      menu = Menu.buildFromTemplate([app_menu, file_menu, edit_menu, view_menu, go_menu, window_menu, help_menu]);
    } else {
      menu = Menu.buildFromTemplate([file_menu, edit_menu, view_menu, go_menu, help_menu]);
    }
    Menu.setApplicationMenu(menu);
    return menu;
  },
  setup_tray: function(app){
    var menu;
    menu = Menu.buildFromTemplate([
      {
        role: 'quit'
      }
    ]);
    return menu;
  }
};
<commit_msg>Use a variable for menu separators<commit_after>const electron = require('electron');

const app = electron.app;
const Shell = electron.shell;
const Menu = electron.Menu;
const auto_updater = require('./auto_update.js');
const is = require('electron-is');
const open = require('open');

var checkForUpdates = {
  label: 'Check for Updates…',
  id: 'updateCheck',
  click: function (item, focusedWindow) {
    auto_updater.check();
  }
};
var sep = {
  type: 'separator'
};
var prefs = {
  label: 'Preferences…',
  accelerator: 'CmdOrCtrl+,',
  click: function (item, focusedWindow, event) {
    if (focusedWindow) {
      focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.openSettings(); }', true);
    }
  }
};
var show_config = {
  label: 'Reveal Config File…',
  click: function (item, focusedWindow, event) {
    Shell.showItemInFolder(app.config.path);
  }
};

module.exports = {
  setup: function () {
    var app_menu = {
      label: app.getName(),
      id: 'app',
      submenu: [
        {
          role: 'about'
        },
        checkForUpdates,
        sep,
        prefs,
        sep,
        show_config,
        sep,
        {
          role: 'services',
          submenu: []
        },
        sep,
        {
          role: 'hide'
        }, {
          role: 'hideothers'
        }, {
          role: 'unhide'
        },
        sep,
        {
          role: 'quit'
        }
      ]
    };
    var file_menu = {
      label: 'File',
      submenu: [
        {
          role: 'close'
        },
        sep,
        {
          label: 'Open in Browser',
          click: function(item, focusedWindow, event) {
            var url = focusedWindow ?
              focusedWindow.webContents.getURL() :
              app.config.get('host');
            require('electron').shell.openExternal(url);
          }
        }, {
          label: 'Open Browser Tab…',
          accelerator: 'CmdOrCtrl+T',
          click: function(item, focusedWindow, event) {
            open('http://');
          }
        },
        sep,
        {
          label: 'Add a Network…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.addNetwork(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Jump to…',
          accelerator: 'CmdOrCtrl+K',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.channelSwitcher.toggle(); }', true);
            }
          }
        }, {
          label: 'Select Next in List',
          accelerator: 'Alt+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous in List',
          accelerator: 'Alt+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Next Unread in List',
          accelerator: 'Alt+Shift+Down',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectNextUnreadBuffer(); }', true);
            }
          }
        }, {
          label: 'Select Previous Unread in List',
          accelerator: 'Alt+Shift+Up',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.sidebar.bufferList.selectPreviousUnreadBuffer(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Mark Current as Read',
          accelerator: 'Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.read(); }', true);
            }
          }
        }, {
          label: 'Mark All as Read',
          accelerator: 'Shift+Esc',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION) { SESSION.markAllAsRead(); }', true);
            }
          }
        },
        sep,
        {
          label: 'Upload a File…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("uploadPrompt"); }', true);
            }
          }
        }, {
          label: 'Start a Pastebin…',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSION && SESSION.currentBuffer) { SESSION.currentBuffer.trigger("pastePrompt"); }', true);
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      file_menu.submenu.push(sep);
      file_menu.submenu.push(prefs);
      file_menu.submenu.push(show_config);
      file_menu.submenu.push(sep);
      file_menu.submenu.push({
        label: 'Show in Tray',
        type:  'checkbox',
        checked: Boolean(app.config.get('tray')),
        click: function(item, focusedWindow, event) {
          app.config.set('tray', item.checked);
          app.toggleTray();
        }
      });
      file_menu.submenu.push({
        role: 'quit'
      });
    }

    var spellingItem;
    var spellingSubItem = {
      type: 'checkbox',
      id: 'spellingItem',
      checked: app.config.get('spellcheck'),
      click: function(item, focusedWindow, event) {
        app.config.set('spellcheck', item.checked);
        app.toggleSpellcheck();
      }
    };
    if (is.macOS()) {
      spellingSubItem.label = 'Check Spelling While Typing';
      spellingItem = {
        label: 'Spelling and Grammar',
        submenu: [spellingSubItem]
      };
    } else {
      spellingSubItem.label = 'Check spelling as you type';
      spellingItem = spellingSubItem;
    }
    var edit_menu = {
      label: 'Edit',
      id: 'edit',
      submenu: [
        {
          role: 'undo'
        }, {
          role: 'redo'
        },
        sep,
        {
          role: 'cut'
        }, {
          role: 'copy'
        }, {
          role: 'delete'
        }, {
          role: 'paste'
        }, {
          role: 'pasteandmatchstyle'
        }, {
          role: 'selectall'
        },
        sep,
        spellingItem
      ]
    };

    var view_menu = {
      label: 'View',
      id: 'view',
      submenu: [
        {
          label: 'Reload',
          accelerator: 'CmdOrCtrl+R',
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.reloadIgnoringCache();
            } else {
              app.emit('activate', {
                reload: true
              });
            }
          }
        },
        sep,
        {
          role: 'togglefullscreen'
        }, {
          label: 'Actual Size',
          id: 'zoomReset',
          enabled: false,
          accelerator: 'CmdOrCtrl+0',
          click: function(item, focusedWindow, event) {
            app.resetZoom();
          }
        }, {
          label: 'Zoom In',
          id: 'zoomIn',
          enabled: false,
          accelerator: 'CmdOrCtrl+=',
          click: function(item, focusedWindow, event) {
            app.zoomIn();
          }
        }, {
          label: 'Zoom Out',
          id: 'zoomOut',
          enabled: false,
          accelerator: 'CmdOrCtrl+-',
          click: function(item, focusedWindow, event) {
            app.zoomOut();
          }
        },
        sep,
        {
          label: 'Developer Tools',
          accelerator: (function() {
            if (is.macOS()) {
              return 'Cmd+Alt+I';
            } else {
              return 'Ctrl+Shift+I';
            }
          })(),
          click: function(item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.openDevTools();
            }
          }
        }
      ]
    };
    if (!is.macOS()) {
      view_menu.submenu.splice(2, 0, {
        label: 'Toggle Menu Bar',
        accelerator: 'Ctrl+Shift+M',
        click: function(item, focusedWindow, event) {
          if (focusedWindow.isMenuBarAutoHide()) {
            app.config.set('menu-bar', true);
            app.toggleMenuBar(focusedWindow);
          } else {
            app.config.set('menu-bar', false);
            app.toggleMenuBar(focusedWindow);
          }
        }
      });
    }

    var go_menu = {
      label: 'Go',
      id: 'history',
      submenu: [
        {
          label: 'Back',
          accelerator: 'CmdOrCtrl+[',
          enabled: false,
          id: 'backMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goBack();
            }
          }
        }, {
          label: 'Forward',
          accelerator: 'CmdOrCtrl+]',
          enabled: false,
          id: 'fwdMenu',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.goForward();
            }
          }
        },
        sep,
        {
          label: 'File Uploads',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.files.show(); }', true);
            }
          }
        }, {
          label: 'Pastebins',
          click: function (item, focusedWindow, event) {
            if (focusedWindow) {
              focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.pastebins.show(); }', true);
            }
          }
        }
      ]
    };

    var window_menu = {
      label: 'Window',
      role: 'window',
      submenu: [
        {
          role: 'minimize'
        },
        sep,
        {
          role: 'front'
        },
        sep,
        {
          label: 'Main Window',
          accelerator: 'CmdOrCtrl+1',
          click: function (item, focusedWindow, event) {
            app.emit('activate');
          }
        }
      ]
    };

    var help_menu = {
      role: 'help',
      submenu: [
        {
          label: 'Keyboard Shortcuts',
          accelerator: 'CmdOrCtrl+/',
          click: function (item, focusedWindow, event) {
            focusedWindow.webContents.executeJavaScript('if (SESSIONVIEW) { SESSIONVIEW.navigate("?/shortcuts", {trigger: true}); }', true);
          }
        },
        sep,
        {
          label: 'Known Issues',
          click: function(item, focusedWindow, event) {
            require('electron').shell.openExternal('https://github.com/irccloud/irccloud-desktop/issues');
          }
        }
      ]
    };
    if (!is.macOS()) {
      help_menu.submenu.push(checkForUpdates);
    }

    var menu;
    if (is.macOS()) {
      menu = Menu.buildFromTemplate([app_menu, file_menu, edit_menu, view_menu, go_menu, window_menu, help_menu]);
    } else {
      menu = Menu.buildFromTemplate([file_menu, edit_menu, view_menu, go_menu, help_menu]);
    }
    Menu.setApplicationMenu(menu);
    return menu;
  },
  setup_tray: function(app){
    var menu;
    menu = Menu.buildFromTemplate([
      {
        role: 'quit'
      }
    ]);
    return menu;
  }
};
<|endoftext|>


<commit_before>
var Strukturas = [
    {
        id: "vienkars_saraksts",
        nosaukums: "Vienkāršsaistīts saraksts",
        izveidot: null
    },
    {
        id: "divkars_saraksts",
        nosaukums: "Divkāršsaistīts saraksts",
        izveidot: null
    },
    {
        id: "steks",
        nosaukums: "Steks",
        izveidot: null
    },
    {
        id: "rinda",
        nosaukums: "Rinda",
        izveidot: null
    },
    {
        id: "kaudze",
        nosaukums: "Kaudze",
        izveidot: null
    },
    {
        id: "binars_koks",
        nosaukums: "Binārs koks",
        izveidot: null
    },
    {
        id: "avl_koks",
        nosaukums: "AVL koks",
        izveidot: null
    },
    {
        id: "meklesanas_koks",
        nosaukums: "Meklēšanas koks",
        izveidot: null
    }
];

var c = 0;

function dabutVertibu() {
    return Math.round(Math.random() * 99);
}

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    var objekts = this;
    this.elements = function(vertiba) {
        this.vertiba = vertiba;
        this.zimejums = [];
        this.nakosais = null;
    };
    this.katramElementam = function(fn) {
        var elem = objekts.struktura;
        fn(elem);
        while (elem.nakosais) {
            elem = elem.nakosais;
            fn(elem);
        }
    };
    this.iegutElementu = function(sakuma) {
        if (sakuma) {
            return objekts.struktura;
        } else {
            var elem = objekts.struktura;
            while (elem.nakosais) {
                elem = elem.nakosais;
            }
            return elem;
        }
    };
    this.pievienot = function(vertiba, sakuma) {
        if (objekts.struktura) {
            var elem = objekts.iegutElementu(sakuma);
            elem.nakosais = new objekts.elements(vertiba);
        } else {
            objekts.struktura = new objekts.elements(vertiba);
        }
    };
    for (var i = 0; i < elementi; i++) {
        objekts.pievienot(dabutVertibu(), false);
    }
    this.zimet = function(attels, ramis, teksts, linija) {
        var i = 0;
        objekts.katramElementam(function(elem) {
            i++;
            ramis.left = 50 + (ramis.width + 20) * i;
            teksts.setText(elem.vertiba.toString());
            teksts.left = ramis.left + (ramis.width / 4);
            attels.add(ramis);
            attels.add(teksts);
            elem.zimejums = [ramis, teksts];
            ramis = window.fabric.util.object.clone(ramis);
            teksts = window.fabric.util.object.clone(teksts);
        });
        objekts.katramElementam(function(elem) {
            if (elem.nakosais) {
                linija.set({x1: elem.zimejums[0].left + elem.zimejums[0].width / 4 * 3,
                            x2: elem.zimejums[0].left + elem.zimejums[0].width + 40,
                            y1: elem.zimejums[0].top + elem.zimejums[0].height / 5,
                            y2: elem.zimejums[0].top + elem.zimejums[0].height / 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'x1': linija.x2 - 15, 'y1': linija.y1 - 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'y1': linija.y1 + 10});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
            }
        });
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    var objekts = this;
    this.elements = function(vertiba) {
        this.vertiba = vertiba;
        this.zimejums = [];
        this.ieprieksejais = null;
        this.nakosais = null;
    };
    this.katramElementam = function(fn) {
        var elem = objekts.struktura;
        fn(elem);
        while (elem.nakosais) {
            elem = elem.nakosais;
            fn(elem);
        }
    };
    this.iegutElementu = function(sakuma) {
        if (sakuma) {
            return objekts.struktura;
        } else {
            var elem = objekts.struktura;
            while (elem.nakosais) {
                elem = elem.nakosais;
            }
            return elem;
        }
    };
    this.pievienot = function(vertiba, sakuma) {
        if (objekts.struktura) {
            var elem = objekts.iegutElementu(sakuma);
            elem.nakosais = new objekts.elements(vertiba);
            elem.nakosais.ieprieksejais = elem;
        } else {
            objekts.struktura = new objekts.elements(vertiba);
        }
    };
    for (var i = 0; i < elementi; i++) {
        objekts.pievienot(dabutVertibu(), false);
    }
    this.zimet = function(attels, ramis, teksts, linija) {
        var i = 0;
        objekts.katramElementam(function(elem) {
            i++;
            ramis.left = 50 + (ramis.width + 20) * i;
            teksts.setText(elem.vertiba.toString());
            teksts.left = ramis.left + (ramis.width / 4);
            attels.add(ramis);
            attels.add(teksts);
            elem.zimejums = [ramis, teksts];
            ramis = window.fabric.util.object.clone(ramis);
            teksts = window.fabric.util.object.clone(teksts);
        });
        objekts.katramElementam(function(elem) {
            if (elem.nakosais) {
                linija.set({x1: elem.zimejums[0].left + elem.zimejums[0].width / 4 * 3,
                            x2: elem.zimejums[0].left + elem.zimejums[0].width + 40,
                            y1: elem.zimejums[0].top + elem.zimejums[0].height / 5,
                            y2: elem.zimejums[0].top + elem.zimejums[0].height / 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'x1': linija.x2 - 15, 'y1': linija.y1 - 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'y1': linija.y1 + 10});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
            }
            if (elem.ieprieksejais) {
            linija.set({x1: elem.zimejums[0].left + elem.zimejums[0].width / 4,
                        x2: elem.zimejums[0].left - 20 - elem.zimejums[0].width / 4,
                        y1: elem.zimejums[0].top + elem.zimejums[0].height - elem.zimejums[0].height / 6,
                        y2: elem.zimejums[0].top + elem.zimejums[0].height - elem.zimejums[0].height / 6});
            attels.add(linija);
            elem.zimejums.push(linija);
            linija = window.fabric.util.object.clone(linija);
            linija.set({x1: elem.zimejums[0].left - 20 - elem.zimejums[0].width / 4 + 15,
                        y1: linija.y1 - 5});
            attels.add(linija);
            elem.zimejums.push(linija);
            linija = window.fabric.util.object.clone(linija);
            linija.set({'y1': linija.y1 + 10});
            attels.add(linija);
            elem.zimejums.push(linija);
            linija = window.fabric.util.object.clone(linija);
            }
        });
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

export default Strukturas;
<commit_msg>Izveidot un uzzīmēt Steku<commit_after>
var Strukturas = [
    {
        id: "vienkars_saraksts",
        nosaukums: "Vienkāršsaistīts saraksts",
        izveidot: null
    },
    {
        id: "divkars_saraksts",
        nosaukums: "Divkāršsaistīts saraksts",
        izveidot: null
    },
    {
        id: "steks",
        nosaukums: "Steks",
        izveidot: null
    },
    {
        id: "rinda",
        nosaukums: "Rinda",
        izveidot: null
    },
    {
        id: "kaudze",
        nosaukums: "Kaudze",
        izveidot: null
    },
    {
        id: "binars_koks",
        nosaukums: "Binārs koks",
        izveidot: null
    },
    {
        id: "avl_koks",
        nosaukums: "AVL koks",
        izveidot: null
    },
    {
        id: "meklesanas_koks",
        nosaukums: "Meklēšanas koks",
        izveidot: null
    }
];

var c = 0;

function dabutVertibu() {
    return Math.round(Math.random() * 99);
}

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    var objekts = this;
    this.elements = function(vertiba) {
        this.vertiba = vertiba;
        this.zimejums = [];
        this.nakosais = null;
    };
    this.katramElementam = function(fn) {
        var elem = objekts.struktura;
        fn(elem);
        while (elem.nakosais) {
            elem = elem.nakosais;
            fn(elem);
        }
    };
    this.iegutElementu = function(sakuma) {
        if (sakuma) {
            return objekts.struktura;
        } else {
            var elem = objekts.struktura;
            while (elem.nakosais) {
                elem = elem.nakosais;
            }
            return elem;
        }
    };
    this.pievienot = function(vertiba, sakuma) {
        if (objekts.struktura) {
            var elem = objekts.iegutElementu(sakuma);
            elem.nakosais = new objekts.elements(vertiba);
        } else {
            objekts.struktura = new objekts.elements(vertiba);
        }
    };
    for (var i = 0; i < elementi; i++) {
        objekts.pievienot(dabutVertibu(), false);
    }
    this.zimet = function(attels, ramis, teksts, linija) {
        var i = 0;
        objekts.katramElementam(function(elem) {
            i++;
            ramis.left = 50 + (ramis.width + 20) * i;
            teksts.setText(elem.vertiba.toString());
            teksts.left = ramis.left + (ramis.width / 4);
            attels.add(ramis);
            attels.add(teksts);
            elem.zimejums = [ramis, teksts];
            ramis = window.fabric.util.object.clone(ramis);
            teksts = window.fabric.util.object.clone(teksts);
        });
        objekts.katramElementam(function(elem) {
            if (elem.nakosais) {
                linija.set({x1: elem.zimejums[0].left + elem.zimejums[0].width / 4 * 3,
                            x2: elem.zimejums[0].left + elem.zimejums[0].width + 40,
                            y1: elem.zimejums[0].top + elem.zimejums[0].height / 5,
                            y2: elem.zimejums[0].top + elem.zimejums[0].height / 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'x1': linija.x2 - 15, 'y1': linija.y1 - 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'y1': linija.y1 + 10});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
            }
        });
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    var objekts = this;
    this.elements = function(vertiba) {
        this.vertiba = vertiba;
        this.zimejums = [];
        this.ieprieksejais = null;
        this.nakosais = null;
    };
    this.katramElementam = function(fn) {
        var elem = objekts.struktura;
        fn(elem);
        while (elem.nakosais) {
            elem = elem.nakosais;
            fn(elem);
        }
    };
    this.iegutElementu = function(sakuma) {
        if (sakuma) {
            return objekts.struktura;
        } else {
            var elem = objekts.struktura;
            while (elem.nakosais) {
                elem = elem.nakosais;
            }
            return elem;
        }
    };
    this.pievienot = function(vertiba, sakuma) {
        if (objekts.struktura) {
            var elem = objekts.iegutElementu(sakuma);
            elem.nakosais = new objekts.elements(vertiba);
            elem.nakosais.ieprieksejais = elem;
        } else {
            objekts.struktura = new objekts.elements(vertiba);
        }
    };
    for (var i = 0; i < elementi; i++) {
        objekts.pievienot(dabutVertibu(), false);
    }
    this.zimet = function(attels, ramis, teksts, linija) {
        var i = 0;
        objekts.katramElementam(function(elem) {
            i++;
            ramis.left = 50 + (ramis.width + 20) * i;
            teksts.setText(elem.vertiba.toString());
            teksts.left = ramis.left + (ramis.width / 4);
            attels.add(ramis);
            attels.add(teksts);
            elem.zimejums = [ramis, teksts];
            ramis = window.fabric.util.object.clone(ramis);
            teksts = window.fabric.util.object.clone(teksts);
        });
        objekts.katramElementam(function(elem) {
            if (elem.nakosais) {
                linija.set({x1: elem.zimejums[0].left + elem.zimejums[0].width / 4 * 3,
                            x2: elem.zimejums[0].left + elem.zimejums[0].width + 40,
                            y1: elem.zimejums[0].top + elem.zimejums[0].height / 5,
                            y2: elem.zimejums[0].top + elem.zimejums[0].height / 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'x1': linija.x2 - 15, 'y1': linija.y1 - 5});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
                linija.set({'y1': linija.y1 + 10});
                attels.add(linija);
                elem.zimejums.push(linija);
                linija = window.fabric.util.object.clone(linija);
            }
            if (elem.ieprieksejais) {
            linija.set({x1: elem.zimejums[0].left + elem.zimejums[0].width / 4,
                        x2: elem.zimejums[0].left - 20 - elem.zimejums[0].width / 4,
                        y1: elem.zimejums[0].top + elem.zimejums[0].height - elem.zimejums[0].height / 6,
                        y2: elem.zimejums[0].top + elem.zimejums[0].height - elem.zimejums[0].height / 6});
            attels.add(linija);
            elem.zimejums.push(linija);
            linija = window.fabric.util.object.clone(linija);
            linija.set({x1: elem.zimejums[0].left - 20 - elem.zimejums[0].width / 4 + 15,
                        y1: linija.y1 - 5});
            attels.add(linija);
            elem.zimejums.push(linija);
            linija = window.fabric.util.object.clone(linija);
            linija.set({'y1': linija.y1 + 10});
            attels.add(linija);
            elem.zimejums.push(linija);
            linija = window.fabric.util.object.clone(linija);
            }
        });
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = [];
    var objekts = this;
    this.elements = function(vertiba) {
        this.vertiba = vertiba;
        this.zimejums = [];
    };
    this.pievienot = function(vertiba, sakuma) {
        if (sakuma) {
            objekts.struktura.unshift(new objekts.elements(vertiba));
        } else {
            objekts.struktura.push(new objekts.elements(vertiba));
        }
    };
    for (var i = 0; i < elementi; i++) {
        objekts.pievienot(dabutVertibu(), false);
    }
    this.zimet = function(attels, ramis, teksts, linija) {
        ramis.left = 200;
        teksts.left = 215;
        for (var i = 0; i < objekts.struktura.length; i++) {
            ramis.top = 50 + (ramis.height + 2) * i;
            teksts.setText(objekts.struktura[objekts.struktura.length - 1 - i].vertiba.toString());
            teksts.top = ramis.top + (ramis.height / 4);
            attels.add(ramis);
            attels.add(teksts);
            objekts.struktura[i].zimejums = [ramis, teksts];
            ramis = window.fabric.util.object.clone(ramis);
            teksts = window.fabric.util.object.clone(teksts);
        }
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

Strukturas[c++].izveidot = function(elementi) {
    this.struktura = null;
    this.pievienot = function(vertiba, sakuma) {
    };
    this.zimet = function(attels, ramis, teksts, linija) {
    };
    return this;
};

export default Strukturas;
<|endoftext|>


<commit_before>/*
 * Copyright 2012 Igor Kalnitsky <igor@kalnitsky.org>
 *
 * This file is part of Icon Hider for Gnome Shell.
 *
 * Icon Hider is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Icon Hider is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Icon Hider Extension.  If not, see <http://www.gnu.org/licenses/>.
 */

const Lang = imports.lang;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const PanelMenu = imports.ui.panelMenu;

const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;

// global consts
const EXTENSION_NAME = 'Icon Hider';
const GSETTINGS = {
    HIDDEN:             'hidden',
    KNOWN:              'known',
    EXCEPTIONS:         'exceptions',
    IS_INDICATOR_SHOWN: 'is-indicator-shown',
    IS_USERNAME_SHOWN:  'is-username-shown'
};

/*
 * Indicator definition.
 *
 * Create item in StatusArea panel. Provide menu for manipulating
 * visiblity of other icons.
 */

function Indicator() {
    this._init.apply(this, arguments);
}

Indicator.prototype = {
    __proto__: PanelMenu.SystemStatusButton.prototype,

    /**
     * Constructor
     */
    _init: function() {
        PanelMenu.SystemStatusButton.prototype._init.call(this, 'view-grid');
        Main.panel.addToStatusArea(EXTENSION_NAME, this);

        this._settings = Convenience.getSettings();
        this._createMenu();
    },

    /**
     * Create menu in top bar.
     */
    _createMenu: function() {
        let knownItems = this._settings.get_strv(GSETTINGS.KNOWN);
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);

        // create switchers list
        for each (let item in knownItems) {
            // create menu item
            let isHidden = (hiddenItems.indexOf(item) != -1);
            let menuItem = new PopupMenu.PopupSwitchMenuItem(item, !isHidden);
            this.menu.addMenuItem(menuItem);

            menuItem.statusAreaKey = item;

            // set handler
            menuItem.connect('toggled', Lang.bind(this, function (item) {
                item.state == false
                    ? this._hideItem(item)
                    : this._showItem(item);
            }));
        }

        // create service items
        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

        let settingsItem = new PopupMenu.PopupMenuItem('Settings');
        settingsItem.connect('activate', Lang.bind(this, function() {
            var runPrefs = 'gnome-shell-extension-prefs ' + Me.metadata.uuid;
            Main.Util.trySpawnCommandLine(runPrefs);
        }));
        this.menu.addMenuItem(settingsItem);
    },

    /**
     * Hide element and mark it as hidden in settings.
     */
    _hideItem: function (item) {
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);

        if (hiddenItems.indexOf(item.statusAreaKey) == -1) {
            hiddenItems.push(item.statusAreaKey);
            this._settings.set_strv(GSETTINGS.HIDDEN, hiddenItems);
        }
    },

    /**
     * Show element and mark it as visible in settings.
     */
    _showItem: function (item) {
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);
        let index = hiddenItems.indexOf(item.statusAreaKey);

        while (index != -1) {
            hiddenItems.splice(index, 1);
            this._settings.set_strv(GSETTINGS.HIDDEN, hiddenItems);
            index = hiddenItems.indexOf(item.statusAreaKey);
        }
    }
}

/*
 * Extension definition.
 */

function Extension() {
    this._init();
}

Extension.prototype = {
    _init: function() {
        this._indicator = null;
        this._settings = Convenience.getSettings();
        this._statusArea = Main.panel._statusArea;
    },

    enable: function() {
        // save signal id (should be used for disconnecting in `destroy()`)
        this._settingsSignal =
            this._settings.connect('changed::', Lang.bind(this, this._reloadSettings));
        this._loadSettings();
    },

    /**
     * Clean-up:
     *   - restore icons' visibility
     *   - disconnect settings signal
     *   - destroy indicator
     */
    disable: function() {
        // restore visibility
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);
        for each (let item in hiddenItems)
            if (item in this._statusArea)
                this._statusArea[item].actor.show();

        this._indicator.destroy();
        this._indicator = null;
        this._settings.disconnect(this._settingsSignal);
    },

    /**
     * This function is called when settings are changed.
     */
    _reloadSettings: function() {
        this.disable();
        this.enable();
    },

    /**
     * Load settings:
     *   - scan for icons
     *   - show/hide username
     *   - create and show/hide indicator
     */
    _loadSettings: function() {
        // load visibility
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);
        let knownItems = this._settings.get_strv(GSETTINGS.KNOWN);
        let exceptionsItems = this._settings.get_strv(GSETTINGS.EXCEPTIONS);

        for (let item in this._statusArea) {
            // skip exceptions (this items don't works correctly)
            if (exceptionsItems.indexOf(item) != -1 || item === EXTENSION_NAME)
                continue;

            // add to known icons (used by prefs.js and indicator)
            if (knownItems.indexOf(item) == -1)
                knownItems.push(item);

            // set icon visibility
            hiddenItems.indexOf(item) != -1
                ? this._statusArea[item].actor.hide()
                : this._statusArea[item].actor.show();
        }

        // create indicator
        this._indicator = new Indicator();

        // load utilities settings
        let isIndicatorShown = this._settings.get_boolean(GSETTINGS.IS_INDICATOR_SHOWN);
        let isUsernameShown = this._settings.get_boolean(GSETTINGS.IS_USERNAME_SHOWN);

        isIndicatorShown
            ? this._indicator.actor.show()
            : this._indicator.actor.hide();

        isUsernameShown
            ? this._statusArea.userMenu._name.show()
            : this._statusArea.userMenu._name.hide();
    }
};

/**
 * Entry point.
 *
 * Should return an object with callable `enable` and `disable` properties.
 */
function init() {
    return new Extension();
}
<commit_msg>fixed #6<commit_after>/*
 * Copyright 2012 Igor Kalnitsky <igor@kalnitsky.org>
 *
 * This file is part of Icon Hider for Gnome Shell.
 *
 * Icon Hider is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Icon Hider is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Icon Hider Extension.  If not, see <http://www.gnu.org/licenses/>.
 */

const Lang = imports.lang;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const PanelMenu = imports.ui.panelMenu;

const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;

// global consts
const EXTENSION_NAME = 'Icon Hider';
const GSETTINGS = {
    HIDDEN:             'hidden',
    KNOWN:              'known',
    EXCEPTIONS:         'exceptions',
    IS_INDICATOR_SHOWN: 'is-indicator-shown',
    IS_USERNAME_SHOWN:  'is-username-shown'
};

/*
 * Indicator definition.
 *
 * Create item in StatusArea panel. Provide menu for manipulating
 * visiblity of other icons.
 */

function Indicator() {
    this._init.apply(this, arguments);
}

Indicator.prototype = {
    __proto__: PanelMenu.SystemStatusButton.prototype,

    /**
     * Constructor
     */
    _init: function() {
        PanelMenu.SystemStatusButton.prototype._init.call(this, 'view-grid');
        Main.panel.addToStatusArea(EXTENSION_NAME, this);

        this._settings = Convenience.getSettings();
        this._createMenu();
    },

    /**
     * Create menu in top bar.
     */
    _createMenu: function() {
        let knownItems = this._settings.get_strv(GSETTINGS.KNOWN);
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);

        // create switchers list
        for each (let item in knownItems) {
            // create menu item
            let isHidden = (hiddenItems.indexOf(item) != -1);
            let menuItem = new PopupMenu.PopupSwitchMenuItem(item, !isHidden);
            this.menu.addMenuItem(menuItem);

            menuItem.statusAreaKey = item;

            // set handler
            menuItem.connect('toggled', Lang.bind(this, function (item) {
                item.state == false
                    ? this._hideItem(item)
                    : this._showItem(item);
            }));
        }

        // create service items
        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

        let settingsItem = new PopupMenu.PopupMenuItem('Settings');
        settingsItem.connect('activate', Lang.bind(this, function() {
            var runPrefs = 'gnome-shell-extension-prefs ' + Me.metadata.uuid;
            Main.Util.trySpawnCommandLine(runPrefs);
        }));
        this.menu.addMenuItem(settingsItem);
    },

    /**
     * Hide element and mark it as hidden in settings.
     */
    _hideItem: function (item) {
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);

        if (hiddenItems.indexOf(item.statusAreaKey) == -1) {
            hiddenItems.push(item.statusAreaKey);
            this._settings.set_strv(GSETTINGS.HIDDEN, hiddenItems);
        }
    },

    /**
     * Show element and mark it as visible in settings.
     */
    _showItem: function (item) {
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);
        let index = hiddenItems.indexOf(item.statusAreaKey);

        while (index != -1) {
            hiddenItems.splice(index, 1);
            this._settings.set_strv(GSETTINGS.HIDDEN, hiddenItems);
            index = hiddenItems.indexOf(item.statusAreaKey);
        }
    }
}

/*
 * Extension definition.
 */

function Extension() {
    this._init();
}

Extension.prototype = {
    _init: function() {
        this._indicator = null;
        this._settings = Convenience.getSettings();
        this._statusArea = Main.panel._statusArea;
    },

    enable: function() {
        // load visibility
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);
        let knownItems = this._settings.get_strv(GSETTINGS.KNOWN);
        let exceptionsItems = this._settings.get_strv(GSETTINGS.EXCEPTIONS);

        for (let item in this._statusArea) {
            // skip exceptions (this items don't works correctly)
            if (exceptionsItems.indexOf(item) != -1 || item === EXTENSION_NAME)
                continue;

            // add to known icons (used by prefs.js and indicator)
            if (knownItems.indexOf(item) == -1)
                knownItems.push(item);

            // set icon visibility
            hiddenItems.indexOf(item) != -1
                ? this._statusArea[item].actor.hide()
                : this._statusArea[item].actor.show();
        }
        this._settings.set_strv(GSETTINGS.KNOWN, knownItems);

        // create indicator
        this._indicator = new Indicator();

        // load utilities settings
        let isIndicatorShown = this._settings.get_boolean(GSETTINGS.IS_INDICATOR_SHOWN);
        let isUsernameShown = this._settings.get_boolean(GSETTINGS.IS_USERNAME_SHOWN);

        isIndicatorShown
            ? this._indicator.actor.show()
            : this._indicator.actor.hide();

        isUsernameShown
            ? this._statusArea.userMenu._name.show()
            : this._statusArea.userMenu._name.hide();
        // save signal id (should be used for disconnecting in `destroy()`)
        this._settingsSignal =
            this._settings.connect('changed::', Lang.bind(this, this._reloadSettings));
    },

    /**
     * Clean-up:
     *   - restore icons' visibility
     *   - disconnect settings signal
     *   - destroy indicator
     */
    disable: function() {
        // restore visibility
        let hiddenItems = this._settings.get_strv(GSETTINGS.HIDDEN);
        for each (let item in hiddenItems)
            if (item in this._statusArea)
                this._statusArea[item].actor.show();

        this._indicator.destroy();
        this._indicator = null;
        this._settings.disconnect(this._settingsSignal);
    },

    /**
     * This function is called when settings are changed.
     */
    _reloadSettings: function() {
        this.disable();
        this.enable();
    }
};

/**
 * Entry point.
 *
 * Should return an object with callable `enable` and `disable` properties.
 */
function init() {
    return new Extension();
}
<|endoftext|>


<commit_before>app.service("ThemeModel", function($q,AbstractModel, WsApi) {

	var self;

	var Theme = function(futureData) {
		self = this;
		angular.extend(self, AbstractModel);
		self.unwrap(self, futureData);
	};

	Theme.data = null;

	Theme.promise = null;

	Theme.set = function(data) {
		self.unwrap(self, data);
	};

	Theme.get = function() {

		var newThemePromise = WsApi.fetch({
				endpoint: '/private/queue',
				controller: 'theme',
				method: "all",
		});

		Theme.promise = newThemePromise;
		Theme.data = new Theme(newThemePromise);

		return Theme.data;
	};

	Theme.ready = function() {
		return Theme.promise;
	};

	Theme.refresh = function() {
		Theme.promise = null;
		Theme.get();
	};

	Theme.updateThemeProperty = function(themeId,propertyId,value) {
		return $q(function(resolve,reject) {
			WsApi.fetch({
					endpoint: '/private/queue',
					controller: 'theme',
					method: 'update-property',
					data: {
						"themeId":themeId,
						"propertyId":propertyId,
						"value":value,
					}
			}).then(function() {
				resolve("Theme Property Updated");
			},function() {
				reject("Failed to update Theme Property");
			});
		});
	};

	Theme.addTheme = function(newTheme) {
		return $q(function(resolve,reject) {
			WsApi.fetch({
					endpoint: '/private/queue',
					controller: 'theme',
					method: 'add-theme',
					data: {"newTheme":newTheme}
			}).then(function() {
				resolve("Theme Added");
			},function() {
				reject("Failed to add new Theme");
			});
		});
	};

	Theme.activateTheme = function(themeId) {
		return $q(function(resolve,reject) {
			WsApi.fetch({
					endpoint: '/private/queue',
					controller: 'theme',
					method: 'activate-theme',
					data: {"themeId":themeId}
			}).then(function() {
				resolve("Theme Activated");
			},function() {
				reject("Failed to activate Theme");
			});
		});
	};
	return Theme;

});<commit_msg>catch new theme broadcast<commit_after>app.service("ThemeModel", function($q,AbstractModel, WsApi) {

	var self;

	var Theme = function(futureData) {
		self = this;
		angular.extend(self, AbstractModel);
		self.unwrap(self, futureData);
	};

	Theme.data = null;

	Theme.promise = null;

	Theme.set = function(data) {
		self.unwrap(self, data);
	};

	Theme.receive = function(theme, response) {
		if(JSON.parse(response.body).payload.String) {
			console.log(JSON.parse(response.body).payload.String);
		}
		else {
			var newTheme = true;
			for(var key in Theme.data.list) {
				if(Theme.data.list[key].id == theme.id) {
					Theme.data.list[key] = JSON.parse(response.body).payload.CoreTheme;
					newTheme = false;
					break;
				}
			}
			if(newTheme && Theme.data.list != null) {
				Theme.data.list.push(JSON.parse(response.body).payload.CoreTheme);
			}
		}
	};

	Theme.get = function() {

		var newThemePromise = WsApi.fetch({
				endpoint: '/private/queue',
				controller: 'theme',
				method: "all",
		});

		Theme.promise = newThemePromise;
		Theme.data = new Theme(newThemePromise);

		WsApi.listen({
				endpoint: '/channel',
				controller: 'theme/'
		}).then(null, null, function(response) {
			Theme.receive(JSON.parse(response.body).payload.CoreTheme, response);
		});

		return Theme.data;
	};

	Theme.ready = function() {
		return Theme.promise;
	};

	Theme.refresh = function() {
		Theme.promise = null;
		Theme.get();
	};

	Theme.updateThemeProperty = function(themeId,propertyId,value) {
		return $q(function(resolve,reject) {
			WsApi.fetch({
					endpoint: '/private/queue',
					controller: 'theme',
					method: 'update-property',
					data: {
						"themeId":themeId,
						"propertyId":propertyId,
						"value":value,
					}
			}).then(function() {
				resolve("Theme Property Updated");
			},function() {
				reject("Failed to update Theme Property");
			});
		});
	};

	Theme.addTheme = function(newTheme) {
		return $q(function(resolve,reject) {
			WsApi.fetch({
					endpoint: '/private/queue',
					controller: 'theme',
					method: 'add-theme',
					data: {"newTheme":newTheme}
			}).then(function() {
				resolve("Theme Added");
			},function() {
				reject("Failed to add new Theme");
			});
		});
	};

	Theme.activateTheme = function(themeId) {
		return $q(function(resolve,reject) {
			WsApi.fetch({
					endpoint: '/private/queue',
					controller: 'theme',
					method: 'activate-theme',
					data: {"themeId":themeId}
			}).then(function() {
				resolve("Theme Activated");
			},function() {
				reject("Failed to activate Theme");
			});
		});
	};
	return Theme;

});<|endoftext|>