javascript - Native Menus not showing OS X Electron -


i used electron-quick-start create electron app, , want native menu show 'edit' menu, usual suspects inside.

however, after searching , exhausting relevant google results 'electron menu not working', i'm @ loss.

my current main.js file:

const {app, menu, browserwindow} = require('electron')  // keep global reference of window object, if don't, window // closed automatically when javascript object garbage collected. let mainwindow;  app.setname('mathulator');  function createwindow () {   // create browser window.   mainwindow = new browserwindow({width: 900, height: 550})    // , load index.html of app.   mainwindow.loadurl(`file://${__dirname}/index.html`)    // in file can include rest of app's specific main process   // code. can put them in separate files , require them here.    const template = [     {         label: 'mathulator',         submenu: [             {                 role: 'quit'             }         ]     },     {       label: 'edit',       submenu: [         {           role: 'undo'         },         {           role: 'redo'         },         {           type: 'separator'         },         {           role: 'cut'         },         {           role: 'copy'         },         {           role: 'paste'         },         {           role: 'pasteandmatchstyle'         },         {           role: 'delete'         },         {           role: 'selectall'         }       ]     }    ]    mainwindow.setmenu(menu.buildfromtemplate(template))    // emitted when window closed.   mainwindow.on('closed', function () {     // dereference window object, store windows     // in array if app supports multi windows, time     // when should delete corresponding element.     mainwindow = null   }) }  // method called when electron has finished // initialization , ready create browser windows. // apis can used after event occurs. app.on('ready', createwindow)  // quit when windows closed. app.on('window-all-closed', function () {   // on os x common applications , menu bar   // stay active until user quits explicitly cmd + q   if (process.platform !== 'darwin') {     app.quit()   } })  app.on('activate', function () {   // on os x it's common re-create window in app when   // dock icon clicked , there no other windows open.   if (mainwindow === null) {     createwindow()   } }) 

i've packaged electron-packager, no avail.

i'm running in main.js file, can gather masses of either vague or convoluted information around web, main process , therefore 1 in should create menus.

i tried doing in render.js, saw suggested. no avail. it'll either show default electron-quick-start menu, or simple menu named after app, containing 1 item labelled 'quit'.

what might doing wrong, , might have misunderstood available information?


edit: attached wrong file, tried using menu.setapplicationmenu() first time, so:

const {app, menu, browserwindow} = require('electron')  // keep global reference of window object, if don't, window // closed automatically when javascript object garbage collected. let mainwindow;  app.setname('mathulator');  function createwindow () {     // create browser window.     mainwindow = new browserwindow({width: 900, height: 550});      // , load index.html of app.     mainwindow.loadurl(`file://${__dirname}/index.html`);      // emitted when window closed.     mainwindow.on('closed', function () {         // dereference window object, store windows         // in array if app supports multi windows, time         // when should delete corresponding element.         mainwindow = null;     }); }  // method called when electron has finished // initialization , ready create browser windows. // apis can used after event occurs. app.on('ready', createwindow);  // quit when windows closed. app.on('window-all-closed', function () {     // on os x common applications , menu bar     // stay active until user quits explicitly cmd + q     if (process.platform !== 'darwin') {         app.quit();     } })  app.on('activate', function () {     // on os x it's common re-create window in app when     // dock icon clicked , there no other windows open.     if (mainwindow === null) {         createwindow();     } })  const template = [     {         label: 'mathulator',         submenu: [             {                 role: 'quit'             }         ]     },     {         label: 'edit',         submenu: [             {                 role: 'undo'             },             {                 role: 'redo'             },             {                 type: 'separator'             },             {                 role: 'cut'             },             {                 role: 'copy'             },             {                 role: 'paste'             },             {                 role: 'pasteandmatchstyle'             },             {                 role: 'delete'             },             {                 role: 'selectall'             }         ]     } ];  menu.setapplicationmenu(menu.buildfromtemplate(template)); 

the issue here browserwindow.setmenu() available on windows , linux. on macos should use menu.setapplicationmenu().


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -