Advertisement
Guest User

main.js

a guest
Feb 28th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Modules to control application life and create native browser window
  2. const { app, BrowserWindow } = require('electron')
  3. const Menu = require('electron').Menu
  4. const path = require('path')
  5.  
  6. // Keep a global reference of the window object, if you don't, the window will
  7. // be closed automatically when the JavaScript object is garbage collected.
  8. let mainWindow
  9.  
  10. function createWindow() {
  11.     // Create the browser window.
  12.  
  13.     mainWindow = new BrowserWindow({
  14.         width: 1024,
  15.         height: 768,
  16.         webPreferences: { nodeIntegration: false },
  17.         icon: path.join(__dirname, 'assets/icons/png/64x64.png')
  18.     })
  19.  
  20.     // and load the index.html of the app.
  21.     mainWindow.loadURL('https://dashboard.example.com')
  22.  
  23.     // Open the DevTools.
  24.     // mainWindow.webContents.openDevTools()
  25.  
  26.     // Emitted when the window is closed.
  27.     mainWindow.on('closed', function () {
  28.         // Dereference the window object, usually you would store windows
  29.         // in an array if your app supports multi windows, this is the time
  30.         // when you should delete the corresponding element.
  31.         mainWindow = null
  32.     })
  33. }
  34.  
  35. function createMenu() {
  36.     const application = {
  37.         //label: "Application",
  38.         label: "File",
  39.         submenu: [
  40.             {
  41.                 label: "About MyApp: Desktop",
  42.                 selector: "orderFrontStandardAboutPanel:"
  43.             },
  44.             {
  45.                 type: "separator"
  46.             },
  47.             {
  48.                 label: "Sair",
  49.                 accelerator: "CmdOrCtrl+Q",
  50.                 click: () => {
  51.                     app.quit()
  52.                 }
  53.             }
  54.         ]
  55.     }
  56.  
  57.     const edit = {
  58.         label: "Edit",
  59.         submenu: [
  60.             {
  61.                 label: "Undo",
  62.                 accelerator: "CmdOrCtrl+Z",
  63.                 selector: "undo:"
  64.             },
  65.             {
  66.                 label: "Redo",
  67.                 accelerator: "Shift+CmdOrCtrl+Z",
  68.                 selector: "redo:"
  69.             },
  70.             {
  71.                 type: "separator"
  72.             },
  73.             {
  74.                 label: "Cut",
  75.                 accelerator: "CmdOrCtrl+X",
  76.                 selector: "cut:"
  77.             },
  78.             {
  79.                 label: "Copy",
  80.                 accelerator: "CmdOrCtrl+C",
  81.                 selector: "copy:"
  82.             },
  83.             {
  84.                 label: "Paste",
  85.                 accelerator: "CmdOrCtrl+V",
  86.                 selector: "paste:"
  87.             },
  88.             {
  89.                 label: "Select All",
  90.                 accelerator: "CmdOrCtrl+A",
  91.                 selector: "selectAll:"
  92.             }
  93.         ]
  94.     }
  95.  
  96.     const template = [
  97.         application,
  98.         edit
  99.     ]
  100.  
  101.     Menu.setApplicationMenu(Menu.buildFromTemplate(template))
  102. }
  103.  
  104. // This method will be called when Electron has finished
  105. // initialization and is ready to create browser windows.
  106. // Some APIs can only be used after this event occurs.
  107. app.on('ready', () => {
  108.     createWindow()
  109.     createMenu()
  110.   })
  111.  
  112.  
  113. // Quit when all windows are closed.
  114. app.on('window-all-closed', function () {
  115.     // On OS X it is common for applications and their menu bar
  116.     // to stay active until the user quits explicitly with Cmd + Q
  117.     if (process.platform !== 'darwin') {
  118.         app.quit()
  119.     }
  120. })
  121.  
  122. app.on('activate', function () {
  123.     // On OS X it's common to re-create a window in the app when the
  124.     // dock icon is clicked and there are no other windows open.
  125.     if (mainWindow === null) {
  126.         createWindow()
  127.     }
  128. })
  129.  
  130. // In this file you can include the rest of your app's specific main process
  131. // code. You can also put them in separate files and require them here.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement